public void SimpleUsage() { GraphNode parent = new GraphNode(); GraphNode child = new GraphNode(); parent.AddDependent(child); Assert.AreSame(child, parent.Dependents[0]); }
public void Removal() { GraphNode parent = new GraphNode(); GraphNode child = new GraphNode(); parent.AddDependent(child); child.RemoveDepender(parent); Assert.IsTrue(parent.Dependents.Length == 0); Assert.IsTrue(parent.Dependers.Length == 0); Assert.IsTrue(child.Dependers.Length == 0); Assert.IsTrue(child.Dependents.Length == 0); }
private IChainStep <T> ComputeChainSequence() { DirectedAcyclicGraph <IChainStep <T> > graph = new DirectedAcyclicGraph <IChainStep <T> >(); foreach (var step in _steps.Values) { graph.AddNode(new GraphNode <IChainStep <T> >(step.Name, step)); } foreach (var step in _steps.Values) { GraphNode <IChainStep <T> > node = graph.GetNode(step.Name); foreach (var dependency in step.Dependencies) { if (dependency.MustExist) { Asserter.Assert( _steps.ContainsKey(dependency.Name), string.Format( "Cannot execute chain '{0}' because step '{1}' has a mandatory dependency on step '{2}' and '{2}' cannot be found in the {0} chain.", _name, step.Name, dependency.Name)); } var dependentNode = graph.GetNode(dependency.Name); node.AddDependent(dependentNode); } } var ordered = graph.ComputeDependencyOrderedList().Select(node => node.Item).ToArray(); for (int i = ordered.Length - 2; i > 0; i--) { ordered[i].Successor = ordered[i + 1]; } return(ordered[0]); }