public void Retrieve_NonTerminalDescriptor_DataOfTheTerminalDescriptorsThatComposeIt() { var terminalDescriptors = ArraysHelper.CreateWithContent( new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object ); var data = new IData[terminalDescriptors.Length]; for (var i = 0; i < terminalDescriptors.Length; ++i) { var terminalDescriptor = terminalDescriptors[i]; var dataItem = new Mock <IData>().Object; TestInstanceMock .Setup <IData>(_ => _.Retrieve(terminalDescriptor)) .Returns(dataItem); data[i] = dataItem; } CompositionsMock .Setup(_ => _.Retrieve(NonTerminalDescriptor)) .Returns(() => terminalDescriptors); var result = TestInstance.Retrieve(NonTerminalDescriptor); Assert.IsTrue(data.Equivalent(result)); }
public void FindDistinctAdditions_NewCompositionsSubsetOfInitialComposition_EmptyCollection() { var initialComposition = ArraysHelper.CreateWithContent(new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object); var newComposition = ArraysHelper.CreateWithContent(initialComposition[0], initialComposition[2]); var result = ReflectionHelper.Invoke(TestInstance, "FindDistinctAdditions", initialComposition, newComposition) as IEnumerable <ITerminalDescriptor>; Assert.AreEqual(0, result.Count()); }
public void FindDistinctAdditions_CompositionsDisjunct_EquivalentToNewComposition() { var initialComposition = ArraysHelper.CreateWithContent(new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object); var newComposition = ArraysHelper.CreateWithContent(new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object); var result = ReflectionHelper.Invoke(TestInstance, "FindDistinctAdditions", initialComposition, newComposition) as IEnumerable <ITerminalDescriptor>; Assert.IsTrue(newComposition.Equivalent(result)); }
public void FindDistinctAdditions_NewCompositionHasDuplicatedAdditions_Distinct() { var additions = ArraysHelper.CreateWithContent(new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object); var initialComposition = ArraysHelper.CreateWithContent(new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object); var newComposition = ArraysHelper.CreateWithContent(additions[0], additions[1], additions[1], additions[0]); var result = ReflectionHelper.Invoke(TestInstance, "FindDistinctAdditions", initialComposition, newComposition) as IEnumerable <ITerminalDescriptor>; Assert.IsTrue(additions.Equivalent(result)); }
public void RetrieveAllDescriptors__NonTerminalDescriptorsRetrieved() { var nonTerminalDescriptorMocks = ArraysHelper.CreateWithContent(new Mock <INonTerminalDescriptor>(), new Mock <INonTerminalDescriptor>()); var nonTerminalDescriptors = nonTerminalDescriptorMocks.Select(_ => _.Object); DataStoreMock.Setup(_ => _.RetrieveDescriptors()).Returns(new ITerminalDescriptor[0]); CompositionsMock.Setup(_ => _.RetrieveDescriptors()).Returns(nonTerminalDescriptors).Verifiable(); var result = (IEnumerable <IDescriptor>)ReflectionHelper.Invoke(TestInstance, "RetrieveAllDescriptors"); CompositionsMock.Verify(); Assert.IsTrue(nonTerminalDescriptors.Equivalent(result)); }
public void UpdateCompositionAndProvideAdditions__ProxiesNonTerminalDescriptorCompositionsStore() { var additions = ArraysHelper.CreateWithContent(new Mock <ITerminalDescriptor>().Object, new Mock <ITerminalDescriptor>().Object); CompositionsMock .Setup(_ => _.UpdateAndProvideAdditions(NonTerminalDescriptor, TerminalDescriptorsCollection)) .Returns(additions) .Verifiable(); var result = TestInstance.UpdateCompositionAndProvideAdditions(NonTerminalDescriptor, TerminalDescriptorsCollection); CompositionsMock.Verify(); Assert.AreSame(additions, result); }
public void FindIntersectingDescriptors__AllIntersectingDescriptors() { var providedDescriptor = new Mock <IDescriptor>().Object; var disjunctDescriptorMocks = ArraysHelper.CreateWithContent(new Mock <IDescriptor>(), new Mock <IDescriptor>()); var intersectingDescriptorMocks = ArraysHelper.CreateWithContent(new Mock <IDescriptor>(), new Mock <IDescriptor>()); var allDescriptorMocks = intersectingDescriptorMocks.ShuffledMerge(disjunctDescriptorMocks); var intersectingDescriptors = intersectingDescriptorMocks.Select(_ => _.Object); var allDescriptors = allDescriptorMocks.Select(_ => _.Object); disjunctDescriptorMocks.ForEach(_ => _.Setup(__ => __.Intersects(providedDescriptor)).Returns(false)); intersectingDescriptorMocks.ForEach(_ => _.Setup(__ => __.Intersects(providedDescriptor)).Returns(true)); TestInstanceMockProtected .Setup <IEnumerable <IDescriptor> >("RetrieveAllDescriptors") .Returns(allDescriptors) .Verifiable(); var result = TestInstance.FindIntersectingDescriptors(providedDescriptor); TestInstanceMock.Verify(); allDescriptorMocks.ForEach(_ => _.VerifyAll()); Assert.IsTrue(intersectingDescriptors.Equivalent(result)); }