#46: start code cleanup

pull/53/head
Simon G 5 years ago
parent 6590efb388
commit cfa1eb816c
  1. 4
      LightweightIocContainer/Exceptions/ConstructorNotMatchingException.cs
  2. 4
      LightweightIocContainer/Exceptions/IllegalAbstractMethodCreationException.cs
  3. 9
      LightweightIocContainer/Exceptions/IocContainerException.cs
  4. 4
      LightweightIocContainer/Exceptions/MultipleRegistrationException.cs
  5. 4
      LightweightIocContainer/Exceptions/MultitonResolveException.cs
  6. 11
      LightweightIocContainer/Exceptions/NoMatchingConstructorFoundException.cs
  7. 4
      LightweightIocContainer/Exceptions/NoPublicConstructorFoundException.cs
  8. 4
      LightweightIocContainer/Exceptions/TypeNotRegisteredException.cs
  9. 5
      LightweightIocContainer/Installers/FromAssembly.cs
  10. 26
      LightweightIocContainer/IocContainer.cs
  11. 4
      LightweightIocContainer/Registrations/DefaultRegistration.cs
  12. 4
      LightweightIocContainer/Registrations/MultitonRegistration.cs
  13. 69
      LightweightIocContainer/Registrations/RegistrationFactory.cs
  14. 4
      LightweightIocContainer/Registrations/SingleTypeRegistration.cs
  15. 4
      LightweightIocContainer/Registrations/TypedRegistrationBase.cs
  16. 8
      Test.LightweightIocContainer/ActionExtensionTest.cs
  17. 8
      Test.LightweightIocContainer/AssemblyInstallerTest.cs
  18. 4
      Test.LightweightIocContainer/EnumerableExtensionTest.cs
  19. 24
      Test.LightweightIocContainer/IocContainerInterfaceSegregationTest.cs
  20. 15
      Test.LightweightIocContainer/IocContainerParameterRegistrationTest.cs
  21. 21
      Test.LightweightIocContainer/IocContainerRecursionTest.cs
  22. 56
      Test.LightweightIocContainer/IocContainerTest.cs
  23. 8
      Test.LightweightIocContainer/OnCreateTest.cs
  24. 8
      Test.LightweightIocContainer/OpenGenericRegistrationTest.cs
  25. 4
      Test.LightweightIocContainer/RegistrationBaseTest.cs
  26. 5
      Test.LightweightIocContainer/SingleTypeRegistrationTest.cs

@ -18,10 +18,8 @@ namespace LightweightIocContainer.Exceptions
/// <param name="constructor">The constructor that does not match</param>
/// <param name="exception">The inner exception</param>
public ConstructorNotMatchingException(ConstructorInfo constructor, Exception exception)
: base($"Constructor {constructor} does not match the given or resolvable arguments.", exception)
{
: base($"Constructor {constructor} does not match the given or resolvable arguments.", exception) =>
Constructor = constructor;
}
/// <summary>
/// The constructor that does not match

@ -17,10 +17,8 @@ namespace LightweightIocContainer.Exceptions
/// <param name="message">The exception message</param>
/// <param name="method">The method that is illegal to create</param>
public IllegalAbstractMethodCreationException(string message, MethodInfo method)
: base(message)
{
: base(message) =>
Method = method;
}
/// <summary>
/// The Method whose creation is illegal

@ -37,13 +37,8 @@ namespace LightweightIocContainer.Exceptions
/// <param name="message">The message of the <see cref="Exception"/></param>
/// <param name="innerException">The inner <see cref="Exception"/></param>
protected IocContainerException(string message, Exception innerException)
: base(message, innerException)
{
InnerExceptions = new List<Exception>()
{
innerException
};
}
: base(message, innerException) =>
InnerExceptions = new List<Exception>() {innerException};
/// <summary>
/// The inner exceptions of the <see cref="IocContainerException"/>

