-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve test coverage for ReadOnlyKernel.
- Loading branch information
Showing
14 changed files
with
1,208 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ject.Test/Integration/EnumerableDependenciesTests/Fakes/RequestsConstrainedICollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Ninject.Tests.Integration.EnumerableDependenciesTests.Fakes | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public class RequestsConstrainedICollection : IParent | ||
{ | ||
public RequestsConstrainedICollection([Named("bob")] ICollection<IChild> children) | ||
{ | ||
this.Children = children.ToList(); | ||
} | ||
|
||
public IList<IChild> Children { get; private set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Ninject.Test/Integration/EnumerableDependenciesTests/Fakes/RequestsConstrainedIList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Ninject.Tests.Integration.EnumerableDependenciesTests.Fakes | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public class RequestsConstrainedIList : IParent | ||
{ | ||
public RequestsConstrainedIList([Named("bob")] IList<IChild> children) | ||
{ | ||
this.Children = children; | ||
} | ||
|
||
public IList<IChild> Children { get; private set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Ninject.Test/Integration/EnumerableDependenciesTests/Fakes/RequestsICollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Ninject.Tests.Integration.EnumerableDependenciesTests.Fakes | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public class RequestsICollection : IParent | ||
{ | ||
public RequestsICollection(ICollection<IChild> children) | ||
{ | ||
this.Children = children.ToList(); | ||
} | ||
|
||
public IList<IChild> Children { get; private set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Ninject.Test/Integration/EnumerableDependenciesTests/Fakes/RequestsIList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Ninject.Tests.Integration.EnumerableDependenciesTests.Fakes | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public class RequestsIList : IParent | ||
{ | ||
public RequestsIList(IList<IChild> children) | ||
{ | ||
this.Children = children; | ||
} | ||
|
||
public IList<IChild> Children { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...on/EnumerableDependenciesTests/WhenServiceRequestsConstrainedICollectionOfDependencies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Ninject.Tests.Integration.EnumerableDependenciesTests | ||
{ | ||
using FluentAssertions; | ||
using Ninject.Tests.Integration.EnumerableDependenciesTests.Fakes; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
public class WhenServiceRequestsConstrainedICollectionOfDependencies : ConstrainedDependenciesContext | ||
{ | ||
[Fact] | ||
public void ServiceIsInjectedWithAllDependenciesThatMatchTheConstraint() | ||
{ | ||
this.Kernel.Bind<IParent>().To<RequestsConstrainedICollection>(); | ||
this.Kernel.Bind<IChild>().To<ChildA>().Named("joe"); | ||
this.Kernel.Bind<IChild>().To<ChildB>().Named("bob"); | ||
|
||
var parent = this.Kernel.Get<IParent>(); | ||
|
||
VerifyInjection(parent); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
} | ||
|
||
[Fact] | ||
public void WhenNoMatchingBindingExistsEmptyEnumerableIsInjected() | ||
{ | ||
this.Kernel.Bind<IParent>().To<RequestsConstrainedICollection>(); | ||
this.Kernel.Bind<IChild>().To<ChildA>().Named("joe"); | ||
this.Kernel.Bind<IChild>().To<ChildB>().Named("ian"); | ||
|
||
var parent = this.Kernel.Get<IParent>(); | ||
|
||
parent.Should().NotBeNull(); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
parent.Children.Count.Should().Be(0); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...egration/EnumerableDependenciesTests/WhenServiceRequestsConstrainedIListOfDependencies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Ninject.Tests.Integration.EnumerableDependenciesTests | ||
{ | ||
using FluentAssertions; | ||
using Ninject.Tests.Integration.EnumerableDependenciesTests.Fakes; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
public class WhenServiceRequestsConstrainedIListOfDependencies : ConstrainedDependenciesContext | ||
{ | ||
[Fact] | ||
public void ServiceIsInjectedWithAllDependenciesThatMatchTheConstraint() | ||
{ | ||
this.Kernel.Bind<IParent>().To<RequestsConstrainedIList>(); | ||
this.Kernel.Bind<IChild>().To<ChildA>().Named("joe"); | ||
this.Kernel.Bind<IChild>().To<ChildB>().Named("bob"); | ||
|
||
var parent = this.Kernel.Get<IParent>(); | ||
|
||
VerifyInjection(parent); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
} | ||
|
||
[Fact] | ||
public void WhenNoMatchingBindingExistsEmptyEnumerableIsInjected() | ||
{ | ||
this.Kernel.Bind<IParent>().To<RequestsConstrainedIList>(); | ||
this.Kernel.Bind<IChild>().To<ChildA>().Named("joe"); | ||
this.Kernel.Bind<IChild>().To<ChildB>().Named("ian"); | ||
|
||
var parent = this.Kernel.Get<IParent>(); | ||
|
||
parent.Should().NotBeNull(); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
parent.Children.Count.Should().Be(0); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...ration/EnumerableDependenciesTests/WhenServiceRequestsUnconstrainedArrayOfDependencies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ration/EnumerableDependenciesTests/WhenServiceRequestsUnconstrainedIListOfDependencies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
namespace Ninject.Tests.Integration.EnumerableDependenciesTests | ||
{ | ||
using FluentAssertions; | ||
using Ninject.Tests.Integration.EnumerableDependenciesTests.Fakes; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
public class WhenServiceRequestsUnconstrainedIListOfDependencies : UnconstrainedDependenciesContext | ||
{ | ||
[Fact] | ||
public void ServiceIsInjectedWithListOfAllAvailableDependencies() | ||
{ | ||
this.Kernel.Bind<IParent>().To<RequestsIList>(); | ||
this.Kernel.Bind<IChild>().To<ChildA>(); | ||
this.Kernel.Bind<IChild>().To<ChildB>(); | ||
|
||
var parent = this.Kernel.Get<IParent>(); | ||
|
||
VerifyInjection(parent); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
} | ||
|
||
[Fact] | ||
public void ServiceIsInjectedWithEmptyListIfElementTypeIsMissingBinding() | ||
{ | ||
this.Kernel.Bind<IParent>().To<RequestsIList>(); | ||
|
||
var parent = this.Kernel.Get<IParent>(); | ||
|
||
parent.Should().NotBeNull(); | ||
parent.Children.Should().BeEmpty(); | ||
parent.Children.Should().BeOfType<List<IChild>>(); | ||
} | ||
|
||
[Fact] | ||
public void ListIsResolvedIfElementTypeIsExplicitlyBinded() | ||
{ | ||
this.Kernel.Bind<IChild>().To<ChildA>(); | ||
|
||
var children = this.Kernel.Get<IList<IChild>>(); | ||
|
||
children.Should().NotBeEmpty(); | ||
children.Should().BeOfType<List<IChild>>(); | ||
} | ||
|
||
[Fact] | ||
public void EmptyListIsResolvedIfElementTypeIsMissingBinding() | ||
{ | ||
var children = this.Kernel.Get<IList<IChild>>(); | ||
|
||
children.Should().BeEmpty(); | ||
children.Should().BeOfType<List<IChild>>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.