public void ShouldBeAbleToReturnAllAvailableImplementationsForADependency() { var numberOfImplementations = 5; var implementations = Enumerable.Range(0, numberOfImplementations) .Select(_ => A.Fake <IImplementation>()).ToArray(); var dependency = new Dependency(typeof(IEnumerable <string>)); var map = new DependencyMap(); for (var i = 0; i < numberOfImplementations; i++) { var implementation = implementations[i]; map.AddService(dependency, implementation); } Assert.True(map.Contains(dependency)); Assert.Contains(dependency, map.Dependencies); var results = map.GetImplementations(dependency, false).ToArray(); for (var i = 0; i < numberOfImplementations; i++) { Assert.Contains(implementations[i], results); } }
public void ShouldBeAbleToReturnAllAvailableImplementationsForADependencyExceptForTheIncompleteDependencies() { var numberOfImplementations = 5; var numberOfIncompleteImplementations = 3; IEnumerable <IImplementation> CreateImplementations(int numberOfImplementationsToCreate, bool isCompleted) { var incompleteDependencies = isCompleted ? Enumerable.Empty <IDependency>() : new[] { A.Fake <IDependency>() }; return(Enumerable.Range(0, numberOfImplementationsToCreate) .Select(_ => { var currentImplementation = A.Fake <IImplementation>(); A.CallTo(() => currentImplementation.GetMissingDependencies(A <IDependencyMap> .Ignored)) .Returns(incompleteDependencies); return currentImplementation; }).ToArray()); } var implementations = new List <IImplementation>(); implementations.AddRange(CreateImplementations(numberOfImplementations, true)); var incompleteImplementations = CreateImplementations(numberOfIncompleteImplementations, false) .ToArray(); implementations.AddRange(incompleteImplementations); var dependency = new Dependency(typeof(IEnumerable <string>)); var map = new DependencyMap(); foreach (var implementation in implementations) { map.AddService(dependency, implementation); } Assert.True(map.Contains(dependency)); Assert.Contains(dependency, map.Dependencies); var results = map.GetImplementations(dependency, false).ToArray(); for (var i = 0; i < numberOfImplementations; i++) { Assert.Contains(implementations[i], results); } foreach (var implementation in incompleteImplementations) { Assert.DoesNotContain(implementation, results); } }
public void ShouldReturnImplementationsFromDependencyMapFromImplementationsThatHaveNoMissingDependencies() { var map = new DependencyMap(); var dependency = new Dependency(typeof(IVehicle), string.Empty); var implementation = new Mock <IImplementation>(); implementation.Expect(impl => impl.GetMissingDependencies(map)).Returns(new IDependency[0]); bool addIncompleteImplementations = false; map.AddService(dependency, implementation.Object); var results = map.GetImplementations(dependency, addIncompleteImplementations); Assert.IsTrue(results.Count() > 0); Assert.IsTrue(results.Contains(implementation.Object)); implementation.VerifyAll(); }
public void ShouldReturnImplementationsFromDependencyMapFromImplementationsThatHaveNoMissingDependencies() { var map = new DependencyMap(); var dependency = new Dependency(typeof(IVehicle), string.Empty); var implementation = new Mock<IImplementation>(); implementation.Expect(impl => impl.GetMissingDependencies(map)).Returns(new IDependency[0]); bool addIncompleteImplementations = false; map.AddService(dependency, implementation.Object); var results = map.GetImplementations(dependency, addIncompleteImplementations); Assert.IsTrue(results.Count() > 0); Assert.IsTrue(results.Contains(implementation.Object)); implementation.VerifyAll(); }