- add validation test for factory of open generic type

ImplementExpressionTrees
Simon G. 2 years ago
parent 7cc36927ed
commit 3569c97589
Signed by: SimonG
GPG Key ID: 7CD6DBFB1B2786ED
  1. 34
      Test.LightweightIocContainer.Validation/IocValidatorTest.cs

@ -32,6 +32,30 @@ public class IocValidatorTest
public Test(IParameter parameter) => parameter.Method(); public Test(IParameter parameter) => parameter.Method();
} }
[UsedImplicitly]
public interface IConstraint
{
}
[UsedImplicitly]
public interface IGenericTest<T> where T : IConstraint, new()
{
}
[UsedImplicitly]
public class GenericTest<T> : IGenericTest<T> where T : IConstraint, new()
{
}
[UsedImplicitly]
public interface IGenericTestFactory
{
IGenericTest<T> Create<T>() where T : IConstraint, new();
}
[UsedImplicitly] [UsedImplicitly]
private class TestViewModelDontIgnoreDesignTimeCtor : ITest private class TestViewModelDontIgnoreDesignTimeCtor : ITest
{ {
@ -264,6 +288,16 @@ public class IocValidatorTest
AssertNoMatchingConstructorFoundForType<Test>(aggregateException); AssertNoMatchingConstructorFoundForType<Test>(aggregateException);
} }
[Test]
public void TestValidateFactoryOfOpenGenericType()
{
IocContainer iocContainer = new();
iocContainer.Register(r => r.AddOpenGenerics(typeof(IGenericTest<>), typeof(GenericTest<>)).WithFactory<IGenericTestFactory>());
IocValidator validator = new(iocContainer);
validator.Validate();
}
private void AssertNoMatchingConstructorFoundForType<T>(AggregateException aggregateException) private void AssertNoMatchingConstructorFoundForType<T>(AggregateException aggregateException)
{ {
Exception exception = aggregateException?.InnerExceptions[0]; Exception exception = aggregateException?.InnerExceptions[0];

Loading…
Cancel
Save