|
|
|
@ -2,8 +2,10 @@ |
|
|
|
// Created: 2021-12-03 |
|
|
|
// Created: 2021-12-03 |
|
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved. |
|
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using JetBrains.Annotations; |
|
|
|
using JetBrains.Annotations; |
|
|
|
using LightweightIocContainer; |
|
|
|
using LightweightIocContainer; |
|
|
|
|
|
|
|
using LightweightIocContainer.Exceptions; |
|
|
|
using LightweightIocContainer.Interfaces; |
|
|
|
using LightweightIocContainer.Interfaces; |
|
|
|
using LightweightIocContainer.Interfaces.Installers; |
|
|
|
using LightweightIocContainer.Interfaces.Installers; |
|
|
|
using LightweightIocContainer.Validation; |
|
|
|
using LightweightIocContainer.Validation; |
|
|
|
@ -37,11 +39,22 @@ namespace Test.LightweightIocContainer |
|
|
|
ITest Create(IParameter parameter); |
|
|
|
ITest Create(IParameter parameter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly] |
|
|
|
|
|
|
|
public interface IInvalidFactory |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ITest Create(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class TestInstaller : IIocInstaller |
|
|
|
private class TestInstaller : IIocInstaller |
|
|
|
{ |
|
|
|
{ |
|
|
|
public void Install(IIocContainer container) => container.Register<ITest, Test>().WithFactory<ITestFactory>(); |
|
|
|
public void Install(IIocContainer container) => container.Register<ITest, Test>().WithFactory<ITestFactory>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class InvalidTestInstaller : IIocInstaller |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public void Install(IIocContainer container) => container.Register<ITest, Test>().WithFactory<IInvalidFactory>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
[Test] |
|
|
|
public void TestValidate() |
|
|
|
public void TestValidate() |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -70,5 +83,22 @@ namespace Test.LightweightIocContainer |
|
|
|
|
|
|
|
|
|
|
|
parameterMock.Verify(p => p.Method(), Times.Once); |
|
|
|
parameterMock.Verify(p => p.Method(), Times.Once); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
|
|
public void TestValidateInvalidFactory() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IocContainer iocContainer = new(); |
|
|
|
|
|
|
|
iocContainer.Install(new InvalidTestInstaller()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IocValidator validator = new(iocContainer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AggregateException aggregateException = Assert.Throws<AggregateException>(() => validator.Validate()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Exception exception = aggregateException?.InnerExceptions[0]; |
|
|
|
|
|
|
|
Assert.IsInstanceOf<NoMatchingConstructorFoundException>(exception); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NoMatchingConstructorFoundException noMatchingConstructorFoundException = (NoMatchingConstructorFoundException) exception; |
|
|
|
|
|
|
|
Assert.AreEqual(typeof(Test), noMatchingConstructorFoundException?.Type); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |