diff --git a/test/DryIoc.UnitTests/RequiredPropertiesTests.cs b/test/DryIoc.UnitTests/RequiredPropertiesTests.cs index 667acc034..3fdd5c376 100644 --- a/test/DryIoc.UnitTests/RequiredPropertiesTests.cs +++ b/test/DryIoc.UnitTests/RequiredPropertiesTests.cs @@ -13,8 +13,10 @@ public int Run() { Can_inject_required_properties(); Should_throw_for_unresolved_required_property(); - Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties(); - return 3; + Should_skip_required_property_injection_when_using_ctor_which_SetsRequiredProperties(); + Works_with_constructor_selector(); + Works_with_open_generic_registration_and_constructor_selector_which_SetsRequiredProperties(); + return 5; } [Test] @@ -49,7 +51,7 @@ public void Should_throw_for_unresolved_required_property() } [Test] - public void Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties() + public void Should_skip_required_property_injection_when_using_ctor_which_SetsRequiredProperties() { var c = new Container(Rules.Default.With(propertiesAndFields: PropertiesAndFields.RequiredProperties())); @@ -64,6 +66,44 @@ public void Should_skip_required_property_injection_when_using_ctor_with_SetsReq Assert.NotNull(x.B); } + [Test] + public void Works_with_constructor_selector() + { + var c = new Container( + Rules.Default.With( + factoryMethod: FactoryMethod.ConstructorWithResolvableArguments, + propertiesAndFields: PropertiesAndFields.RequiredProperties())); + + c.Register(); + + c.Register(); + c.Register(); + + var x = c.Resolve(); + + Assert.NotNull(x.A); + Assert.NotNull(x.B); + } + + [Test] + public void Works_with_open_generic_registration_and_constructor_selector_which_SetsRequiredProperties() + { + var c = new Container( + Rules.Default.With( + factoryMethod: FactoryMethod.ConstructorWithResolvableArguments, + propertiesAndFields: PropertiesAndFields.RequiredProperties())); + + c.Register(typeof(SS<>)); + c.Register(typeof(B<>)); + c.Register(); + + var x = c.Resolve>(); + + Assert.Null(x.A); + Assert.NotNull(x.B); + Assert.IsInstanceOf(x.B.A); + } + public class A {} public class B {} public class C {} @@ -90,6 +130,32 @@ public class SS [SetsRequiredMembers] public SS(B b) => B = b; } + + public class SSS + { + public required A A { get; init; } + public B B { get; private set; } + + public SSS(B b) => B = b; + + public SSS() => B = null; + } + + public class B + { + public required T A { get; init; } + } + + public class SS + { + public required A A { get; init; } + public B B { get; private set; } + + [SetsRequiredMembers] + public SS(B b) => B = b; + + public SS() => B = null; + } #endif } } \ No newline at end of file