@ -17,10 +17,8 @@ namespace LightweightIocContainer.Exceptions
/// </summary>
/// <param name="type">The <see cref="System.Type"/> that is already registered in this <see cref="IIocContainer"/></param>
public MultipleRegistrationException(Type type)
: base($"Type {type.Name} is already registered in this IocContainer.")
{
: base($"Type {type.Name} is already registered in this IocContainer.") =>
Type = type;
}
/// <summary>
/// The registered <see cref="System.Type"/>

@ -17,10 +17,8 @@ namespace LightweightIocContainer.Exceptions
/// <param name="message">The exception message</param>
/// <param name="type">The <see cref="System.Type"/> of the multiton that's responsible for the exception</param>
public MultitonResolveException(string message, Type type)
: base(message)
{
: base(message) =>
Type = type;
}
/// <summary>
/// The <see cref="System.Type"/> of the multiton that's responsible for the exception

@ -22,11 +22,7 @@ namespace LightweightIocContainer.Exceptions
: base($"No matching constructor for {type} found.")
{
Type = type;
if (exceptions == null)
InnerExceptions = new List<Exception>();
else
InnerExceptions = exceptions.OfType<Exception>().ToList();
InnerExceptions = exceptions == null ? new List<Exception>() : exceptions.OfType<Exception>().ToList();
}
@ -39,9 +35,6 @@ namespace LightweightIocContainer.Exceptions
/// Add an inner exception to the <see cref="IocContainerException.InnerExceptions"/>
/// </summary>
/// <param name="exception">The <see cref="ConstructorNotMatchingException"/></param>
public void AddInnerException(ConstructorNotMatchingException exception)
{
InnerExceptions.Add(exception);
}
public void AddInnerException(ConstructorNotMatchingException exception) => InnerExceptions.Add(exception);
}
}

@ -16,10 +16,8 @@ namespace LightweightIocContainer.Exceptions
/// </summary>
/// <param name="type">The <see cref="Type"/> with no public constructor</param>
public NoPublicConstructorFoundException(Type type)
: base($"No public constructor for {type} found.")
{
: base($"No public constructor for {type} found.") =>
Type = type;
}
/// <summary>
/// The <see cref="Type"/> with no public constructor

@ -17,10 +17,8 @@ namespace LightweightIocContainer.Exceptions
/// </summary>
/// <param name="type">The unregistered <see cref="System.Type"/></param>
public TypeNotRegisteredException(Type type)
: base($"Type {type.Name} is not registered in this IocContainer.")
{
: base($"Type {type.Name} is not registered in this IocContainer.") =>
Type = type;
}
/// <summary>
/// The unregistered <see cref="System.Type"/>

@ -27,9 +27,6 @@ namespace LightweightIocContainer.Installers
/// </summary>
/// <param name="assembly">The given <see cref="Assembly"/></param>
/// <returns>A new <see cref="IAssemblyInstaller"/> with the given <see cref="Assembly"/></returns>
public static IAssemblyInstaller Instance(Assembly assembly)
{
return new AssemblyInstaller(assembly);
}
public static IAssemblyInstaller Instance(Assembly assembly) => new AssemblyInstaller(assembly);
}
}

