diff --git a/LightweightIocContainer/Validation/IocValidator.cs b/LightweightIocContainer/Validation/IocValidator.cs index b7f42ef..7f8dce9 100644 --- a/LightweightIocContainer/Validation/IocValidator.cs +++ b/LightweightIocContainer/Validation/IocValidator.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); } } diff --git a/Test.LightweightIocContainer/IocValidatorTest.cs b/Test.LightweightIocContainer/IocValidatorTest.cs index 7af50ee..12f5724 100644 --- a/Test.LightweightIocContainer/IocValidatorTest.cs +++ b/Test.LightweightIocContainer/IocValidatorTest.cs @@ -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(() => validator.Validate()); + AggregateException aggregateException = Assert.Throws(() => validator.Validate()); AssertNoMatchingConstructorFoundForType(aggregateException); } @@ -110,18 +110,18 @@ namespace Test.LightweightIocContainer IocValidator validator = new(iocContainer); - var aggregateException = Assert.Throws(() => validator.Validate()); + AggregateException aggregateException = Assert.Throws(() => validator.Validate()); AssertNoMatchingConstructorFoundForType(aggregateException); } - private static void AssertNoMatchingConstructorFoundForType(AggregateException aggregateException) + private void AssertNoMatchingConstructorFoundForType(AggregateException aggregateException) { Exception exception = aggregateException?.InnerExceptions[0]; - Assert.IsInstanceOf(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()}"); } } } \ No newline at end of file