public void ShouldReplaceDependant() { DependantCollection <TestDependant> coll = new DependantCollection <TestDependant>(); var original = new TestDependant1(); var replacement = new TestDependant2(); coll.Add(original); coll.Replace(original, replacement); Assert.Equal(new[] { replacement }, coll); }
public void ShouldThrowExceptionForTwoDependantsWithIdenticalTypeDependencies() { var dependant1 = new TestDependant1().RequiresAny(typeof(TestDependant)); var dependant2 = new TestDependant2().RequiresAny(typeof(TestDependant)); var coll = new DependantCollection <TestDependant>(new TestDependant[] { dependant1, dependant2 }); var ioex = Assert.Throws <InvalidOperationException>(() => Run(coll)); Assert.IsType <DependencyException>(ioex.InnerException); }
public void ShouldOrderDependantsOfTwoGroupsOfRelatedDependants() { bool[] rootCalled = { false, false }; bool[] midCalled = { false, false }; bool[] dependantCalled = { false, false }; bool[] independentCalled = { false, false }; //group1 of dependency chain var root1 = new TestDependant1(() => rootCalled[0] = true); var mid1 = new TestDependant1(() => { Assert.True(rootCalled[0]); midCalled[0] = true; }).Requires(root1); var dependant1 = new TestDependant1(() => { Assert.True(midCalled[0]); dependantCalled[0] = true; }).Requires(mid1); var root2 = new TestDependant2(() => rootCalled[1] = true); var mid2 = new TestDependant2(() => { Assert.True(rootCalled[1]); midCalled[1] = true; }).Requires(root2); var dependant2 = new TestDependant2(() => { Assert.True(midCalled[1]); dependantCalled[1] = true; }).Requires(mid2); var independent1 = new TestDependant1(() => independentCalled[0] = true); var independent2 = new TestDependant2(() => independentCalled[1] = true); RunTest(new TestDependant[] { dependant1, independent1, dependant2, mid2, mid1, root1, independent2, root2 }, c => { Assert.True(dependantCalled[0]); Assert.True(dependantCalled[1]); Assert.True(independentCalled[0]); Assert.True(independentCalled[1]); }, () => { rootCalled[0] = rootCalled[1] = false; midCalled[0] = midCalled[1] = false; dependantCalled[0] = dependantCalled[1] = false; independentCalled[0] = independentCalled[1] = false; }); }
public void ShouldOrderObjectDependencyBeforeDependant() { bool rootCalled = false, dependantCalled = false; var root = new TestDependant1(() => rootCalled = true); var dependant = new TestDependant2(() => { Assert.True(rootCalled); dependantCalled = true; }).Requires(root); RunTest(new TestDependant[] { root, dependant }, c => Assert.True(dependantCalled), () => rootCalled = dependantCalled = false); }
public void ShouldOrderTypeDependencyBeforeDependant() { // similar to above, except the dependency is expressed as a type dependency bool rootCalled = false, dependantCalled = false; var root = new TestDependant1(() => rootCalled = true); var dependant = new TestDependant2(() => { Assert.True(rootCalled); dependantCalled = true; }).RequiresAny(typeof(TestDependant1)); RunTest(new TestDependant[] { root, dependant }, c => Assert.True(dependantCalled), () => rootCalled = dependantCalled = false); }
public void ShouldOrderTransitiveObjectDependencyBeforeDependants() { bool rootCalled = false, midCalled = false, dependantCalled = false; var root = new TestDependant1(() => rootCalled = true); var mid = new TestDependant2(() => { Assert.True(rootCalled); midCalled = true; }).Requires(root); var dependant = new TestDependant3(() => { Assert.True(midCalled); dependantCalled = true; }).Requires(mid); RunTest(new TestDependant[] { root, mid, dependant }, c => Assert.True(dependantCalled), () => rootCalled = midCalled = dependantCalled = false); }
public void ShouldOrderTransitiveTypeDependencyBeforeDependants() { // same as above, but this time the dependencies are expressed as // type dependencies. Therefore dependant should inherit a dependency // on root via its type dependency on TestDependant2 bool rootCalled = false, midCalled = false, dependantCalled = false; var root = new TestDependant1(() => rootCalled = true); var mid = new TestDependant2(() => { Assert.True(rootCalled); midCalled = true; }).RequiresAny(typeof(TestDependant1)); var dependant = new TestDependant3(() => { Assert.True(midCalled); dependantCalled = true; }).RequiresAny(typeof(TestDependant2)); RunTest(new TestDependant[] { root, mid, dependant }, c => Assert.True(dependantCalled), () => rootCalled = midCalled = dependantCalled = false); }