- add another test case

master
Simon G. 11 months ago
parent 3d55222ef0
commit d6765ac85a
Signed by: SimonG
GPG Key ID: 0B82B964BA536523
  1. 22
      Test.LightweightIocContainer/OpenGenericRegistrationTest.cs

@ -76,6 +76,18 @@ public class OpenGenericRegistrationTest
public ITest<AnotherConstraint> Test { get; } = test; public ITest<AnotherConstraint> Test { get; } = test;
} }
[UsedImplicitly]
public interface IGenericClass<T> where T : IConstraint, new()
{
ITest<T> Test { get; }
}
[UsedImplicitly]
public class GenericClass<T>(ITest<T> test) : IGenericClass<T> where T : IConstraint, new()
{
public ITest<T> Test { get; } = test;
}
[SetUp] [SetUp]
public void SetUp() => _iocContainer = new IocContainer(); public void SetUp() => _iocContainer = new IocContainer();
@ -157,4 +169,14 @@ public class OpenGenericRegistrationTest
Assert.That(b.Test, Is.Not.SameAs(a.Test)); Assert.That(b.Test, Is.Not.SameAs(a.Test));
} }
[Test]
public void TestOpenGenericTypeAsGenericParameter()
{
_iocContainer.Register(r => r.AddOpenGenerics(typeof(IGenericClass<>), typeof(GenericClass<>)));
_iocContainer.Register(r => r.AddOpenGenerics(typeof(ITest<>), typeof(Test<>), Lifestyle.Singleton));
IGenericClass<Constraint> genericClass = _iocContainer.Resolve<IGenericClass<Constraint>>();
Assert.That(genericClass, Is.InstanceOf<GenericClass<Constraint>>());
}
} }
Loading…
Cancel
Save