public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeAndSectionsNotUpdated_ThenDataGridViewNotUpdated()
        {
            // Given
            var failureMechanism = new TestFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                CreateFailureMechanismSection("a")
            });

            using (FailureMechanismSectionsView view = ShowFailureMechanismSectionsView(failureMechanism.Sections, failureMechanism))
            {
                DataGridView sectionsDataGridView = GetSectionsDataGridView(view);

                var invalidated = false;

                sectionsDataGridView.Invalidated += (s, e) =>
                {
                    invalidated = true;
                };

                // When
                failureMechanism.NotifyObservers();

                // Then
                Assert.IsFalse(invalidated);
            }
        }
Exemplo n.º 2
0
        public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeButNothingRelevantChanged_ThenDataGridViewNotUpdated()
        {
            // Given
            var failureMechanism = new TestFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                CreateFailureMechanismSection("a", 0.0, 0.0, 1.0, 1.0)
            });

            ProbabilityAssessmentInput probabilityAssessmentInput = CreateProbabilityAssessmentInput();

            using (FailureMechanismSectionsProbabilityAssessmentView view = ShowFailureMechanismSectionsProbabilityAssessmentView(failureMechanism.Sections,
                                                                                                                                  failureMechanism,
                                                                                                                                  probabilityAssessmentInput))
            {
                DataGridView sectionsDataGridView = GetSectionsDataGridView(view);

                var invalidated = false;

                sectionsDataGridView.Invalidated += (s, e) =>
                {
                    invalidated = true;
                };

                // When
                failureMechanism.NotifyObservers();

                // Then
                Assert.IsFalse(invalidated);
            }
        }
        public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeAndSectionsUpdated_ThenDataGridViewUpdated()
        {
            // Given
            var failureMechanism = new TestFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                CreateFailureMechanismSection("a")
            });

            using (FailureMechanismSectionsView view = ShowFailureMechanismSectionsView(failureMechanism.Sections, failureMechanism))
            {
                DataGridViewControl sectionsDataGridViewControl = GetSectionsDataGridViewControl(view);

                // Precondition
                AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), sectionsDataGridViewControl);

                // When
                FailureMechanismTestHelper.SetSections(failureMechanism, new[]
                {
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
                });
                failureMechanism.NotifyObservers();

                // Then
                AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), sectionsDataGridViewControl);
            }
        }
Exemplo n.º 4
0
        public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeAndSectionsUpdated_ThenDataGridViewUpdated()
        {
            // Given
            var failureMechanism = new TestFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                CreateFailureMechanismSection("a", 0.0, 0.0, 1.0, 1.0)
            });

            ProbabilityAssessmentInput probabilityAssessmentInput = CreateProbabilityAssessmentInput();

            using (FailureMechanismSectionsProbabilityAssessmentView view = ShowFailureMechanismSectionsProbabilityAssessmentView(failureMechanism.Sections,
                                                                                                                                  failureMechanism,
                                                                                                                                  probabilityAssessmentInput))
            {
                DataGridViewControl sectionsDataGridViewControl = GetSectionsDataGridViewControl(view);

                // Precondition
                AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), probabilityAssessmentInput, sectionsDataGridViewControl);

                // When
                FailureMechanismTestHelper.SetSections(failureMechanism, new[]
                {
                    CreateFailureMechanismSection("a", 1.0, 1.0, 2.0, 2.0)
                });
                failureMechanism.NotifyObservers();

                // Then
                AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), probabilityAssessmentInput, sectionsDataGridViewControl);
            }
        }
        public void GivenMapLayerWithFailureMechanismSectionAssemblyResults_WhenChangingFailureMechanismDataAndObserversNotified_ThenMapDataUpdated()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var random           = new Random(21);
            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            using (var mapLayer = new NonCalculatableFailureMechanismSectionResultsMapLayer <TestFailureMechanismSectionResult>(
                       failureMechanism, result => assemblyResult))
            {
                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);

                // When
                failureMechanism.SetSections(new[]
                {
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                    {
                        new Point2D(0, 0),
                        new Point2D(1, 1)
                    }),
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                    {
                        new Point2D(1, 1),
                        new Point2D(2, 2)
                    })
                }, string.Empty);
                failureMechanism.NotifyObservers();

                // Then
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }
        public void GivenPropertyControlWithData_WhenFailureMechanismUpdated_RefreshRequiredEventRaised()
        {
            // Given
            var failureMechanism = new TestFailureMechanism();

            using (var properties = new FailureMechanismSectionsProperties(failureMechanism))
            {
                var refreshRequiredRaised = 0;
                properties.RefreshRequired += (sender, args) => refreshRequiredRaised++;

                // When
                failureMechanism.NotifyObservers();

                // Then
                Assert.AreEqual(1, refreshRequiredRaised);
            }
        }
