public void If_a_circular_dependency_was_detected_it_should_raise_a_exception() { var tasks = new[] { new RegisteredTask(typeof (ExampleTask1)) {DependsOn = new[] {nameof(ExampleTask2)}}, new RegisteredTask(typeof (ExampleTask2)) {DependsOn = new[] {nameof(ExampleTask3)}}, new RegisteredTask(typeof (ExampleTask3)) {DependsOn = new[] {nameof(ExampleTask4)}}, new RegisteredTask(typeof (ExampleTask4)) {DependsOn = new[] {nameof(ExampleTask1)}} }; var registration = A.Fake<ITaskRegistration>(); A.CallTo(() => registration.Tasks).Returns(tasks); var resolver = new TaskGraphResolver(registration); var taskToResolve = tasks[0]; Assert.Throws<CircularTaskDependencyDetectedException>(() => resolver.Resolve(taskToResolve)); }
public void It_should_resolve_the_dependency_graph() { var tasks = new[] { new RegisteredTask(typeof (ExampleTask1)) { DependsOn = new[] {nameof(ExampleTask2), nameof(ExampleTask3)} }, new RegisteredTask(typeof (ExampleTask2)) {DependsOn = new[] {nameof(ExampleTask4)}}, new RegisteredTask(typeof (ExampleTask3)) {DependsOn = new[] {nameof(ExampleTask4)}}, new RegisteredTask(typeof (ExampleTask4)) }; var registration = A.Fake<ITaskRegistration>(); A.CallTo(() => registration.Tasks).Returns(tasks); var resolver = new TaskGraphResolver(registration); var taskToResolve = tasks[0]; var result = resolver.Resolve(taskToResolve); CollectionAssert.AreEqual(new[] {tasks[3], tasks[1], tasks[2], tasks[0]}, result); }