From 4945fb803566fa0e4505369dd28126dc415a47a2 Mon Sep 17 00:00:00 2001 From: "Simon G." Date: Thu, 19 Dec 2024 08:14:36 +0100 Subject: [PATCH] - add failing test for openGeneric parameter validation --- .../IocValidatorTest.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Test.LightweightIocContainer.Validation/IocValidatorTest.cs b/Test.LightweightIocContainer.Validation/IocValidatorTest.cs index fc48b98..1b8480c 100644 --- a/Test.LightweightIocContainer.Validation/IocValidatorTest.cs +++ b/Test.LightweightIocContainer.Validation/IocValidatorTest.cs @@ -31,6 +31,9 @@ public class IocValidatorTest [UsedImplicitly] public interface IConstraint; + + [UsedImplicitly] + public class Constraint : IConstraint; [UsedImplicitly] public interface IGenericTest where T : IConstraint, new(); @@ -44,6 +47,18 @@ public class IocValidatorTest IGenericTest Create() where T : IConstraint, new(); } + [UsedImplicitly] + public interface IGenericParameter; + + [UsedImplicitly] + public class GenericParameter : IGenericParameter + { + public GenericParameter(IGenericTest test) + { + + } + } + [UsedImplicitly] private class TestViewModelDontIgnoreDesignTimeCtor : ITest { @@ -286,6 +301,17 @@ public class IocValidatorTest validator.Validate(); } + [Test] + public void TestValidateOpenGenericTypeAsParameter() + { + IocContainer iocContainer = new(); + iocContainer.Register(r => r.AddOpenGenerics(typeof(IGenericTest<>), typeof(GenericTest<>))); + iocContainer.Register(r => r.Add()); + + IocValidator validator = new(iocContainer); + validator.Validate(); + } + private void AssertNoMatchingConstructorFoundForType(AggregateException aggregateException) { Exception exception = aggregateException?.InnerExceptions[0];