Exemplo n.º 7
0
        public void GivenPropertyControlWithData_WhenFailureMechanismUpdated_RefreshRequiredEventRaised()
        {
            // Given
            var random = new Random(39);
            var probabilityAssessmentInput = new TestProbabilityAssessmentInput(random.NextDouble(), random.NextDouble());
            var failureMechanism           = new TestFailureMechanism();

            using (var properties = new FailureMechanismSectionsProbabilityAssessmentProperties(
                       failureMechanism, probabilityAssessmentInput))
            {
                var refreshRequiredRaised = 0;
                properties.RefreshRequired += (sender, args) => refreshRequiredRaised++;

                // When
                failureMechanism.NotifyObservers();

                // Then
                Assert.AreEqual(1, refreshRequiredRaised);
            }
        }
Exemplo n.º 8
0
        public void UpdateObserver_FailureMechanismUpdated_MapDataUpdated()
        {
            // Setup
            var failureMechanism = new TestFailureMechanism();

            using (StandAloneFailureMechanismView <IFailureMechanism <FailureMechanismSectionResult>, FailureMechanismSectionResult> view =
                       CreateView(failureMechanism, new AssessmentSectionStub()))
            {
                IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

                IEnumerable <MapData> sectionsCollection = ((MapDataCollection)map.Data.Collection.ElementAt(sectionsCollectionIndex)).Collection;
                var sectionMapData       = (MapLineData)sectionsCollection.ElementAt(sectionsIndex);
                var sectionStartsMapData = (MapPointData)sectionsCollection.ElementAt(sectionsStartPointIndex);
                var sectionsEndsMapData  = (MapPointData)sectionsCollection.ElementAt(sectionsEndPointIndex);

                var         mocks     = new MockRepository();
                IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
                observers[sectionsObserverIndex].Expect(obs => obs.UpdateObserver());
                observers[sectionsStartPointObserverIndex].Expect(obs => obs.UpdateObserver());
                observers[sectionsEndPointObserverIndex].Expect(obs => obs.UpdateObserver());
                mocks.ReplayAll();

                // Call
                FailureMechanismTestHelper.SetSections(failureMechanism, new[]
                {
                    new FailureMechanismSection(string.Empty, new[]
                    {
                        new Point2D(1, 2),
                        new Point2D(1, 2)
                    })
                });
                failureMechanism.NotifyObservers();

                // Assert
                MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData);
                MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData);
                MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData);
                mocks.VerifyAll();
            }
        }
Exemplo n.º 9
0
        public void GivenViewWithSections_WhenFailureMechanismNotifiesChangeAndProbabilityAssessmentInputChanged_ThenDataGridViewRefreshed()
        {
            // Given
            var failureMechanism = new TestFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                CreateFailureMechanismSection("a", 0.0, 0.0, 1.0, 1.0)
            });

            ProbabilityAssessmentInput probabilityAssessmentInput = CreateProbabilityAssessmentInput();

            using (FailureMechanismSectionsProbabilityAssessmentView view = ShowFailureMechanismSectionsProbabilityAssessmentView(failureMechanism.Sections,
                                                                                                                                  failureMechanism,
                                                                                                                                  probabilityAssessmentInput))
            {
                DataGridView sectionsDataGridView = GetSectionsDataGridView(view);

                var dataSourceChanged = false;

                sectionsDataGridView.DataSourceChanged += (s, e) =>
                {
                    dataSourceChanged = true;
                };

                DataGridViewControl sectionsDataGridViewControl = GetSectionsDataGridViewControl(view);

                // Precondition
                AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), probabilityAssessmentInput, sectionsDataGridViewControl);

                // When
                probabilityAssessmentInput.A = 0.5;
                failureMechanism.NotifyObservers();

                // Then
                Assert.IsFalse(dataSourceChanged);
                AssertSectionsDataGridViewControl(failureMechanism.Sections.ToArray(), probabilityAssessmentInput, sectionsDataGridViewControl);
            }
        }
Exemplo n.º 10
0
        public void GivenFailureMechanismResultObserverWithAttachedObserver_WhenFailureMechanismNotifiesObservers_ThenAttachedObserverNotified()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var failureMechanism = new TestFailureMechanism();

            using (var resultObserver = new FailureMechanismResultObserver <TestFailureMechanism, FailureMechanismSectionResult>(
                       failureMechanism))
            {
                resultObserver.Attach(observer);

                // When
                failureMechanism.NotifyObservers();
            }

            // Then
            mocks.VerifyAll();
        }