public void GivenControlWithSelectedVertex_WhenOtherVertexSelected_FirstSelectedVertexUnselected() { // Given using (var graphControl = new PointedTreeGraphControl()) { var node = new GraphNode("<text>node 1</text>", new[] { new GraphNode("<text>node 2</text>", new GraphNode[0], true) }, true); graphControl.Data = node; PointedTreeGraph graph = PointedTreeGraphControlHelper.GetPointedTreeGraph(graphControl); PointedTreeElementVertex firstSelectedVertex = graph.Vertices.ElementAt(1); firstSelectedVertex.IsSelected = true; PointedTreeElementVertex newSelectedVertex = graph.Vertices.First(); // When newSelectedVertex.IsSelected = true; // Then Assert.IsFalse(firstSelectedVertex.IsSelected); } }
public void GivenGraphControlWithoutData_WhenDataSet_ThenGraphControlUpdated() { // Given using (var graphControl = new PointedTreeGraphControl()) { var doubleUsedNode = new GraphNode("<text>Double used</text>", new GraphNode[0], false); var node = new GraphNode("<text>Root</text>", new[] { new GraphNode("<text>Child 1</text>", new[] { doubleUsedNode }, false), new GraphNode("<text>Child 2</text>", new[] { doubleUsedNode }, false) }, false); PointedTreeGraph originalGraph = PointedTreeGraphControlHelper.GetPointedTreeGraph(graphControl); // When graphControl.Data = node; // Then PointedTreeGraph newGraph = PointedTreeGraphControlHelper.GetPointedTreeGraph(graphControl); Assert.AreNotSame(originalGraph, newGraph); Assert.AreEqual(5, newGraph.VertexCount); Assert.AreEqual(4, newGraph.EdgeCount); } }
public void GivenControlWithData_WhenVertexSelected_SelectionSetToGraphNodeAndSelectionChangedFired() { // Given using (var graphControl = new PointedTreeGraphControl()) { var childNode = new GraphNode("<text>node 2</text>", new GraphNode[0], true); var node = new GraphNode("<text>node 1</text>", new[] { childNode }, true); graphControl.Data = node; PointedTreeGraph graph = PointedTreeGraphControlHelper.GetPointedTreeGraph(graphControl); var selectionChanged = 0; graphControl.SelectionChanged += (sender, args) => selectionChanged++; // Precondition Assert.IsNull(graphControl.Selection); // When PointedTreeElementVertex selectedVertex = graph.Vertices.ElementAt(1); selectedVertex.IsSelected = true; // Then Assert.AreSame(childNode, graphControl.Selection); Assert.AreEqual(1, selectionChanged); } }
public void GivenGraphControlWithData_WhenDataSetToNull_ThenGraphControlUpdated() { // Given var node = new GraphNode("<text>Root</text>", new[] { new GraphNode("<text>Child 1</text>", new GraphNode[0], false) }, false); using (var graphControl = new PointedTreeGraphControl { Data = node }) { PointedTreeGraph graph = PointedTreeGraphControlHelper.GetPointedTreeGraph(graphControl); // Precondition Assert.AreEqual(2, graph.VertexCount); Assert.AreEqual(1, graph.EdgeCount); // When graphControl.Data = null; // Then graph = PointedTreeGraphControlHelper.GetPointedTreeGraph(graphControl); Assert.AreEqual(0, graph.VertexCount); Assert.AreEqual(0, graph.EdgeCount); } }
public void GivenControlWithData_WhenDataSetToNull_ThenPointedTreeGraphUpdated() { // Given using (var control = new IllustrationPointsFaultTreeControl()) { var rootNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint()); rootNode.SetChildren(new[] { new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")), new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B")) }); control.Data = new TopLevelFaultTreeIllustrationPoint( WindDirectionTestFactory.CreateTestWindDirection(), "closing situation", rootNode); PointedTreeGraph graph = GetPointedTreeGraph(control); // Precondition Assert.AreEqual(4, graph.VertexCount); Assert.AreEqual(3, graph.EdgeCount); // When control.Data = null; // Then graph = GetPointedTreeGraph(control); Assert.IsNull(control.Selection); Assert.AreEqual(0, graph.VertexCount); Assert.AreEqual(0, graph.EdgeCount); } }
public void Constructor_ExpectedValues() { // Call var graph = new PointedTreeGraph(); // Assert Assert.IsInstanceOf <BidirectionalGraph <PointedTreeElementVertex, PointedTreeEdge> >(graph); }
private void CreateNewGraph() { graph = new PointedTreeGraph(); zoomControl.Content = new PointedTreeGraphLayout { Graph = graph }; }
public void GivenFullyConfiguredView_WhenSelectingFaultTreeIllustrationPointInTree_ThenSelectionChangedAndPropagatedAccordingly(bool sameClosingSituations) { // Given var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResultFunc = GetGeneralResultWithThreeTopLevelIllustrationPointsWithChildren(sameClosingSituations); var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => generalResultFunc); ShowTestView(view); var selectionChangedCount = 0; view.SelectionChanged += (sender, args) => selectionChangedCount++; IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view); PointedTreeGraph pointedTreeGraph = GetPointedTreeGraph(illustrationPointsFaultTreeControl); // When PointedTreeElementVertex selectedVertex = pointedTreeGraph.Vertices.ElementAt(0); selectedVertex.IsSelected = true; // Then Assert.AreEqual(1, selectionChangedCount); TopLevelFaultTreeIllustrationPoint topLevel = generalResultFunc.TopLevelIllustrationPoints.First(); IllustrationPointNode expectedSelectedNode = topLevel.FaultTreeNodeRoot; var selectedFaultTreeContext = view.Selection as IllustrationPointContext <FaultTreeIllustrationPoint>; Assert.IsNotNull(selectedFaultTreeContext); Assert.AreSame(expectedSelectedNode, selectedFaultTreeContext.IllustrationPointNode); Assert.AreEqual(sameClosingSituations ? string.Empty : topLevel.ClosingSituation, selectedFaultTreeContext.ClosingSituation); Assert.AreEqual(topLevel.WindDirection.Name, selectedFaultTreeContext.WindDirectionName); mocks.VerifyAll(); }