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
{
var arguments = definedParameters.Select(p => p.parameter).ToArray();
object?[] arguments = definedParameters.Select(p => p.parameter).ToArray();
TryResolve(registration.InterfaceType, arguments, validationExceptions);
}
}

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