|
1 |
| -using Shouldly; |
| 1 | +using System; |
| 2 | + |
| 3 | +using Shouldly; |
2 | 4 |
|
3 | 5 | using Xunit;
|
4 | 6 |
|
5 | 7 | namespace Spectre.Console.Registrars.SimpleInjector.Tests
|
6 | 8 | {
|
7 | 9 | public class RegistrarTests
|
8 | 10 | {
|
| 11 | + [Fact] |
| 12 | + public void Resolver_Resolving_null_Throws() |
| 13 | + { |
| 14 | + var fixture = new RegistrarFixture(); |
| 15 | + var resolver = fixture.GetResolver(); |
| 16 | + |
| 17 | + Action action = () => resolver.Resolve(null); |
| 18 | + |
| 19 | + action.ShouldThrow<ArgumentNullException>(); |
| 20 | + } |
| 21 | + |
9 | 22 | [Fact]
|
10 | 23 | public void Resolver_Should_Return_Registration_From_Container()
|
11 | 24 | {
|
@@ -56,6 +69,20 @@ public void Resolver_Should_Return_Lazy_From_Registrar()
|
56 | 69 | ReferenceEquals(expected, actual).ShouldBeTrue();
|
57 | 70 | }
|
58 | 71 |
|
| 72 | + [Fact] |
| 73 | + public void Resolver_Resolving_From_Multiple_Lazies_Returns_The_Last_Registration() |
| 74 | + { |
| 75 | + var fixture = new RegistrarFixture(); |
| 76 | + fixture.GivenMultiRegistrationTypes(typeof(ISomeInterface)); |
| 77 | + fixture.GivenOnRegistrar(r => r.RegisterLazy(typeof(ISomeInterface), () => new SomeDependency())); |
| 78 | + fixture.GivenOnRegistrar(r => r.RegisterLazy(typeof(ISomeInterface), () => new SomeOtherDependency())); |
| 79 | + |
| 80 | + var actual = fixture.GetResolver().Resolve(typeof(ISomeInterface)); |
| 81 | + |
| 82 | + actual.ShouldNotBeNull(); |
| 83 | + actual.ShouldBeOfType<SomeOtherDependency>(); |
| 84 | + } |
| 85 | + |
59 | 86 | [Fact(Skip = "Doesn't work at the moment")]
|
60 | 87 | public void Resolver_Should_Not_Call_Lazy_Factory_If_Not_Needed()
|
61 | 88 | {
|
@@ -99,6 +126,20 @@ public void Resolver_Resolving_From_Multiple_Returns_The_Last_Registration()
|
99 | 126 | actual.ShouldBeOfType<SomeOtherDependency>();
|
100 | 127 | }
|
101 | 128 |
|
| 129 | + [Fact] |
| 130 | + public void Resolver_Resolving_From_Multiple_Instances_Returns_The_Last_Registration() |
| 131 | + { |
| 132 | + var fixture = new RegistrarFixture(); |
| 133 | + fixture.GivenMultiRegistrationTypes(typeof(ISomeInterface)); |
| 134 | + fixture.GivenOnRegistrar(r => r.RegisterInstance(typeof(ISomeInterface), new SomeDependency())); |
| 135 | + fixture.GivenOnRegistrar(r => r.RegisterInstance(typeof(ISomeInterface), new SomeOtherDependency())); |
| 136 | + |
| 137 | + var actual = fixture.GetResolver().Resolve(typeof(ISomeInterface)); |
| 138 | + |
| 139 | + actual.ShouldNotBeNull(); |
| 140 | + actual.ShouldBeOfType<SomeOtherDependency>(); |
| 141 | + } |
| 142 | + |
102 | 143 | private interface ISomeInterface
|
103 | 144 | {
|
104 | 145 | }
|
|
0 commit comments