Skip to content

Commit 2a1879f

Browse files
committed
adding the new test for #535
1 parent 0f0a16a commit 2a1879f

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed

test/DryIoc.IssuesTests/GHIssue535_Property_injection_does_not_work_when_appending_implementation_for_multiple_registration.cs

+49-6
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,69 @@ public class GHIssue535_Property_injection_does_not_work_when_appending_implemen
88
{
99
public int Run()
1010
{
11-
Test();
11+
// Test1();
12+
Test2();
1213
return 1;
1314
}
1415

15-
[Test]
16-
[Ignore("fixme")]
17-
public void Test()
16+
// [Test]
17+
public void Test1()
1818
{
1919
// ARRANGE
2020
const string testFoo1 = "TF1";
2121
const string testFoo2 = "TF2";
2222

2323
var container = new Container();
2424

25-
container.RegisterMany(new[] { typeof(Foo1), typeof(IFoo) }, typeof(Foo1), reuse: Reuse.Singleton);
2625
var propertiesAndFieldsSelector = PropertiesAndFields.Of.Name(nameof(IFoo.Test), _ => testFoo1);
27-
container.RegisterMany(new[] { typeof(Foo1), typeof(IFoo) }, typeof(Foo1), reuse: Reuse.Singleton,
26+
container.RegisterMany(new[] { typeof(Foo1), typeof(IFoo) }, typeof(Foo1), reuse: Reuse.Singleton,
27+
made: propertiesAndFieldsSelector, ifAlreadyRegistered: IfAlreadyRegistered.AppendNewImplementation);
28+
29+
propertiesAndFieldsSelector = PropertiesAndFields.Of.Name(nameof(IFoo.Test), _ => testFoo2);
30+
container.RegisterMany(new[] { typeof(Foo2), typeof(IFoo) }, typeof(Foo2), reuse: Reuse.Singleton,
31+
made: propertiesAndFieldsSelector, ifAlreadyRegistered: IfAlreadyRegistered.AppendNewImplementation);
32+
33+
// ACT
34+
var foo1 = container.Resolve<Foo1>();
35+
var foo2 = container.Resolve<Foo2>();
36+
var foos = container.Resolve<IEnumerable<IFoo>>();
37+
38+
// ASSERT
39+
Assert.AreEqual(testFoo1, foo1.Test);
40+
Assert.AreEqual(testFoo2, foo2.Test);
41+
42+
foreach (var foo in foos)
43+
{
44+
switch (foo)
45+
{
46+
case Foo1 foo1FromEnumerable:
47+
Assert.AreEqual(testFoo1, foo.Test);
48+
Assert.AreEqual(foo1, foo1FromEnumerable);
49+
break;
50+
case Foo2 foo2FromEnumerable:
51+
Assert.AreEqual(testFoo2, foo.Test);
52+
Assert.AreEqual(foo2, foo2FromEnumerable);
53+
break;
54+
}
55+
}
56+
}
57+
58+
// [Test]
59+
public void Test2()
60+
{
61+
// ARRANGE
62+
const string testFoo1 = "TF1";
63+
const string testFoo2 = "TF2";
64+
65+
var container = new Container();
66+
67+
// container.RegisterMany(new[] { typeof(Foo1), typeof(IFoo) }, typeof(Foo1), reuse: Reuse.Singleton);
68+
var propertiesAndFieldsSelector = PropertiesAndFields.Of.Name(nameof(IFoo.Test), _ => testFoo1);
69+
container.RegisterMany(new[] { typeof(Foo1), typeof(IFoo) }, typeof(Foo1), reuse: Reuse.Singleton,
2870
made: propertiesAndFieldsSelector, ifAlreadyRegistered: IfAlreadyRegistered.AppendNewImplementation);
2971

3072
container.RegisterMany(new[] { typeof(Foo2), typeof(IFoo) }, typeof(Foo2), reuse: Reuse.Singleton);
73+
3174
propertiesAndFieldsSelector = PropertiesAndFields.Of.Name(nameof(IFoo.Test), _ => testFoo2);
3275
container.RegisterMany(new[] { typeof(Foo2), typeof(IFoo) }, typeof(Foo2), reuse: Reuse.Singleton,
3376
made: propertiesAndFieldsSelector, ifAlreadyRegistered: IfAlreadyRegistered.AppendNewImplementation);

0 commit comments

Comments
 (0)