pull/59/head
Simon G 3 years ago
parent f4517a809d
commit 66f3d78d1e
  1. 2
      LightweightIocContainer/Validation/IocValidator.cs
  2. 18
      Test.LightweightIocContainer/IocValidatorTest.cs

@ -63,7 +63,7 @@ namespace LightweightIocContainer.Validation
} }
else else
{ {
var arguments = definedParameters.Select(p => p.parameter).ToArray(); object?[] arguments = definedParameters.Select(p => p.parameter).ToArray();
TryResolve(registration.InterfaceType, arguments, validationExceptions); TryResolve(registration.InterfaceType, arguments, validationExceptions);
} }
} }

@ -30,7 +30,7 @@ namespace Test.LightweightIocContainer
private class Test : ITest private class Test : ITest
{ {
public Test(IParameter parameter) => parameter?.Method(); public Test(IParameter parameter) => parameter.Method();
} }
[UsedImplicitly] [UsedImplicitly]
@ -61,14 +61,14 @@ namespace Test.LightweightIocContainer
} }
[Test] [Test]
public void TestValidate() public void TestValidateWithoutFactory()
{ {
IocContainer iocContainer = new(); IocContainer iocContainer = new();
iocContainer.Install(new TestInstallerNoFactory()); iocContainer.Install(new TestInstallerNoFactory());
IocValidator validator = new(iocContainer); IocValidator validator = new(iocContainer);
var aggregateException = Assert.Throws<AggregateException>(() => validator.Validate()); AggregateException aggregateException = Assert.Throws<AggregateException>(() => validator.Validate());
AssertNoMatchingConstructorFoundForType<Test>(aggregateException); AssertNoMatchingConstructorFoundForType<Test>(aggregateException);
} }
@ -110,18 +110,18 @@ namespace Test.LightweightIocContainer
IocValidator validator = new(iocContainer); IocValidator validator = new(iocContainer);
var aggregateException = Assert.Throws<AggregateException>(() => validator.Validate()); AggregateException aggregateException = Assert.Throws<AggregateException>(() => validator.Validate());
AssertNoMatchingConstructorFoundForType<Test>(aggregateException); AssertNoMatchingConstructorFoundForType<Test>(aggregateException);
} }
private static void AssertNoMatchingConstructorFoundForType<T>(AggregateException aggregateException) private void AssertNoMatchingConstructorFoundForType<T>(AggregateException aggregateException)
{ {
Exception exception = aggregateException?.InnerExceptions[0]; Exception exception = aggregateException?.InnerExceptions[0];
Assert.IsInstanceOf<NoMatchingConstructorFoundException>(exception); if (exception is NoMatchingConstructorFoundException noMatchingConstructorFoundException)
Assert.AreEqual(typeof(T), noMatchingConstructorFoundException.Type);
NoMatchingConstructorFoundException noMatchingConstructorFoundException = (NoMatchingConstructorFoundException)exception; else
Assert.AreEqual(typeof(T), noMatchingConstructorFoundException?.Type); Assert.Fail($"Exception is no NoMatchingConstructorFoundException, actual type: {exception?.GetType()}");
} }
} }
} }
Loading…
Cancel
Save