Skip to content

Commit

Permalink
structuremap#43 - Added failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dazinator committed Aug 26, 2018
1 parent 0478649 commit a644385
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />

</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.DependencyInjection.Specification;
using Microsoft.Extensions.DependencyInjection.Specification.Fakes;
using Microsoft.Extensions.Options;
using Xunit;

namespace StructureMap.Microsoft.DependencyInjection.Tests
Expand Down Expand Up @@ -60,6 +61,33 @@ public void CanResolveIEnumerableWithDefaultConstructor()
Assert.NotEmpty(logger.Factory.Providers);
}

[Fact]
public void CanResolveIOptionsTFromChildContainer()
{

ServiceCollection services = new ServiceCollection();

StructureMap.Container container = new StructureMap.Container();
container.Populate(services);

var childContainer = container.CreateChildContainer();
childContainer.Configure((a) =>
{
var childServices = new ServiceCollection();
childServices.AddOptions();
childServices.Configure<MyOptions>((b) =>
{
b.Prop = true;
});
a.Populate(childServices);
});

IServiceProvider sp = childContainer.GetInstance<IServiceProvider>();
IOptions<MyOptions> options = sp.GetRequiredService<IOptions<MyOptions>>();
Assert.True(options.Value?.Prop);

}

private interface ILoggerProvider { }

private class TestLoggerProvider : ILoggerProvider { }
Expand Down Expand Up @@ -97,5 +125,10 @@ public Logger(ILoggerFactory factory)

public ILoggerFactory Factory { get; }
}

private class MyOptions
{
public bool Prop { get; internal set; }
}
}
}

0 comments on commit a644385

Please sign in to comment.