public void ApplyConventions_Edge_Should_Apply_Conventions() { var conventionTracker = new ConventionTracker(); var convention = MockRepository.GenerateMock<IEdgeConvention>(); var fromNode = new GraphNode("a"); var toNode = new GraphNode("b"); var edgeInfo = new EdgeInfo(new NodeInfo(fromNode.Name, null), new NodeInfo(toNode.Name, null), null); convention.Expect(x => x.ShouldApply(edgeInfo)) .IgnoreArguments() .Constraints(Is.Matching<IEdgeInfo>(x => x.FromNode.Name == "a" && x.ToNode.Name == "b")) .Return(true) .Repeat.Once(); convention.Expect(x => x.Apply(null, null)).IgnoreArguments() .Constraints( Is.Matching<IEdgeInfo>(x => x.Tag == edgeInfo.Tag && x.FromNode.Name == edgeInfo.FromNode.Name && x.ToNode.Name == edgeInfo.ToNode.Name ), Is.Matching<IEdgeExpression>(x => x != null)) .Repeat.Once(); conventionTracker.AddConvention(convention); conventionTracker.ApplyConventions(new DirectedEdge(new NodeTarget(fromNode), new NodeTarget(toNode))); convention.VerifyAllExpectations(); }
public void ApplyConventions_Edge_Should_Not_Apply_Conventions_When_Should_Apply_Is_False() { var conventionTracker = new ConventionTracker(); var convention = MockRepository.GenerateMock<IEdgeConvention>(); var fromNode = new GraphNode("a"); var toNode = new GraphNode("b"); var edgeInfo = new EdgeInfo(new NodeInfo(fromNode.Name, null), new NodeInfo(toNode.Name, null), null); convention.Expect(x => x.ShouldApply(edgeInfo)) .IgnoreArguments() .Return(false) .Repeat.Once(); convention.Expect(x => x.Apply(null, null)) .IgnoreArguments() .Repeat.Never(); conventionTracker.AddConvention(convention); conventionTracker.ApplyConventions(new DirectedEdge(new NodeTarget(fromNode), new NodeTarget(toNode))); convention.VerifyAllExpectations(); }
/// <summary> /// Applies the known conventions to the specified edge. /// </summary> /// <param name="edge">The edge to apply the conventions to.</param> public void ApplyConventions(IEdge edge) { for (int i = 0; i < edgeConventions.Count; i++) { var convention = edgeConventions[i]; var edgeInfo = new EdgeInfo(edge); if (convention.ShouldApply(edgeInfo)) { convention.Apply(edgeInfo, new EdgeExpression(edge)); } } }