@ -32,11 +32,7 @@ namespace LightweightIocContainer
/// <summary>
/// The main container that carries all the <see cref="IRegistration"/>s and can resolve all the types you'll ever want
/// </summary>
public IocContainer()
{
_registrationFactory = new RegistrationFactory(this);
}
public IocContainer() => _registrationFactory = new RegistrationFactory(this);
/// <summary>
/// Install the given installers for the current <see cref="IocContainer"/>
@ -259,10 +255,7 @@ namespace LightweightIocContainer
/// </summary>
/// <typeparam name="T">The given <see cref="Type"/></typeparam>
/// <returns>An instance of the given <see cref="Type"/></returns>
public T Resolve<T>()
{
return ResolveInternal<T>(null);
}
public T Resolve<T>() => ResolveInternal<T>(null);
/// <summary>
/// Gets an instance of the given <see cref="Type"/>
@ -270,10 +263,7 @@ namespace LightweightIocContainer
/// <typeparam name="T">The given <see cref="Type"/></typeparam>
/// <param name="arguments">The constructor arguments</param>
/// <returns>An instance of the given <see cref="Type"/></returns>
public T Resolve<T>(params object[] arguments)
{
return ResolveInternal<T>(arguments);
}
public T Resolve<T>(params object[] arguments) => ResolveInternal<T>(arguments);
/// <summary>
/// Gets an instance of the given <see cref="Type"/>
@ -283,10 +273,8 @@ namespace LightweightIocContainer
/// <param name="resolveStack">The current resolve stack</param>
/// <returns>An instance of the given <see cref="Type"/></returns>
/// <exception cref="InternalResolveException">Could not find function <see cref="ResolveInternal{T}"/></exception>
private object Resolve(Type type, object[] arguments, List<Type> resolveStack)
{
return GenericMethodCaller.Call(this, nameof(ResolveInternal), type, BindingFlags.NonPublic | BindingFlags.Instance, arguments, resolveStack);
}
private object Resolve(Type type, object[] arguments, List<Type> resolveStack) =>
GenericMethodCaller.Call(this, nameof(ResolveInternal), type, BindingFlags.NonPublic | BindingFlags.Instance, arguments, resolveStack);
/// <summary>
/// Gets an instance of a given registered <see cref="Type"/>
@ -582,9 +570,7 @@ namespace LightweightIocContainer
}
catch (Exception ex)
{
if (noMatchingConstructorFoundException == null)
noMatchingConstructorFoundException = new NoMatchingConstructorFoundException(type);
noMatchingConstructorFoundException ??= new NoMatchingConstructorFoundException(type);
noMatchingConstructorFoundException.AddInnerException(new ConstructorNotMatchingException(ctor, ex));
}
}

@ -21,9 +21,7 @@ namespace LightweightIocContainer.Registrations
/// <param name="implementationType">The <see cref="Type"/> of the implementation</param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> of the <see cref="RegistrationBase{TInterface}"/></param>
public DefaultRegistration(Type interfaceType, Type implementationType, Lifestyle lifestyle)
: base(interfaceType, implementationType, lifestyle)
{
: base(interfaceType, implementationType, lifestyle) =>
Name = $"{InterfaceType.Name}, {ImplementationType.Name}, Lifestyle: {Lifestyle.ToString()}";
}
}
}

@ -21,10 +21,8 @@ namespace LightweightIocContainer.Registrations
/// <param name="implementationType">The <see cref="Type"/> of the Implementation</param>
/// <param name="scope">The <see cref="Type"/> of the Multiton Scope</param>
public MultitonRegistration(Type interfaceType, Type implementationType, Type scope)
: base(interfaceType, implementationType, Lifestyle.Multiton)
{
: base(interfaceType, implementationType, Lifestyle.Multiton) =>
Scope = scope;
}
/// <summary>
/// The <see cref="Type"/> of the multiton scope

