close #38: remove UnitTestCallbackRegistration

pull/43/head
Simon G 6 years ago
parent cd4b80de5b
commit f5fefa400a
  1. 9
      LightweightIocContainer/Interfaces/IIocContainer.cs
  2. 22
      LightweightIocContainer/Interfaces/Registrations/IUnitTestCallbackRegistration.cs
  3. 24
      LightweightIocContainer/IocContainer.cs
  4. 55
      LightweightIocContainer/LightweightIocContainer.xml
  5. 6
      LightweightIocContainer/Registrations/RegistrationFactory.cs
  6. 46
      LightweightIocContainer/Registrations/UnitTestCallbackRegistration.cs
  7. 20
      Test.LightweightIocContainer/IocContainerTest.cs
  8. 72
      Test.LightweightIocContainer/UnitTestCallbackRegistrationTest.cs

@ -99,15 +99,6 @@ namespace LightweightIocContainer.Interfaces
/// <returns>The created <see cref="IRegistration"/></returns>
ITypedFactoryRegistration<TFactory> RegisterFactory<TFactory>();
/// <summary>
/// Register an Interface with an <see cref="ResolveCallback{T}"/> as a callback that is called when <see cref="Resolve{T}()"/> is called
/// </summary>
/// <typeparam name="TInterface">The Interface to register</typeparam>
/// <param name="unitTestCallback">The <see cref="ResolveCallback{T}"/> for the callback</param>
/// <returns>The created <see cref="IRegistration"/></returns>
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
IUnitTestCallbackRegistration<TInterface> RegisterUnitTestCallback<TInterface>(ResolveCallback<TInterface> unitTestCallback);
/// <summary>
/// Gets an instance of the given <see cref="Type"/>
/// </summary>

