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);
            }
        }
Esempio n. 2
0
        private static IEnumerable <TestCaseData> GetValidIllustrationPointNodes()
        {
            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")),
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B"))
            }).SetName("SubMechanismIllustrationPoints"));

            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")),
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("B"))
            }).SetName("SubMechanismAndFaultTreeIllustrationPoints"));

            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("A")),
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("B"))
            }).SetName("FaultTreeIllustrationPoints"));

            var node = new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("A"));

            node.SetChildren(new[]
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B")),
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("C"))
            });

            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("AA")),
                node
            }).SetName("FaultTreeIllustrationPointsWithChildren"));
        }
        public void GivenControl_WhenDataSetWithInvalidIllustrationPointChildType_ThenThrowsNotSupportedException()
        {
            // Given
            using (var control = new IllustrationPointsFaultTreeControl())
            {
                var rootNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());
                rootNode.SetChildren(new[]
                {
                    new IllustrationPointNode(new TestIllustrationPoint()),
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint())
                });

                var topLevelFaultTreeIllustrationPoint = new TopLevelFaultTreeIllustrationPoint(
                    WindDirectionTestFactory.CreateTestWindDirection(),
                    "closing situation",
                    rootNode);

                // When
                TestDelegate test = () => control.Data = topLevelFaultTreeIllustrationPoint;

                // Then
                var exception = Assert.Throws <NotSupportedException>(test);
                Assert.AreEqual($"IllustrationPointNode of type {nameof(TestIllustrationPoint)} is not supported. " +
                                $"Supported types: {nameof(FaultTreeIllustrationPoint)} and {nameof(SubMechanismIllustrationPoint)}", exception.Message);
            }
        }
        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);
            }
        }
Esempio n. 5
0
        public void Create_IllustrationPointNodeWithValidChildren_ReturnFaultTreeIllustrationPointEntity(
            IEnumerable <IllustrationPointNode> children)
        {
            // Setup
            var random = new Random(21);

            var illustrationPoint = new FaultTreeIllustrationPoint("Illustration point name A",
                                                                   random.NextDouble(),
                                                                   Enumerable.Empty <Stochast>(),
                                                                   random.NextEnumValue <CombinationType>());
            int order = random.Next();

            var node = new IllustrationPointNode(illustrationPoint);

            node.SetChildren(children.ToArray());

            // Call
            FaultTreeIllustrationPointEntity entity = node.Create(order);

            // Assert
            AssertFaultTreeIllustrationPointEntity(illustrationPoint, entity);
            AssertIllustrationPointEntities(node.Children.ToArray(),
                                            entity.SubMechanismIllustrationPointEntities.ToArray(),
                                            entity.FaultTreeIllustrationPointEntity1.ToArray());

            Assert.AreEqual(order, entity.Order);
        }
        /// <summary>
        /// Creates a new instance of <see cref="IllustrationPointNode"/> based on the
        /// information of <paramref name="hydraRingIllustrationPointTreeNode"/>.
        /// </summary>
        /// <param name="hydraRingIllustrationPointTreeNode">The <see cref="HydraRingIllustrationPointTreeNode"/>
        /// to base the <see cref="IllustrationPointNode"/> to create on.</param>
        /// <returns>The created <see cref="IllustrationPointNode"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when
        /// <paramref name="hydraRingIllustrationPointTreeNode"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="hydraRingIllustrationPointTreeNode"/>
        /// does not contain 0 or 2 children.</exception>
        /// <exception cref="IllustrationPointConversionException">Thrown when <paramref name="hydraRingIllustrationPointTreeNode"/>
        /// cannot be converted to a <see cref="IllustrationPointNode"/></exception>
        public static IllustrationPointNode Convert(HydraRingIllustrationPointTreeNode hydraRingIllustrationPointTreeNode)
        {
            if (hydraRingIllustrationPointTreeNode == null)
            {
                throw new ArgumentNullException(nameof(hydraRingIllustrationPointTreeNode));
            }

            IllustrationPointBase data;

            try
            {
                data = ConvertIllustrationPointTreeNodeData(hydraRingIllustrationPointTreeNode.Data);
            }
            catch (NotSupportedException e)
            {
                string errorMessage = "An illustration point containing a Hydra-Ring data type of " +
                                      $"{hydraRingIllustrationPointTreeNode.Data.GetType()} is not supported.";
                throw new IllustrationPointConversionException(errorMessage, e);
            }

            var illustrationPointNode = new IllustrationPointNode(data);

            illustrationPointNode.SetChildren(hydraRingIllustrationPointTreeNode.Children.Select(Convert).ToArray());

            return(illustrationPointNode);
        }
        public void GetStochastNamesRecursively_IllustrationPointNodeWithFaultTreeIllustrationPointAndChildrenContainingStochasts_ReturnStochastNames()
        {
            // Setup
            const string stochastNameA         = "Stochast A";
            const string stochastNameB         = "Stochast B";
            var          illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[]
            {
                new Stochast(stochastNameA, 2, 4),
                new Stochast(stochastNameB, 1, 5)
            }));

            illustrationPointNode.SetChildren(new[]
            {
                new IllustrationPointNode(new FaultTreeIllustrationPoint("Point A", 0.0, new[]
                {
                    new Stochast(stochastNameA, 2, 3)
                }, CombinationType.And)),
                new IllustrationPointNode(new FaultTreeIllustrationPoint("Point B", 0.0, new[]
                {
                    new Stochast(stochastNameB, 2, 3)
                }, CombinationType.And))
            });

            // Call
            IEnumerable <string> names = illustrationPointNode.GetStochastNamesRecursively();

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                stochastNameA,
                stochastNameB,
                stochastNameA,
                stochastNameB
            }, names);
        }
        public void SetChildren_ParentDoesNotContainSameStochastsAsChild_ThrowArgumentException()
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new FaultTreeIllustrationPoint("Top",
                                                                                                 0.0,
                                                                                                 new[]
            {
                new Stochast("Stochast A", 0, 0)
            },
                                                                                                 CombinationType.And));
            var childrenToBeAdded = new[]
            {
                new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[]
                {
                    new Stochast("Stochast B", 0, 0)
                })),
                new IllustrationPointNode(new TestFaultTreeIllustrationPoint("B"))
            };

            // Call
            TestDelegate test = () => illustrationPointNode.SetChildren(childrenToBeAdded);

            // Assert
            const string expectedMessage = "De stochasten van een illustratiepunt bevatten niet dezelfde stochasten als in de onderliggende illustratiepunten.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(test, expectedMessage);
        }