@ -16,10 +16,7 @@ namespace LightweightIocContainer.Registrations
{
private readonly IIocContainer _iocContainer;
internal RegistrationFactory(IIocContainer container)
{
_iocContainer = container;
}
internal RegistrationFactory(IIocContainer container) => _iocContainer = container;
/// <summary>
/// Register an Interface with a Type that implements it and create a <see cref="IDefaultRegistration{TInterface,TImplementation}"/>
@ -28,15 +25,17 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="TImplementation">The Type that implements the interface</typeparam>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IDefaultRegistration{TInterface,TImplementation}"/></param>
/// <returns>A new created <see cref="IDefaultRegistration{TInterface,TImplementation}"/> with the given parameters</returns>
public IDefaultRegistration<TInterface, TImplementation> Register<TInterface, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface
{
return new DefaultRegistration<TInterface, TImplementation>(typeof(TInterface), typeof(TImplementation), lifestyle);
}
public IDefaultRegistration<TInterface, TImplementation> Register<TInterface, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface =>
new DefaultRegistration<TInterface, TImplementation>(typeof(TInterface), typeof(TImplementation), lifestyle);
public IOpenGenericRegistration Register(Type tInterface, Type tImplementation, Lifestyle lifestyle)
{
return new OpenGenericRegistration(tInterface, tImplementation, lifestyle);
}
/// <summary>
/// Register an open generic Interface with an open generic Type that implements it and create a <see cref="IOpenGenericRegistration"/>
/// </summary>
/// <param name="tInterface">The open generic Interface to register</param>
/// <param name="tImplementation">The open generic Type that implements the interface</param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IOpenGenericRegistration"/></param>
/// <returns>The created <see cref="IOpenGenericRegistration"/></returns>
public IOpenGenericRegistration Register(Type tInterface, Type tImplementation, Lifestyle lifestyle) => new OpenGenericRegistration(tInterface, tImplementation, lifestyle);
/// <summary>
/// Register multiple interfaces for a <see cref="Type"/> that implements them and create a <see cref="IMultipleRegistration{TInterface1,TInterface2}"/>
@ -46,10 +45,8 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="TImplementation">The <see cref="Type"/> that implements both interfaces</typeparam>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IRegistrationBase{TInterface}"/></param>
/// <returns>The created <see cref="IMultipleRegistration{TInterface1,TInterface2}"/></returns>
public IMultipleRegistration<TInterface1, TInterface2, TImplementation> Register<TInterface1, TInterface2, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2
{
return new MultipleRegistration<TInterface1, TInterface2, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TImplementation), lifestyle);
}
public IMultipleRegistration<TInterface1, TInterface2, TImplementation> Register<TInterface1, TInterface2, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2 =>
new MultipleRegistration<TInterface1, TInterface2, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TImplementation), lifestyle);
/// <summary>
/// Register multiple interfaces for a <see cref="Type"/> that implements them and create a <see cref="IMultipleRegistration{TInterface1,TInterface2,TInterface3}"/>
@ -60,10 +57,8 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="TImplementation">The <see cref="Type"/> that implements both interfaces</typeparam>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IRegistrationBase{TInterface}"/></param>
/// <returns>The created <see cref="IMultipleRegistration{TInterface1,TInterface2,TInterface3}"/></returns>
public IMultipleRegistration<TInterface1, TInterface2, TInterface3, TImplementation> Register<TInterface1, TInterface2, TInterface3, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3
{
return new MultipleRegistration<TInterface1, TInterface2, TInterface3, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TImplementation), lifestyle);
}
public IMultipleRegistration<TInterface1, TInterface2, TInterface3, TImplementation> Register<TInterface1, TInterface2, TInterface3, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3 =>
new MultipleRegistration<TInterface1, TInterface2, TInterface3, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TImplementation), lifestyle);
/// <summary>
/// Register multiple interfaces for a <see cref="Type"/> that implements them and create a <see cref="IMultipleRegistration{TInterface1,TInterface2,TInterface3,TInterface4}"/>
@ -75,10 +70,8 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="TImplementation">The <see cref="Type"/> that implements both interfaces</typeparam>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IRegistrationBase{TInterface}"/></param>
/// <returns>The created <see cref="IMultipleRegistration{TInterface1,TInterface2,TInterface3,TInterface4}"/></returns>
public IMultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TImplementation> Register<TInterface1, TInterface2, TInterface3, TInterface4, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3, TInterface4
{
return new MultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TInterface4), typeof(TImplementation), lifestyle);
}
public IMultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TImplementation> Register<TInterface1, TInterface2, TInterface3, TInterface4, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3, TInterface4 =>
new MultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TInterface4), typeof(TImplementation), lifestyle);
/// <summary>
/// Register multiple interfaces for a <see cref="Type"/> that implements them and create a <see cref="IMultipleRegistration{TInterface1,TInterface2,TInterface3,TInterface4,TInterface5}"/>
@ -91,10 +84,8 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="TImplementation">The <see cref="Type"/> that implements both interfaces</typeparam>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IRegistrationBase{TInterface}"/></param>
/// <returns>The created <see cref="IMultipleRegistration{TInterface1,TInterface2,TInterface3,TInterface4,TInterface5}"/></returns>
public IMultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TInterface5, TImplementation> Register<TInterface1, TInterface2, TInterface3, TInterface4, TInterface5, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3, TInterface4, TInterface5
{
return new MultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TInterface5, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TInterface4), typeof(TInterface5), typeof(TImplementation), lifestyle);
}
public IMultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TInterface5, TImplementation> Register<TInterface1, TInterface2, TInterface3, TInterface4, TInterface5, TImplementation>(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3, TInterface4, TInterface5 =>
new MultipleRegistration<TInterface1, TInterface2, TInterface3, TInterface4, TInterface5, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TInterface4), typeof(TInterface5), typeof(TImplementation), lifestyle);
/// <summary>
/// Register a <see cref="Type"/> without an interface and create a <see cref="ISingleTypeRegistration{TInterface}"/>
@ -102,10 +93,7 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="T">The <see cref="Type"/> to register</typeparam>
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="ISingleTypeRegistration{TInterface}"/></param>
/// <returns>A new created <see cref="ISingleTypeRegistration{TInterface}"/> with the given parameters</returns>
public ISingleTypeRegistration<T> Register<T>(Lifestyle lifestyle)
{
return new SingleTypeRegistration<T>(typeof(T), lifestyle);
}
public ISingleTypeRegistration<T> Register<T>(Lifestyle lifestyle) => new SingleTypeRegistration<T>(typeof(T), lifestyle);
/// <summary>
/// Register an Interface with a Type that implements it as a multiton and create a <see cref="IMultitonRegistration{TInterface,TImplementation}"/>
@ -114,10 +102,8 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="TImplementation">The Type that implements the interface</typeparam>
/// <typeparam name="TScope">The Type of the multiton scope</typeparam>
/// <returns>A new created <see cref="IMultitonRegistration{TInterface,TImplementation}"/> with the given parameters</returns>
public IMultitonRegistration<TInterface, TImplementation> RegisterMultiton<TInterface, TImplementation, TScope>() where TImplementation : TInterface
{
return new MultitonRegistration<TInterface, TImplementation>(typeof(TInterface), typeof(TImplementation), typeof(TScope));
}
public IMultitonRegistration<TInterface, TImplementation> RegisterMultiton<TInterface, TImplementation, TScope>() where TImplementation : TInterface =>
new MultitonRegistration<TInterface, TImplementation>(typeof(TInterface), typeof(TImplementation), typeof(TScope));
/// <summary>
/// Register multiple interfaces for a <see cref="Type"/> that implements them as a multiton
@ -127,19 +113,14 @@ namespace LightweightIocContainer.Registrations
/// <typeparam name="TImplementation">The Type that implements the interface</typeparam>
/// <typeparam name="TScope">The Type of the multiton scope</typeparam>
/// <returns>A new created <see cref="IMultipleMultitonRegistration{TInterface1,TInterface2,TImplementation}"/> with the given parameters</returns>
public IMultipleMultitonRegistration<TInterface1, TInterface2, TImplementation> RegisterMultiton<TInterface1, TInterface2, TImplementation, TScope>() where TImplementation : TInterface1, TInterface2
{
return new MultipleMultitonRegistration<TInterface1, TInterface2, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TImplementation), typeof(TScope));
}
public IMultipleMultitonRegistration<TInterface1, TInterface2, TImplementation> RegisterMultiton<TInterface1, TInterface2, TImplementation, TScope>() where TImplementation : TInterface1, TInterface2 =>
new MultipleMultitonRegistration<TInterface1, TInterface2, TImplementation>(typeof(TInterface1), typeof(TInterface2), typeof(TImplementation), typeof(TScope));
/// <summary>
/// Register an Interface as an abstract typed factory and create a <see cref="ITypedFactoryRegistration{TFactory}"/>
/// </summary>
/// <typeparam name="TFactory">The abstract typed factory to register</typeparam>
/// <returns>A new created <see cref="ITypedFactoryRegistration{TFactory}"/> with the given parameters</returns>
public ITypedFactoryRegistration<TFactory> RegisterFactory<TFactory>()
{
return new TypedFactoryRegistration<TFactory>(typeof(TFactory), _iocContainer);
}
public ITypedFactoryRegistration<TFactory> RegisterFactory<TFactory>() => new TypedFactoryRegistration<TFactory>(typeof(TFactory), _iocContainer);
}
}

