From 3569c975894352d227c6c2fc7bdb752625fd06f1 Mon Sep 17 00:00:00 2001 From: "Simon G." Date: Wed, 1 Nov 2023 20:17:56 +0100 Subject: [PATCH] - add validation test for factory of open generic type --- .../IocValidatorTest.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Test.LightweightIocContainer.Validation/IocValidatorTest.cs b/Test.LightweightIocContainer.Validation/IocValidatorTest.cs index f4e8b4d..98ca6c8 100644 --- a/Test.LightweightIocContainer.Validation/IocValidatorTest.cs +++ b/Test.LightweightIocContainer.Validation/IocValidatorTest.cs @@ -31,6 +31,30 @@ public class IocValidatorTest { public Test(IParameter parameter) => parameter.Method(); } + + [UsedImplicitly] + public interface IConstraint + { + + } + + [UsedImplicitly] + public interface IGenericTest where T : IConstraint, new() + { + + } + + [UsedImplicitly] + public class GenericTest : IGenericTest where T : IConstraint, new() + { + + } + + [UsedImplicitly] + public interface IGenericTestFactory + { + IGenericTest Create() where T : IConstraint, new(); + } [UsedImplicitly] private class TestViewModelDontIgnoreDesignTimeCtor : ITest @@ -264,6 +288,16 @@ public class IocValidatorTest AssertNoMatchingConstructorFoundForType(aggregateException); } + [Test] + public void TestValidateFactoryOfOpenGenericType() + { + IocContainer iocContainer = new(); + iocContainer.Register(r => r.AddOpenGenerics(typeof(IGenericTest<>), typeof(GenericTest<>)).WithFactory()); + + IocValidator validator = new(iocContainer); + validator.Validate(); + } + private void AssertNoMatchingConstructorFoundForType(AggregateException aggregateException) { Exception exception = aggregateException?.InnerExceptions[0];