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);
            }
        }
Exemple #2
0
        public void GivenViewWithIllustrationPoints_WhenIllustrationPointsCleared_ThenControlsSyncedAccordingly()
        {
            // Given
            var returnGeneralResult = true;

            var calculation = new TestCalculation();
            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints();

            var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => returnGeneralResult
                                                                                              ? generalResult
                                                                                              : null);

            ShowTestView(view);

            // Precondition
            IllustrationPointsControl          illustrationPointsControl          = GetIllustrationPointsControl(view);
            IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view);

            AssertIllustrationPointControlItems(generalResult, illustrationPointsControl);
            Assert.AreSame(generalResult.TopLevelIllustrationPoints.First(), illustrationPointsFaultTreeControl.Data);

            // When
            returnGeneralResult = false;
            calculation.NotifyObservers();

            // Then
            CollectionAssert.IsEmpty(illustrationPointsControl.Data);
            Assert.IsNull(illustrationPointsFaultTreeControl.Data);
        }
        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);
            }
        }
        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 Constructor_ExpectedValues()
        {
            // Call
            using (var control = new IllustrationPointsFaultTreeControl())
            {
                // Assert
                Assert.IsInstanceOf <UserControl>(control);
                Assert.IsInstanceOf <ISelectionProvider>(control);
                Assert.IsNull(control.Data);
                Assert.IsNull(control.Selection);
                Assert.AreEqual("IllustrationPointsFaultTreeControl", control.Name);

                Assert.AreEqual(1, control.Controls.Count);
                var pointedTreeGraphControl = control.Controls[0] as PointedTreeGraphControl;
                Assert.IsNotNull(pointedTreeGraphControl);
            }
        }
Exemple #6
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();
        }
Exemple #7
0
        public void GivenFullyConfiguredView_WhenSelectingCellInRow_ThenSelectionChangedAndPropagatedAccordingly()
        {
            // Given
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints();
            var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => generalResult);

            ShowTestView(view);

            var selectionChangedCount = 0;

            view.SelectionChanged += (sender, args) => selectionChangedCount++;

            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            // When
            dataGridView.CurrentCell = dataGridView.Rows[1].Cells[0];
            EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0));

            // Then
            Assert.AreEqual(1, selectionChangedCount);

            IEnumerable <TopLevelFaultTreeIllustrationPoint> topLevelFaultTreeIllustrationPoints = generalResult.TopLevelIllustrationPoints.ToArray();
            TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint = topLevelFaultTreeIllustrationPoints.ElementAt(1);

            AssertIllustrationPointSelection(topLevelFaultTreeIllustrationPoint,
                                             topLevelFaultTreeIllustrationPoints.Select(ip => ip.ClosingSituation),
                                             view.Selection);

            IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view);

            Assert.AreSame(topLevelFaultTreeIllustrationPoint, illustrationPointsFaultTreeControl.Data);
            mocks.VerifyAll();
        }
Exemple #8
0
        public void Constructor_GeneralResultWithoutIllustrationPoints_DataSetOnIllustrationPointControl()
        {
            // Setup
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            // Call
            var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => null);

            ShowTestView(view);

            // Assert
            IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view);

            CollectionAssert.IsEmpty(illustrationPointsControl.Data);

            IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view);

            Assert.IsNull(illustrationPointsFaultTreeControl.Data);

            mocks.VerifyAll();
        }
Exemple #9
0
        private static PointedTreeGraph GetPointedTreeGraph(IllustrationPointsFaultTreeControl control)
        {
            var pointedTreeGraphControl = TypeUtils.GetField <PointedTreeGraphControl>(control, "pointedTreeGraphControl");

            return(PointedTreeGraphControlHelper.GetPointedTreeGraph(pointedTreeGraphControl));
        }