Пример #1
0
        public void Convert_WithGraphNode_ReturnPointedTreeElementVertex(GraphNodeShape graphNodeShape,
                                                                         PointedTreeVertexType expectedVertexType)
        {
            // Setup
            var random = new Random(21);

            const string content      = "<text>Node</text>";
            bool         isSelectable = random.NextBoolean();
            int          lineWidth    = random.Next();
            Color        fillColor    = Color.Aquamarine;
            Color        lineColor    = Color.Coral;

            var graphNode = new GraphNode(content, new GraphNode[0], isSelectable,
                                          new GraphNodeStyle(graphNodeShape, fillColor,
                                                             lineColor, lineWidth));

            // Call
            PointedTreeElementVertex vertex = GraphNodeConverter.Convert(graphNode);

            // Assert
            Assert.AreEqual(content, vertex.Content);
            Assert.AreEqual(isSelectable, vertex.IsSelectable);
            Assert.AreEqual(expectedVertexType, vertex.Type);
            Assert.AreEqual(lineWidth, vertex.LineWidth);
            AssertColors(fillColor, vertex.FillColor);
            AssertColors(lineColor, vertex.LineColor);
        }
Пример #2
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            const string content             = "test";
            Color        fillColor           = Colors.Blue;
            Color        lineColor           = Colors.Gray;
            const int    lineWidth           = 3;
            const PointedTreeVertexType type = PointedTreeVertexType.None;
            const bool isSelectable          = true;

            // Call
            var vertex = new PointedTreeElementVertex(content, fillColor, lineColor, lineWidth, type, isSelectable);

            // Assert
            Assert.IsInstanceOf <INotifyPropertyChanged>(vertex);
            Assert.AreEqual(content, vertex.Content);
            Assert.IsInstanceOf <SolidColorBrush>(vertex.FillColor);
            Assert.AreEqual(fillColor, ((SolidColorBrush)vertex.FillColor).Color);
            Assert.IsInstanceOf <SolidColorBrush>(vertex.LineColor);
            Assert.AreEqual(lineColor, ((SolidColorBrush)vertex.LineColor).Color);
            Assert.AreEqual(lineWidth, vertex.LineWidth);
            Assert.AreEqual(type, vertex.Type);
            Assert.AreEqual(isSelectable, vertex.IsSelectable);
            Assert.IsFalse(vertex.IsSelected);
            Assert.IsInstanceOf <VertexSelectedCommand>(vertex.VertexSelectedCommand);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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 GivenControlWithData_WhenVertexSelected_SelectionSetToCorrespondingIllustrationPointNodeSelectionChangedFired()
        {
            // Given
            using (var control = new IllustrationPointsFaultTreeControl())
            {
                var illustrationPointNode = new IllustrationPointNode(new TestSubMechanismIllustrationPoint());

                var rootNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint("A"));
                rootNode.SetChildren(new[]
                {
                    illustrationPointNode,
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B"))
                });

                control.Data = new TopLevelFaultTreeIllustrationPoint(
                    WindDirectionTestFactory.CreateTestWindDirection(),
                    "closing situation",
                    rootNode);

                var selectionChanged = 0;
                control.SelectionChanged += (sender, args) => selectionChanged++;

                PointedTreeElementVertex selectedVertex = GetPointedTreeGraph(control).Vertices.ElementAt(2);

                // When
                selectedVertex.IsSelected = true;

                // Then
                object selection = control.Selection;
                Assert.AreSame(illustrationPointNode, selection);
                Assert.AreEqual(1, selectionChanged);
            }
        }
Пример #6
0
        /// <summary>
        /// Creates a new instance of <see cref="VertexSelectedCommand"/>.
        /// </summary>
        /// <param name="vertex">The <see cref="PointedTreeElementVertex"/>
        /// to create the command for.</param>
        /// <exception cref="ArgumentNullException">Thrown when
        /// <paramref name="vertex"/> is <c>null</c>.</exception>
        public VertexSelectedCommand(PointedTreeElementVertex vertex)
        {
            if (vertex == null)
            {
                throw new ArgumentNullException(nameof(vertex));
            }

            this.vertex = vertex;
        }
Пример #7
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            PointedTreeElementVertex source = PointedTreeTestDataFactory.CreatePointedTreeElementVertex();
            PointedTreeElementVertex target = PointedTreeTestDataFactory.CreatePointedTreeElementVertex();

            // Call
            var edge = new PointedTreeEdge(source, target);

            // Assert
            Assert.IsInstanceOf <Edge <PointedTreeElementVertex> >(edge);
            Assert.AreSame(source, edge.Source);
            Assert.AreSame(target, edge.Target);
        }
Пример #8
0
        public void IsSelected_SetNewValue_PropertyChangedEventFired()
        {
            // Setup
            PointedTreeElementVertex vertex = PointedTreeTestDataFactory.CreatePointedTreeElementVertex(true);

            var propertyChanged = 0;

            vertex.PropertyChanged += (sender, args) => propertyChanged++;

            // Call
            vertex.IsSelected = true;

            // Assert
            Assert.AreEqual(1, propertyChanged);
        }
Пример #9
0
        public void Execute_Always_SetVertexSelectionToTrue()
        {
            // Setup
            PointedTreeElementVertex vertex = PointedTreeTestDataFactory.CreatePointedTreeElementVertex(true);
            var command = new VertexSelectedCommand(vertex);

            // Precondition
            Assert.IsFalse(vertex.IsSelected);

            // Call
            command.Execute(null);

            // Assert
            Assert.IsTrue(vertex.IsSelected);
        }
Пример #10
0
        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();
        }
Пример #11
0
        private void DrawNode(GraphNode node, PointedTreeElementVertex parentVertex = null)
        {
            PointedTreeElementVertex vertex = GraphNodeConverter.Convert(node);

            vertex.PropertyChanged += VertexOnPropertyChanged;

            var drawnGraphNode = new DrawnGraphNode
            {
                GraphNode = node,
                Vertex    = vertex
            };

            drawnGraphNodeList.Add(drawnGraphNode);

            graph.AddVertex(vertex);

            node.ChildNodes.ForEachElementDo(cn => DrawNode(cn, vertex));

            if (parentVertex != null)
            {
                graph.AddEdge(new PointedTreeEdge(parentVertex, vertex));
            }
        }