Exemplo n.º 1
0
        public void Constructor_ExpectedValues()
        {
            // Call
            using (var graphControl = new PointedTreeGraphControl())
            {
                // Assert
                Assert.IsInstanceOf <UserControl>(graphControl);
                Assert.IsInstanceOf <IPointedTreeGraphControl>(graphControl);

                Assert.IsNull(graphControl.Data);
                Assert.IsNull(graphControl.Selection);

                Assert.AreEqual(1, graphControl.Controls.Count);

                ZoomControl zoomControl = PointedTreeGraphControlHelper.GetZoomControl(graphControl);

                Assert.AreEqual(300, zoomControl.ZoomDeltaMultiplier);
                Assert.AreEqual(ZoomControlModes.Original, zoomControl.Mode);
                Assert.AreEqual(ZoomViewModifierMode.None, zoomControl.ModifierMode);
                Assert.AreEqual(new TimeSpan(0), zoomControl.AnimationLength);

                Assert.AreEqual(1, zoomControl.Resources.MergedDictionaries.Count);
                ResourceDictionary templateDictionary = zoomControl.Resources.MergedDictionaries.First();
                Assert.AreEqual("/Core.Components.GraphSharp.Forms;component/Templates/PointedTreeGraphTemplate.xaml", templateDictionary.Source.AbsolutePath);

                var graphLayout = (PointedTreeGraphLayout)zoomControl.Content;
                Assert.IsInstanceOf <PointedTreeGraph>(graphLayout.Graph);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the underlying <see cref="PointedTreeGraph"/> from the <paramref name="control"/>.
        /// </summary>
        /// <param name="control">The control to get the underlying <see cref="PointedTreeGraph"/>.</param>
        /// <returns>The found <see cref="PointedTreeGraph"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="control"/> is <c>null</c>.</exception>
        public static PointedTreeGraph GetPointedTreeGraph(PointedTreeGraphControl control)
        {
            ZoomControl zoomControl = GetZoomControl(control);
            var         graphLayout = (PointedTreeGraphLayout)zoomControl.Content;

            return(graphLayout.Graph);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the underlying <see cref="ZoomControl"/> from the <paramref name="control"/>.
        /// </summary>
        /// <param name="control">The control to get the underlying <see cref="ZoomControl"/>.</param>
        /// <returns>The found <see cref="ZoomControl"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="control"/> is <c>null</c>.</exception>
        public static ZoomControl GetZoomControl(PointedTreeGraphControl control)
        {
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            var elementHost = TypeUtils.GetField <ElementHost>(control, "wpfElementHost");

            return((ZoomControl)elementHost.Child);
        }