Skip to content

Commit 9db74c1

Browse files
committed
tests complete for #563
1 parent b288578 commit 9db74c1

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

test/DryIoc.UnitTests/RequiredPropertiesTests.cs

+69-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ public int Run()
1313
{
1414
Can_inject_required_properties();
1515
Should_throw_for_unresolved_required_property();
16-
Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties();
17-
return 3;
16+
Should_skip_required_property_injection_when_using_ctor_which_SetsRequiredProperties();
17+
Works_with_constructor_selector();
18+
Works_with_open_generic_registration_and_constructor_selector_which_SetsRequiredProperties();
19+
return 5;
1820
}
1921

2022
[Test]
@@ -49,7 +51,7 @@ public void Should_throw_for_unresolved_required_property()
4951
}
5052

5153
[Test]
52-
public void Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties()
54+
public void Should_skip_required_property_injection_when_using_ctor_which_SetsRequiredProperties()
5355
{
5456
var c = new Container(Rules.Default.With(propertiesAndFields: PropertiesAndFields.RequiredProperties()));
5557

@@ -64,6 +66,44 @@ public void Should_skip_required_property_injection_when_using_ctor_with_SetsReq
6466
Assert.NotNull(x.B);
6567
}
6668

69+
[Test]
70+
public void Works_with_constructor_selector()
71+
{
72+
var c = new Container(
73+
Rules.Default.With(
74+
factoryMethod: FactoryMethod.ConstructorWithResolvableArguments,
75+
propertiesAndFields: PropertiesAndFields.RequiredProperties()));
76+
77+
c.Register<SSS>();
78+
79+
c.Register<A>();
80+
c.Register<B>();
81+
82+
var x = c.Resolve<SSS>();
83+
84+
Assert.NotNull(x.A);
85+
Assert.NotNull(x.B);
86+
}
87+
88+
[Test]
89+
public void Works_with_open_generic_registration_and_constructor_selector_which_SetsRequiredProperties()
90+
{
91+
var c = new Container(
92+
Rules.Default.With(
93+
factoryMethod: FactoryMethod.ConstructorWithResolvableArguments,
94+
propertiesAndFields: PropertiesAndFields.RequiredProperties()));
95+
96+
c.Register(typeof(SS<>));
97+
c.Register(typeof(B<>));
98+
c.Register<A>();
99+
100+
var x = c.Resolve<SS<A>>();
101+
102+
Assert.Null(x.A);
103+
Assert.NotNull(x.B);
104+
Assert.IsInstanceOf<A>(x.B.A);
105+
}
106+
67107
public class A {}
68108
public class B {}
69109
public class C {}
@@ -90,6 +130,32 @@ public class SS
90130
[SetsRequiredMembers]
91131
public SS(B b) => B = b;
92132
}
133+
134+
public class SSS
135+
{
136+
public required A A { get; init; }
137+
public B B { get; private set; }
138+
139+
public SSS(B b) => B = b;
140+
141+
public SSS() => B = null;
142+
}
143+
144+
public class B<T>
145+
{
146+
public required T A { get; init; }
147+
}
148+
149+
public class SS<T>
150+
{
151+
public required A A { get; init; }
152+
public B<T> B { get; private set; }
153+
154+
[SetsRequiredMembers]
155+
public SS(B<T> b) => B = b;
156+
157+
public SS() => B = null;
158+
}
93159
#endif
94160
}
95161
}

0 commit comments

Comments
 (0)