Esempio n. 9
0
        /// <summary>
        /// Reads the <see cref="FaultTreeIllustrationPointEntity"/> and uses
        /// the information to construct a <see cref="IllustrationPointNode"/>.
        /// </summary>
        /// <param name="entity">The <see cref="FaultTreeIllustrationPointEntity"/>
        /// to create a <see cref="IllustrationPointNode"/> for.</param>
        /// <returns>A new <see cref="IllustrationPointNode"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/>
        /// is <c>null</c>.</exception>
        public static IllustrationPointNode Read(this FaultTreeIllustrationPointEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var node = new IllustrationPointNode(GetFaultTreeIllustrationPoint(entity));

            node.SetChildren(GetChildren(entity).ToArray());

            return(node);
        }
        public void SetChildren_ChildrenNull_ThrowsArgumentNullException()
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint());

            // Call
            TestDelegate call = () => illustrationPointNode.SetChildren(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("children", exception.ParamName);
        }
        public void SetChildren_ValidNrOfChildren_ReturnsExpectedProperties(int nrOfChildren)
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint());
            var childrenToBeAdded     = new IllustrationPointNode[nrOfChildren];

            // Call
            illustrationPointNode.SetChildren(childrenToBeAdded);

            // Assert
            IEnumerable <IllustrationPointNode> addedChildren = illustrationPointNode.Children;

            Assert.AreSame(childrenToBeAdded, addedChildren);
            Assert.AreEqual(nrOfChildren, addedChildren.Count());
        }
        public void SetChildren_InvalidNrOfChildren_ThrowsInvalidArgumentException(int nrOfChildren)
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint());
            var childrenToBeAttached  = new IllustrationPointNode[nrOfChildren];

            // Call
            TestDelegate call = () => illustrationPointNode.SetChildren(childrenToBeAttached);

            // Assert
            const string expectedMessage = "Een illustratiepunt node in de foutenboom moet 0 of 2 onderliggende nodes hebben.";
            var          exception       = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);

            Assert.AreEqual("children", exception.ParamName);
            CollectionAssert.IsEmpty(illustrationPointNode.Children);
        }
        public void Create_ValidTopLevelFaultTreeIllustrationPointWithChildren_ReturnsTopLevelFaultTreeIllustrationPointEntityWithChildren()
        {
            // Setup
            var random = new Random(21);

            var windDirection         = new WindDirection("WindDirection Name", random.NextDouble());
            var illustrationPointNode = new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint());

            illustrationPointNode.SetChildren(new[]
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("Point A")),
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("Point B"))
            });

            var topLevelIllustrationPoint = new TopLevelFaultTreeIllustrationPoint(
                windDirection,
                "Just a situation",
                illustrationPointNode);
            int order = random.Next();

            // Call
            TopLevelFaultTreeIllustrationPointEntity entity = topLevelIllustrationPoint.Create(order);

            // Assert
            TestHelper.AssertAreEqualButNotSame(topLevelIllustrationPoint.ClosingSituation, entity.ClosingSituation);
            TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName);
            Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy());
            Assert.AreEqual(order, entity.Order);

            SubMechanismIllustrationPointEntity[] subMechanismIllustrationPointEntities =
                entity.FaultTreeIllustrationPointEntity.SubMechanismIllustrationPointEntities.ToArray();
            Assert.AreEqual(2, subMechanismIllustrationPointEntities.Length);

            for (var i = 0; i < 2; i++)
            {
                var expectedIllustrationPoint = new TestSubMechanismIllustrationPoint(subMechanismIllustrationPointEntities[i].Name);
                SubMechanismIllustrationPointEntity illustrationPointEntity = subMechanismIllustrationPointEntities[i];
                Assert.AreEqual(expectedIllustrationPoint.Name, illustrationPointEntity.Name);
                Assert.AreEqual(expectedIllustrationPoint.Beta, illustrationPointEntity.Beta, expectedIllustrationPoint.Beta.GetAccuracy());
                Assert.AreEqual(expectedIllustrationPoint.IllustrationPointResults.Count(),
                                illustrationPointEntity.IllustrationPointResultEntities.Count);
                Assert.AreEqual(expectedIllustrationPoint.Stochasts.Count(),
                                illustrationPointEntity.IllustrationPointResultEntities.Count);
                Assert.AreEqual(i, illustrationPointEntity.Order);
            }
        }
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var original = new IllustrationPointNode(new TestIllustrationPoint());

            original.SetChildren(new[]
            {
                new IllustrationPointNode(new TestIllustrationPoint()),
                new IllustrationPointNode(new TestIllustrationPoint())
            });

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
        public void SetChildren_ChildNamesNotUnique_ThrowArgumentException()
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint("Top"));
            var childrenToBeAdded     = new[]
            {
                new IllustrationPointNode(new TestFaultTreeIllustrationPoint("A")),
                new IllustrationPointNode(new TestFaultTreeIllustrationPoint("A"))
            };

            // Call
            TestDelegate test = () => illustrationPointNode.SetChildren(childrenToBeAdded);

            // Assert
            const string expectedMessage = "Een of meerdere illustratiepunten bevatten illustratiepunten met dezelfde naam.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(test, expectedMessage);
        }
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var faultTreeNodeRoot = new IllustrationPointNode(new TestIllustrationPoint());

            faultTreeNodeRoot.SetChildren(new[]
            {
                new IllustrationPointNode(new TestIllustrationPoint()),
                new IllustrationPointNode(new TestIllustrationPoint())
            });

            var original = new TopLevelFaultTreeIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(),
                                                                  "Random closing situation",
                                                                  faultTreeNodeRoot);

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
Esempio n. 17
0
        private static GeneralResult <TopLevelFaultTreeIllustrationPoint> GetGeneralResultWithThreeTopLevelIllustrationPointsWithChildren(bool sameClosingSituations)
        {
            var faultTreeNodeRootWithChildren = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());

            faultTreeNodeRootWithChildren.SetChildren(new[]
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("SubMechanismIllustrationPoint 1")),
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("SubMechanismIllustrationPoint 2"))
            });

            var topLevelFaultTreeIllustrationPoint1 =
                new TopLevelFaultTreeIllustrationPoint(
                    new WindDirection("Wind direction 1", 1.0),
                    sameClosingSituations ? "same closing situation" : "first closing situation",
                    faultTreeNodeRootWithChildren);

            var topLevelFaultTreeIllustrationPoint2 =
                new TopLevelFaultTreeIllustrationPoint(
                    new WindDirection("Wind direction 2", 2.0),
                    sameClosingSituations ? "same closing situation" : "second closing situation",
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint()));

            var topLevelFaultTreeIllustrationPoint3 =
                new TopLevelFaultTreeIllustrationPoint(
                    new WindDirection("Wind direction 3", 3.0),
                    sameClosingSituations ? "same closing situation" : "second closing situation",
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint()));

            var generalResultFunc = new GeneralResult <TopLevelFaultTreeIllustrationPoint>(
                WindDirectionTestFactory.CreateTestWindDirection(),
                Enumerable.Empty <Stochast>(),
                new[]
            {
                topLevelFaultTreeIllustrationPoint1,
                topLevelFaultTreeIllustrationPoint2,
                topLevelFaultTreeIllustrationPoint3
            });

            return(generalResultFunc);
        }