-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathStructureMapServiceProviderTests.cs
More file actions
42 lines (34 loc) · 1.35 KB
/
StructureMapServiceProviderTests.cs
File metadata and controls
42 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Xunit;
namespace StructureMap.Microsoft.DependencyInjection.Tests
{
public class StructureMapServiceProviderTests
{
[Fact]
public void can_start_and_tear_down_a_scope_from_the_provider()
{
var root = new Container(_ =>
{
_.For<IWidget>().Use<BlueWidget>();
});
var provider = new StructureMapServiceProvider(root);
Assert.Same(provider.Container, root);
Assert.IsType<BlueWidget>(provider.GetRequiredService(typeof(IWidget)));
provider.StartNewScope();
provider.Container.Configure(_ => _.For<IWidget>().Use<GreenWidget>());
Assert.IsType<GreenWidget>(provider.GetRequiredService(typeof(IWidget)));
provider.TeardownScope();
Assert.IsType<BlueWidget>(provider.GetRequiredService(typeof(IWidget)));
}
[Fact]
public void get_service_without_registered_types_return_null()
{
var root = new Container();
var provider = new StructureMapServiceProvider(root);
Assert.Same(provider.Container, root);
Assert.Null(provider.GetService(typeof(IWidget)));
}
public interface IWidget { }
public class BlueWidget : IWidget { }
public class GreenWidget : IWidget { }
}
}