Example #1
0
        public void GivenCalculationsView_WhenCalculationUpdatedAndNotified_ThenDataGridViewCorrectlyUpdated()
        {
            // Given
            const string calculationName = "New name";

            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            ConfigureHydraulicBoundaryDatabase(assessmentSection);
            mocks.ReplayAll();

            CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection);

            ShowCalculationsView(calculationGroup, new TestCalculatableFailureMechanism(), assessmentSection);
            var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

            var invalidated = 0;

            dataGridView.Invalidated += (sender, args) => invalidated++;

            // When
            TestCalculation calculation = calculationGroup.Children.Cast <TestCalculation>().First();

            calculation.Name = calculationName;
            calculation.NotifyObservers();

            // Then
            Assert.AreEqual(calculationName, dataGridView.Rows[0].Cells[nameColumnIndex].Value);
            Assert.AreEqual(1, invalidated);
            mocks.VerifyAll();
        }
Example #2
0
        public void GivenViewWithoutIllustrationPoints_WhenIllustrationPointsSetAndNotifiesObserver_ThenControlsSyncedAccordingly()
        {
            // Given
            var returnGeneralResult = false;

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

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

            ShowTestView(view);

            returnGeneralResult = true;

            // Precondition
            IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(view);

            CollectionAssert.IsEmpty(illustrationPointsControl.Data);

            // When
            calculation.NotifyObservers();

            // Then
            AssertIllustrationPointControlItems(generalResult, illustrationPointsControl);
        }
Example #3
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);
        }
Example #4
0
        public void GivenViewWithoutIllustrationPoints_WhenIllustrationPointsChangedAndContainingNotSupportedIllustrationPoints_ThenThrowsNotSupportedException()
        {
            // Given
            var calculation      = new TestCalculation();
            var hasGeneralResult = false;

            var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => hasGeneralResult
                                                                                              ? GetGeneralResultWithTopLevelIllustrationPointsOfNotSupportedType()
                                                                                              : null);

            ShowTestView(view);

            hasGeneralResult = true;

            // When
            void Call() => calculation.NotifyObservers();

            // Assert
            var exception = Assert.Throws <NotSupportedException>(Call);

            Assert.AreEqual($"IllustrationPointNode of type {nameof(TestIllustrationPoint)} is not supported. " +
                            $"Supported types: {nameof(FaultTreeIllustrationPoint)} and {nameof(SubMechanismIllustrationPoint)}", exception.Message);
        }
Example #5
0
        public void GivenFullyConfiguredView_WhenOutputChangesAndNotifyObserver_ThenSelectionChangedAndPropagated(bool withInitialOutput)
        {
            // Given
            var calculation = new TestCalculation();

            if (withInitialOutput)
            {
                calculation.Output = new object();
            }

            var view = new TestGeneralResultIllustrationPointView(
                calculation, () => withInitialOutput
                                       ? GetGeneralResultWithTwoTopLevelIllustrationPoints()
                                       : null);

            ShowTestView(view);

            var selectionChangedCount = 0;

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

            // When
            calculation.Output = withInitialOutput ? null : new object();
            calculation.NotifyObservers();

            // Then
            Assert.AreEqual(1, selectionChangedCount);
            if (withInitialOutput)
            {
                Assert.IsNotNull(view.Selection);
            }
            else
            {
                Assert.IsNull(view.Selection);
            }
        }