@ -1,22 +0,0 @@
// Author: Gockner, Simon
// Created: 2019-10-15
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
namespace LightweightIocContainer.Interfaces.Registrations
{
/// <summary>
/// A special <see cref="IRegistration"/> that allows to set a <see cref="ResolveCallback{T}"/> as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
/// <typeparam name="TInterface"></typeparam>
[Obsolete("IUnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public interface IUnitTestCallbackRegistration<out TInterface> : IRegistration
{
/// <summary>
/// An <see cref="ResolveCallback{T}"/> that is set as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
[Obsolete("UnitTestResolveCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
ResolveCallback<TInterface> UnitTestResolveCallback { get; }
}
}

@ -183,21 +183,6 @@ namespace LightweightIocContainer
return registration;
}
/// <summary>
/// Register an Interface with an <see cref="ResolveCallback{T}"/> as a callback that is called when <see cref="Resolve{T}()"/> is called
/// </summary>
/// <typeparam name="TInterface">The Interface to register</typeparam>
/// <param name="unitTestCallback">The <see cref="ResolveCallback{T}"/> for the callback</param>
/// <returns>The created <see cref="IRegistration"/></returns>
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public IUnitTestCallbackRegistration<TInterface> RegisterUnitTestCallback<TInterface>(ResolveCallback<TInterface> unitTestCallback)
{
IUnitTestCallbackRegistration<TInterface> registration = _registrationFactory.RegisterUnitTestCallback(unitTestCallback);
Register(registration);
return registration;
}
/// <summary>
/// Add the <see cref="IRegistration"/> to the the <see cref="IocContainer"/>
/// </summary>
@ -298,14 +283,7 @@ namespace LightweightIocContainer
T resolvedInstance;
//TODO: remove this #pragma when IUnitTestCallbackRegistration is removed
#pragma warning disable 618
if (registration is IUnitTestCallbackRegistration<T> unitTestCallbackRegistration)
{
resolvedInstance = unitTestCallbackRegistration.UnitTestResolveCallback.Invoke(arguments);
}
#pragma warning restore 618
else if (registration is IRegistrationBase<T> defaultRegistration)
if (registration is IRegistrationBase<T> defaultRegistration)
{
if (defaultRegistration.Lifestyle == Lifestyle.Singleton)
resolvedInstance = GetOrCreateSingletonInstance(defaultRegistration, arguments, resolveStack);

@ -416,14 +416,6 @@
<typeparam name="TFactory">The abstract typed factory to register</typeparam>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
</member>
<member name="M:LightweightIocContainer.Interfaces.IIocContainer.RegisterUnitTestCallback``1(LightweightIocContainer.ResolveCallback{``0})">
<summary>
Register an Interface with an <see cref="T:LightweightIocContainer.ResolveCallback`1"/> as a callback that is called when <see cref="M:LightweightIocContainer.Interfaces.IIocContainer.Resolve``1"/> is called
</summary>
<typeparam name="TInterface">The Interface to register</typeparam>
<param name="unitTestCallback">The <see cref="T:LightweightIocContainer.ResolveCallback`1"/> for the callback</param>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
</member>
<member name="M:LightweightIocContainer.Interfaces.IIocContainer.Resolve``1">
<summary>
Gets an instance of the given <see cref="T:System.Type"/>
@ -672,17 +664,6 @@
A <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistrationBase`1"/> that implements a <see cref="T:System.Type"/>
</summary>
</member>
<member name="T:LightweightIocContainer.Interfaces.Registrations.IUnitTestCallbackRegistration`1">
<summary>
A special <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> that allows to set a <see cref="T:LightweightIocContainer.ResolveCallback`1"/> as a callback that is called on <see cref="M:LightweightIocContainer.Interfaces.IIocContainer.Resolve``1"/>
</summary>
<typeparam name="TInterface"></typeparam>
</member>
<member name="P:LightweightIocContainer.Interfaces.Registrations.IUnitTestCallbackRegistration`1.UnitTestResolveCallback">
<summary>
An <see cref="T:LightweightIocContainer.ResolveCallback`1"/> that is set as a callback that is called on <see cref="M:LightweightIocContainer.Interfaces.IIocContainer.Resolve``1"/>
</summary>
</member>
<member name="T:LightweightIocContainer.InternalResolvePlaceholder">
<summary>
An internal placeholder that is used during the resolving process
@ -784,14 +765,6 @@
<typeparam name="TFactory">The abstract typed factory to register</typeparam>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.RegisterUnitTestCallback``1(LightweightIocContainer.ResolveCallback{``0})">
<summary>
Register an Interface with an <see cref="T:LightweightIocContainer.ResolveCallback`1"/> as a callback that is called when <see cref="M:LightweightIocContainer.IocContainer.Resolve``1"/> is called
</summary>
<typeparam name="TInterface">The Interface to register</typeparam>
<param name="unitTestCallback">The <see cref="T:LightweightIocContainer.ResolveCallback`1"/> for the callback</param>
<returns>The created <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.Register(LightweightIocContainer.Interfaces.Registrations.IRegistration)">
<summary>
Add the <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> to the the <see cref="T:LightweightIocContainer.IocContainer"/>
@ -1322,34 +1295,6 @@
<param name="action">The <see cref="T:System.Action`1"/></param>
<returns>The current instance of this <see cref="T:LightweightIocContainer.Interfaces.Registrations.ITypedRegistrationBase`2"/></returns>
</member>
<member name="T:LightweightIocContainer.Registrations.UnitTestCallbackRegistration`1">
<summary>
A special <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> that allows to set a <see cref="T:LightweightIocContainer.ResolveCallback`1"/> as a callback that is called on <see cref="M:LightweightIocContainer.Interfaces.IIocContainer.Resolve``1"/>
</summary>
<typeparam name="TInterface"></typeparam>
</member>
<member name="M:LightweightIocContainer.Registrations.UnitTestCallbackRegistration`1.#ctor(System.Type,LightweightIocContainer.ResolveCallback{`0})">
<summary>
A special <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> that allows to set a <see cref="T:LightweightIocContainer.ResolveCallback`1"/> as a callback that is called on <see cref="M:LightweightIocContainer.Interfaces.IIocContainer.Resolve``1"/>
</summary>
<param name="interfaceType">The <see cref="T:System.Type"/> of the interface</param>
<param name="unitTestResolveCallback">The <see cref="T:LightweightIocContainer.ResolveCallback`1"/> that is set as a callback</param>
</member>
<member name="P:LightweightIocContainer.Registrations.UnitTestCallbackRegistration`1.Name">
<summary>
The name of the <see cref="T:LightweightIocContainer.Registrations.UnitTestCallbackRegistration`1"/>
</summary>
</member>
<member name="P:LightweightIocContainer.Registrations.UnitTestCallbackRegistration`1.InterfaceType">
<summary>
The <see cref="T:System.Type"/> of the Interface that is registered with this <see cref="T:LightweightIocContainer.Registrations.UnitTestCallbackRegistration`1"/>
</summary>
</member>
<member name="P:LightweightIocContainer.Registrations.UnitTestCallbackRegistration`1.UnitTestResolveCallback">
<summary>
An <see cref="T:LightweightIocContainer.ResolveCallback`1"/> that is set as a callback that is called on <see cref="M:LightweightIocContainer.Interfaces.IIocContainer.Resolve``1"/>
</summary>
</member>
<member name="T:LightweightIocContainer.ResolveCallback`1">
<summary>
The resolve callback delegate

@ -123,11 +123,5 @@ namespace LightweightIocContainer.Registrations
{
return new TypedFactoryRegistration<TFactory>(typeof(TFactory), _iocContainer);
}
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public IUnitTestCallbackRegistration<TInterface> RegisterUnitTestCallback<TInterface>(ResolveCallback<TInterface> unitTestResolveCallback)
{
return new UnitTestCallbackRegistration<TInterface>(typeof(TInterface), unitTestResolveCallback);
}
}
}

@ -1,46 +0,0 @@
// Author: Gockner, Simon
// Created: 2019-10-15
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Registrations;
namespace LightweightIocContainer.Registrations
{
/// <summary>
/// A special <see cref="IRegistration"/> that allows to set a <see cref="ResolveCallback{T}"/> as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
/// <typeparam name="TInterface"></typeparam>
[Obsolete("UnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public class UnitTestCallbackRegistration<TInterface> : IUnitTestCallbackRegistration<TInterface>
{
/// <summary>
/// A special <see cref="IRegistration"/> that allows to set a <see cref="ResolveCallback{T}"/> as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
/// <param name="interfaceType">The <see cref="Type"/> of the interface</param>
/// <param name="unitTestResolveCallback">The <see cref="ResolveCallback{T}"/> that is set as a callback</param>
public UnitTestCallbackRegistration(Type interfaceType, ResolveCallback<TInterface> unitTestResolveCallback)
{
InterfaceType = interfaceType;
UnitTestResolveCallback = unitTestResolveCallback;
Name = InterfaceType.Name;
}
/// <summary>
/// The name of the <see cref="UnitTestCallbackRegistration{TInterface}"/>
/// </summary>
public string Name { get; }
/// <summary>
/// The <see cref="Type"/> of the Interface that is registered with this <see cref="UnitTestCallbackRegistration{TInterface}"/>
/// </summary>
public Type InterfaceType { get; }
/// <summary>
/// An <see cref="ResolveCallback{T}"/> that is set as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
public ResolveCallback<TInterface> UnitTestResolveCallback { get; }
}
}

@ -1,4 +1,3 @@
using System;
using JetBrains.Annotations;
using LightweightIocContainer;
using LightweightIocContainer.Exceptions;
@ -209,13 +208,6 @@ namespace Test.LightweightIocContainer
Assert.Throws<IllegalAbstractMethodCreationException>(() => _iocContainer.RegisterFactory<ITestFactoryNonGenericClear>());
}
[Test]
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public void TestRegisterUnitTestCallback()
{
Assert.DoesNotThrow(() => _iocContainer.RegisterUnitTestCallback<ITest>(delegate {return new Test(); }));
}
[Test]
public void TestResolveNotRegistered()
{
@ -474,18 +466,6 @@ namespace Test.LightweightIocContainer
Assert.AreNotSame(resolvedTest3, resolvedTest5);
}
[Test]
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public void TestResolveUnitTestCallbackRegistration()
{
ITest callbackTest = new Test();
_iocContainer.RegisterUnitTestCallback(delegate { return callbackTest; });
ITest test = _iocContainer.Resolve<ITest>();
Assert.AreEqual(callbackTest, test);
}
[Test]
public void TestResolveSingleTypeRegistrationWithFactoryMethod()
{

@ -1,72 +0,0 @@
// Author: Gockner, Simon
// Created: 2019-10-15
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using LightweightIocContainer;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Registrations;
using LightweightIocContainer.Registrations;
using Moq;
using NUnit.Framework;
namespace Test.LightweightIocContainer
{
[TestFixture]
[Obsolete("UnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public class UnitTestCallbackRegistrationTest
{
private interface ITest
{
int Count { get; }
string Name { get; }
bool Testing { get; }
}
private class Test : ITest
{
public Test()
{
Count = -1;
Name = "Test";
Testing = false;
}
public Test(int count, string name, bool testing)
{
Count = count;
Name = name;
Testing = testing;
}
public int Count { get; }
public string Name { get; }
public bool Testing { get; }
}
[Test]
public void TestUnitTestResolveCallback()
{
RegistrationFactory registrationFactory = new RegistrationFactory(new Mock<IIocContainer>().Object);
ITest test = new Test();
IUnitTestCallbackRegistration<ITest> testCallbackRegistration = registrationFactory.RegisterUnitTestCallback(delegate { return test; });
Assert.AreEqual(test, testCallbackRegistration.UnitTestResolveCallback.Invoke());
}
[Test]
public void TestUnitTestResolveCallbackWithParams()
{
RegistrationFactory registrationFactory = new RegistrationFactory(new Mock<IIocContainer>().Object);
IUnitTestCallbackRegistration<ITest> testCallbackRegistration =
registrationFactory.RegisterUnitTestCallback(new ResolveCallback<ITest>(parameters => new Test((int) parameters[0], (string) parameters[1], (bool) parameters[2])));
ITest test = testCallbackRegistration.UnitTestResolveCallback.Invoke(4, "SomeTest", true);
Assert.AreEqual(4, test.Count);
Assert.AreEqual("SomeTest", test.Name);
Assert.True(test.Testing);
}
}
}
Loading…
Cancel
Save