Esempio n. 1
0
        public void GivenCalculationsView_WhenCalculationInputUpdatedAndNotified_ThenDataGridViewCorrectlyUpdated()
        {
            // Given
            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 dataSourceUpdated = 0;

            dataGridView.DataSourceChanged += (sender, args) => dataSourceUpdated++;

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

            calculation.InputParameters.HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.Last();
            calculation.InputParameters.NotifyObservers();

            // Then
            Assert.AreEqual(1, dataSourceUpdated);
            mocks.VerifyAll();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var mocks   = new MockRepository();
            var handler = mocks.Stub <IObservablePropertyChangeHandler>();

            mocks.ReplayAll();

            var calculation = new TestCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
                }
            };

            // Call
            var row = new TestCalculationRow(calculation, handler);

            // Assert
            Assert.AreSame(calculation, row.Calculation);
            Assert.AreEqual(calculation.Name, row.Name);
            Assert.AreSame(calculation.InputParameters.HydraulicBoundaryLocation, row.SelectableHydraulicBoundaryLocation.WrappedObject.HydraulicBoundaryLocation);
            mocks.VerifyAll();
        }
Esempio n. 6
0
        public void Name_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged()
        {
            // Setup
            var mockRepository = new MockRepository();
            var observer       = mockRepository.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            const string newValue = "Test new name";

            var calculation = new TestCalculation();
            var row         = new TestCalculationRow(calculation, handler);

            calculation.Attach(observer);

            // Call
            row.Name = newValue;

            // Assert
            Assert.AreEqual(newValue, calculation.Name);
            mockRepository.VerifyAll();
        }
Esempio n. 7
0
        public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers()
        {
            // Setup
            var       mocks                     = new MockRepository();
            var       projectObserver           = mocks.StrictMock <IObserver>();
            const int numberOfChangedProperties = 1;

            projectObserver.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties);
            var failureMechanism = mocks.StrictMock <ICalculatableFailureMechanism>();

            mocks.ReplayAll();

            var calculation            = new TestCalculation();
            var testCalculationContext = new TestCalculationContext(calculation, new CalculationGroup(), failureMechanism);

            calculation.Attach(projectObserver);

            var properties = new CalculationContextProperties
            {
                Data = testCalculationContext
            };

            // Call
            const string newName = "Some new cool pretty name";

            properties.Name = newName;

            // Assert
            Assert.AreEqual(newName, calculation.Name);

            mocks.VerifyAll();
        }
Esempio n. 8
0
        private static void SetPropertyAndVerifyNotificationsAndOutputForCalculation(
            Action <CalculationRow <TestCalculation> > setProperty,
            TestCalculation calculation)
        {
            // Setup
            var mocks      = new MockRepository();
            var observable = mocks.StrictMock <IObservable>();

            observable.Expect(o => o.NotifyObservers());
            mocks.ReplayAll();

            var handler = new SetPropertyValueAfterConfirmationParameterTester(
                new[]
            {
                observable
            });

            var row = new TestCalculationRow(calculation, handler);

            // Call
            setProperty(row);

            // Assert
            Assert.IsTrue(handler.Called);
            mocks.VerifyAll();
        }
Esempio n. 9
0
        public void SelectableHydraulicBoundaryLocation_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged()
        {
            // Setup
            var newLocation = new TestHydraulicBoundaryLocation();
            var selectableHydraulicBoundaryLocation = new SelectableHydraulicBoundaryLocation(newLocation, new Point2D(0, 0));
            var newValue = new DataGridViewComboBoxItemWrapper <SelectableHydraulicBoundaryLocation>(selectableHydraulicBoundaryLocation);

            var calculation = new TestCalculation();

            // Call & Assert
            SetPropertyAndVerifyNotificationsAndOutputForCalculation(row => row.SelectableHydraulicBoundaryLocation = newValue, calculation);
        }
Esempio n. 10
0
            public TestCalculationRowWithColumnStateDefinitions(TestCalculation calculation,
                                                                IObservablePropertyChangeHandler propertyChangeHandler,
                                                                bool initialReadOnlyState)
                : base(calculation, propertyChangeHandler)
            {
                ColumnStateDefinitions = new Dictionary <int, DataGridViewColumnStateDefinition>
                {
                    {
                        nameColumnIndex, new DataGridViewColumnStateDefinition()
                    },
                    {
                        selectableHydraulicBoundaryLocationsColumnIndex, new DataGridViewColumnStateDefinition()
                    }
                };

                SetReadOnlyState(initialReadOnlyState);
            }
Esempio n. 11
0
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            const string name        = "<very cool name>";
            var          calculation = new TestCalculation(name);

            var mocks            = new MockRepository();
            var failureMechanism = mocks.StrictMock <ICalculatableFailureMechanism>();

            mocks.ReplayAll();

            var properties = new CalculationContextProperties
            {
                Data = new TestCalculationContext(calculation, new CalculationGroup(), failureMechanism)
            };

            // Call & Assert
            Assert.AreEqual(name, properties.Name);
            mocks.VerifyAll();
        }
Esempio n. 12
0
        public void DoPostUpdateActions_Always_NotifiesCalculationObservers()
        {
            // Setup
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.StrictMock <IInquiryHelper>();
            var observer      = mocks.StrictMock <IObserver>();

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

            var calculation = new TestCalculation();

            calculation.Attach(observer);

            var handler = new TestClearIllustrationPointsOfCalculationChangeHandler(inquiryHelper, calculation);

            // Call
            handler.DoPostUpdateActions();

            // Assert
            mocks.VerifyAll();
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
            }
        }
Esempio n. 15
0
 protected override TestCalculationRow CreateRow(TestCalculation calculation)
 {
     return(new TestCalculationRow(calculation, new ObservablePropertyChangeHandler(calculation, calculation.InputParameters)));
 }
Esempio n. 16
0
 protected override TestCalculationRow CreateRow(TestCalculation calculation)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
        private static void AssertPropertyChangeWithOrWithoutCalculationOutput(
            Action <CalculationRow <TestCalculation> > setProperty,
            Action <TestCalculation> assertions,
            bool hasOutput,
            bool expectUpdates)
        {
            // Setup
            var mockRepository = new MockRepository();
            var inputObserver  = mockRepository.StrictMock <IObserver>();

            if (expectUpdates)
            {
                inputObserver.Expect(o => o.UpdateObserver());
            }

            var calculationObserver = mockRepository.StrictMock <IObserver>();

            if (expectUpdates && hasOutput)
            {
                calculationObserver.Expect(o => o.UpdateObserver());
            }

            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            object assignedOutput = null;

            var calculation = new TestCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
                }
            };

            if (hasOutput)
            {
                assignedOutput = new object();
            }

            calculation.Output = assignedOutput;

            var row = new TestCalculationRow(calculation, handler);

            calculation.Attach(calculationObserver);
            calculation.InputParameters.Attach(inputObserver);

            // Call
            setProperty(row);

            // Assert
            assertions(calculation);
            if (expectUpdates)
            {
                Assert.IsNull(calculation.Output);
            }
            else
            {
                Assert.AreSame(assignedOutput, calculation.Output);
            }
        }
Esempio n. 18
0
 protected override TestCalculationRowWithColumnStateDefinitions CreateRow(TestCalculation calculation)
 {
     return(new TestCalculationRowWithColumnStateDefinitions(calculation,
                                                             new ObservablePropertyChangeHandler(calculation, calculation.InputParameters),
                                                             initialReadOnlyState));
 }