@ -20,10 +20,8 @@ namespace LightweightIocContainer.Registrations
/// <param name="interfaceType">The <see cref="Type"/> of the interface or <see cref="Type"/></param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> of the <see cref="RegistrationBase{TInterface}"/></param>
public SingleTypeRegistration(Type interfaceType, Lifestyle lifestyle)
: base(interfaceType, lifestyle)
{
: base(interfaceType, lifestyle) =>
Name = $"{InterfaceType.Name}, Lifestyle: {Lifestyle.ToString()}";
}
/// <summary>
/// <see cref="Func{T,TResult}"/> that is invoked instead of creating an instance of this <see cref="Type"/> the default way

@ -21,10 +21,8 @@ namespace LightweightIocContainer.Registrations
/// <param name="implementationType">The <see cref="Type"/> of the implementation type</param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> of this <see cref="IRegistrationBase{TInterface}"/></param>
protected TypedRegistrationBase(Type interfaceType, Type implementationType, Lifestyle lifestyle)
: base(interfaceType, lifestyle)
{
: base(interfaceType, lifestyle) =>
ImplementationType = implementationType;
}
/// <summary>
/// The <see cref="Type"/> that implements the <see cref="IRegistration.InterfaceType"/> that is registered with this <see cref="IRegistrationBase{TInterface}"/>

