-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathResolveAssertions_Should.cs
79 lines (68 loc) · 2.31 KB
/
ResolveAssertions_Should.cs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Diagnostics.CodeAnalysis;
using Autofac;
using NSubstitute;
using Xunit;
namespace FluentAssertions.Autofac;
// ReSharper disable InconsistentNaming
public class ResolveAssertions_Should
{
[Fact]
public void Resolve()
{
var container = Configure();
container.Invoking(x => x.Should().Resolve<IDisposable>())
.Should().Throw<Exception>()
.WithMessage($"Expected container to resolve '{typeof(IDisposable)}' but it did not.");
var disposable = Substitute.For<IDisposable>();
container = Configure(builder => builder.RegisterInstance(disposable));
container.Should().Resolve<IDisposable>();
}
[Fact]
public void Resolve_As()
{
var containerShould = Configure(builder =>
builder.RegisterType<Dummy>()
.AsSelf()
.As<IDisposable>()
).Should();
containerShould.Resolve<Dummy>();
containerShould.Resolve<Dummy>().AsSelf();
containerShould.Resolve<IDisposable>().As<Dummy>();
containerShould.Resolve<IDisposable>().As(typeof(Dummy));
}
[Fact]
public void Resolve_Named()
{
var containerShould = Configure(builder =>
builder.RegisterType<Dummy>()
.Named<IDisposable>("dummy")
.AsSelf()
).Should();
containerShould.Resolve<Dummy>()
.AsSelf()
.Named<IDisposable>("dummy")
.Named("dummy", typeof(IDisposable));
}
[Fact]
public void Assert_AutoActivation()
{
var container = Configure(builder => builder.RegisterType<Dummy>().AsSelf().AutoActivate());
container.Should().Resolve<Dummy>().AutoActivate();
container = Configure(builder => builder.RegisterType<Dummy>().AutoActivate());
container.Should().AutoActivate<Dummy>();
container.Should().Invoking(x => x.Resolve<Dummy>()).Should()
.Throw<Exception>("type not registered AS something");
}
private static IContainer Configure(Action<ContainerBuilder> arrange = null)
{
var builder = new ContainerBuilder();
arrange?.Invoke(builder);
return builder.Build();
}
[ExcludeFromCodeCoverage]
private class Dummy : IDisposable
{
public void Dispose() { }
}
}