Skip to content

Commit 6f8a6da

Browse files
committed
Prepare test for GHIssue574
1 parent cde7d3f commit 6f8a6da

File tree

1 file changed

+40
-44
lines changed

1 file changed

+40
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,53 @@
1-
2-
public class DryExamples
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NUnit.Framework;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using DryIoc.Microsoft.DependencyInjection;
7+
8+
namespace DryIoc.IssuesTests
39
{
4-
[Fact] // This works ok.
5-
public void TransferMultipleThenResolveEnumerable()
10+
public class GHIssue574_Cannot_register_multiple_impls_in_child_container_with_default_service_key
611
{
7-
var services = new ServiceCollection();
12+
[Ignore("fixme")]
13+
public void ResolveEnumerableFromChild()
14+
{
15+
var services = new ServiceCollection();
816

9-
services.AddScoped<IPrinter, Printer>();
10-
services.AddScoped<IPrinter, PrinterA>();
11-
services.AddScoped<IPrinter, PrinterB>();
12-
services.AddScoped<IPrinter, NeighborPrinter>();
17+
services.AddScoped<IPrinter, Printer>();
18+
services.AddScoped<IPrinter, PrinterA>();
19+
services.AddScoped<IPrinter, PrinterB>();
20+
services.AddScoped<IPrinter, NeighborPrinter>();
1321

14-
var spf = new DryIocServiceProviderFactory();
15-
var dryContainer = spf.CreateBuilder(services);
16-
var msContainer = dryContainer.GetServiceProvider();
22+
var spf = new DryIocServiceProviderFactory();
23+
var rootContainer = spf.CreateBuilder(new ServiceCollection());
24+
var childContainer = rootContainer.CreateChild(RegistrySharing.Share, "child-stamp", IfAlreadyRegistered.AppendNewImplementation);
1725

18-
Assert.Equal(
19-
dryContainer.Resolve<IEnumerable<IPrinter>>().Count(),
20-
msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count());
21-
}
26+
//childContainer.Populate(services);
27+
foreach (var service in services)
28+
{
29+
childContainer.RegisterDescriptor(service, IfAlreadyRegistered.AppendNewImplementation, "child-stamp");
30+
}
2231

23-
[Fact] // I have not been able to get this to work.
24-
public void TransferMultipleThenResolveEnumerableFromChild()
25-
{
26-
var services = new ServiceCollection();
27-
28-
services.AddScoped<IPrinter, Printer>();
29-
services.AddScoped<IPrinter, PrinterA>();
30-
services.AddScoped<IPrinter, PrinterB>();
31-
services.AddScoped<IPrinter, NeighborPrinter>();
32-
33-
var spf = new DryIocServiceProviderFactory();
34-
var rootContainer = spf.CreateBuilder(new ServiceCollection());
35-
var childContainer = rootContainer.CreateChild(RegistrySharing.Share, "child-stamp", IfAlreadyRegistered.AppendNewImplementation);
36-
//childContainer.Populate(services);
37-
foreach (var service in services)
38-
{
39-
childContainer.RegisterDescriptor(service, IfAlreadyRegistered.AppendNewImplementation, "child-stamp");
40-
}
41-
var msContainer = childContainer.GetServiceProvider();
32+
var msContainer = childContainer.GetServiceProvider();
4233

43-
Assert.Equal(
44-
childContainer.Resolve<IEnumerable<IPrinter>>().Count(),
45-
msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count());
46-
}
34+
Assert.That(
35+
childContainer.Resolve<IEnumerable<IPrinter>>().Count(),
36+
Is.EqualTo(msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count()));
4737

48-
private interface IPrinter{}
38+
Assert.That(
39+
msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count(),
40+
Is.EqualTo(4));
41+
}
4942

50-
private class Printer : IPrinter{}
43+
private interface IPrinter { }
5144

52-
private class PrinterA : IPrinter{}
45+
private class Printer : IPrinter { }
5346

54-
private class PrinterB : IPrinter{}
47+
private class PrinterA : IPrinter { }
5548

56-
private class NeighborPrinter : IPrinter{}
49+
private class PrinterB : IPrinter { }
50+
51+
private class NeighborPrinter : IPrinter { }
52+
}
5753
}

0 commit comments

Comments
 (0)