@ -11,8 +11,6 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class ActionExtensionTest
{
#region TestClasses
private interface IBar
{
void Throw();
@ -25,13 +23,9 @@ namespace Test.LightweightIocContainer
private class Foo : IFoo
{
public void Throw()
{
throw new Exception();
}
public void Throw() => throw new Exception();
}
#endregion TestClasses
[Test]
public void TestConvert()

@ -19,14 +19,9 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class AssemblyInstallerTest
{
#region TestClasses
private class TestInstaller : IIocInstaller
{
public void Install(IIocContainer container)
{
container.Register<Mock<IRegistration>>();
}
public void Install(IIocContainer container) => container.Register<Mock<IRegistration>>();
}
[UsedImplicitly]
@ -35,7 +30,6 @@ namespace Test.LightweightIocContainer
}
#endregion TestClasses
[Test]
public void TestInstall()

@ -12,8 +12,6 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class EnumerableExtensionTest
{
#region TestClasses
private class ListObject
{
public int Index { get; set; }
@ -24,8 +22,6 @@ namespace Test.LightweightIocContainer
}
#endregion TestClasses
[Test]
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Local")]

@ -3,6 +3,7 @@
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using JetBrains.Annotations;
using LightweightIocContainer;
using LightweightIocContainer.Interfaces;
using NUnit.Framework;
@ -12,10 +13,9 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class IocContainerInterfaceSegregationTest
{
#region TestClasses
private interface IBar
{
}
private interface IFoo
@ -24,39 +24,33 @@ namespace Test.LightweightIocContainer
}
private interface IAnotherBar
{
}
private interface IAnotherFoo
{
}
private interface IAnotherOne
{
}
[UsedImplicitly]
private class Foo : IFoo, IBar, IAnotherFoo, IAnotherBar, IAnotherOne
{
public void ThrowFoo()
{
throw new Exception("Foo");
}
public void ThrowFoo() => throw new Exception("Foo");
}
#endregion TestClasses
private IIocContainer _container;
[SetUp]
public void SetUp()
{
_container = new IocContainer();
}
public void SetUp() => _container = new IocContainer();
[TearDown]
public void TearDown()
{
_container.Dispose();
}
public void TearDown() => _container.Dispose();
[Test]
public void TestRegistrationOnCreate2()

@ -13,8 +13,6 @@ namespace Test.LightweightIocContainer
// ReSharper disable MemberHidesStaticFromOuterClass
public class IocContainerParameterRegistrationTest
{
#region TestClasses
[UsedImplicitly]
public interface IA
{
@ -61,6 +59,7 @@ namespace Test.LightweightIocContainer
{
public B(IC c)
{
}
}
@ -87,22 +86,14 @@ namespace Test.LightweightIocContainer
public IC C { get; }
}
#endregion TestClasses
private IIocContainer _iocContainer;
[SetUp]
public void SetUp()
{
_iocContainer = new IocContainer();
}
public void SetUp() => _iocContainer = new IocContainer();
[TearDown]
public void TearDown()
{
_iocContainer.Dispose();
}
public void TearDown() => _iocContainer.Dispose();
[Test]

@ -14,8 +14,6 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class IocContainerRecursionTest
{
#region TestClassesCircularDependency
[UsedImplicitly]
public interface IFoo
{
@ -44,10 +42,6 @@ namespace Test.LightweightIocContainer
}
}
#endregion TestClassesCircularDependency
#region TestClassesNonCircularDependency
[UsedImplicitly]
public interface IA
{
@ -71,6 +65,7 @@ namespace Test.LightweightIocContainer
{
public A(IB b, IC c)
{
}
}
@ -79,6 +74,7 @@ namespace Test.LightweightIocContainer
{
public B(IC c)
{
}
}
@ -88,23 +84,14 @@ namespace Test.LightweightIocContainer
}
#endregion TestClassesNonCircularDependency
private IIocContainer _iocContainer;
[SetUp]
public void SetUp()
{
_iocContainer = new IocContainer();
}
public void SetUp() => _iocContainer = new IocContainer();
[TearDown]
public void TearDown()
{
_iocContainer.Dispose();
}
public void TearDown() => _iocContainer.Dispose();
[Test]
public void TestCircularDependencies()

@ -11,9 +11,6 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class IocContainerTest
{
#region TestClasses
//some of the test classes have to be public to allow the implementation of the factory
public interface ITest
{
@ -101,10 +98,7 @@ namespace Test.LightweightIocContainer
[UsedImplicitly]
private readonly byte _id;
public TestByte(byte id)
{
_id = id;
}
public TestByte(byte id) => _id = id;
}
[UsedImplicitly]
@ -118,23 +112,14 @@ namespace Test.LightweightIocContainer
}
#endregion TestClasses
private IIocContainer _iocContainer;
[SetUp]
public void SetUp()
{
_iocContainer = new IocContainer();
}
public void SetUp() => _iocContainer = new IocContainer();
[TearDown]
public void TearDown()
{
_iocContainer.Dispose();
}
public void TearDown() => _iocContainer.Dispose();
[Test]
@ -165,34 +150,19 @@ namespace Test.LightweightIocContainer
}
[Test]
public void TestRegister()
{
Assert.DoesNotThrow(() => _iocContainer.Register<ITest, Test>());
}
public void TestRegister() => Assert.DoesNotThrow(() => _iocContainer.Register<ITest, Test>());
[Test]
public void TestRegisterTypeWithoutInterface()
{
Assert.DoesNotThrow(() => _iocContainer.Register<Test>());
}
public void TestRegisterTypeWithoutInterface() => Assert.DoesNotThrow(() => _iocContainer.Register<Test>());
[Test]
public void TestRegisterMultiton()
{
Assert.DoesNotThrow(() => _iocContainer.RegisterMultiton<ITest, Test, MultitonScope>());
}
public void TestRegisterMultiton() => Assert.DoesNotThrow(() => _iocContainer.RegisterMultiton<ITest, Test, MultitonScope>());
[Test]
public void TestInvalidMultitonRegistration()
{
Assert.Throws<InvalidRegistrationException>(() => _iocContainer.Register<ITest, Test>(Lifestyle.Multiton));
}
public void TestInvalidMultitonRegistration() => Assert.Throws<InvalidRegistrationException>(() => _iocContainer.Register<ITest, Test>(Lifestyle.Multiton));
[Test]
public void TestRegisterFactory()
{
Assert.DoesNotThrow(() => _iocContainer.RegisterFactory<ITestFactory>());
}
public void TestRegisterFactory() => Assert.DoesNotThrow(() => _iocContainer.RegisterFactory<ITestFactory>());
[Test]
public void TestRegisterMultiple()
@ -203,16 +173,10 @@ namespace Test.LightweightIocContainer
}
[Test]
public void TestRegisterFactoryWithoutCreate()
{
Assert.Throws<InvalidFactoryRegistrationException>(() => _iocContainer.RegisterFactory<ITestFactoryNoCreate>());
}
public void TestRegisterFactoryWithoutCreate() => Assert.Throws<InvalidFactoryRegistrationException>(() => _iocContainer.RegisterFactory<ITestFactoryNoCreate>());
[Test]
public void TestRegisterFactoryClearMultitonsNonGeneric()
{
Assert.Throws<IllegalAbstractMethodCreationException>(() => _iocContainer.RegisterFactory<ITestFactoryNonGenericClear>());
}
public void TestRegisterFactoryClearMultitonsNonGeneric() => Assert.Throws<IllegalAbstractMethodCreationException>(() => _iocContainer.RegisterFactory<ITestFactoryNonGenericClear>());
[Test]
public void TestResolveNotRegistered()

@ -15,8 +15,6 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class OnCreateTest
{
#region TestClasses
private interface ITest
{
void DoSomething();
@ -24,13 +22,9 @@ namespace Test.LightweightIocContainer
private class Test : ITest
{
public void DoSomething()
{
throw new Exception();
}
public void DoSomething() => throw new Exception();
}
#endregion
[Test]
public void TestOnCreate()

@ -60,11 +60,11 @@ namespace Test.LightweightIocContainer
}
[Test]
public void TestRegisterOpenGenericTypeAsMultitonThrowsException()
=> Assert.Throws<InvalidRegistrationException>(() => _iocContainer.RegisterOpenGenerics(typeof(ITest<>), typeof(Test<>), Lifestyle.Multiton));
public void TestRegisterOpenGenericTypeAsMultitonThrowsException() =>
Assert.Throws<InvalidRegistrationException>(() => _iocContainer.RegisterOpenGenerics(typeof(ITest<>), typeof(Test<>), Lifestyle.Multiton));
[Test]
public void TestRegisterNonOpenGenericTypeWithOpenGenericsFunctionThrowsException()
=> Assert.Throws<InvalidRegistrationException>(() => _iocContainer.RegisterOpenGenerics(typeof(int), typeof(int)));
public void TestRegisterNonOpenGenericTypeWithOpenGenericsFunctionThrowsException() =>
Assert.Throws<InvalidRegistrationException>(() => _iocContainer.RegisterOpenGenerics(typeof(int), typeof(int)));
}
}

@ -16,8 +16,6 @@ namespace Test.LightweightIocContainer
[TestFixture]
public class RegistrationBaseTest
{
#region TestClasses
private interface ITest
{
@ -52,8 +50,6 @@ namespace Test.LightweightIocContainer
}
#endregion
[Test]
public void TestWithParameters()

@ -29,10 +29,7 @@ namespace Test.LightweightIocContainer
[UsedImplicitly]
private class Foo : IFoo
{
public Foo(IBar bar)
{
Bar = bar;
}
public Foo(IBar bar) => Bar = bar;
public IBar Bar { get; }
}

Loading…
Cancel
Save