public void Data_UseForeshoreFalse_SetEmptyForeshoreDataOnChart()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                DikeProfile dikeProfile = GetDikeProfileWithGeometry();
                var         calculation = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile  = dikeProfile,
                        UseForeshore = false
                    }
                };

                // Call
                view.Data = calculation;

                // Assert
                Assert.AreSame(calculation, view.Data);

                ChartDataCollection chartData = view.Chart.Data;
                Assert.IsInstanceOf <ChartDataCollection>(chartData);
                Assert.AreEqual(3, chartData.Collection.Count());

                var dikeGeometryData = (ChartLineData)chartData.Collection.ElementAt(dikeProfileIndex);
                var foreshoreData    = (ChartLineData)chartData.Collection.ElementAt(foreshoreIndex);
                var dikeHeightData   = (ChartLineData)chartData.Collection.ElementAt(dikeHeightIndex);

                CollectionAssert.IsEmpty(foreshoreData.Points);
                Assert.AreEqual("Voorlandprofiel", foreshoreData.Name);
                AssertDikeProfileChartData(dikeProfile, dikeGeometryData);
                AssertDikeHeightChartData(dikeProfile, dikeHeightData);
            }
        }
        public void UpdateObserver_PreviousCalculationNameUpdated_ChartTitleNotUpdated()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                const string initialName = "Initial name";
                const string updatedName = "Updated name";

                var calculation = new GrassCoverErosionInwardsCalculation
                {
                    Name = initialName
                };

                view.Data = calculation;

                // Precondition
                Assert.AreEqual(initialName, view.Chart.ChartTitle);

                view.Data = new GrassCoverErosionInwardsCalculation
                {
                    Name = initialName
                };

                calculation.Name = updatedName;

                // Call
                calculation.NotifyObservers();

                // Assert
                Assert.AreEqual(initialName, view.Chart.ChartTitle);
            }
        }
        public void Data_SetChartData_ChartDataSet()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                DikeProfile dikeProfile = GetDikeProfileWithGeometry();
                var         calculation = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile = dikeProfile
                    }
                };

                // Call
                view.Data = calculation;

                // Assert
                Assert.AreSame(calculation, view.Data);

                ChartDataCollection chartData = view.Chart.Data;
                Assert.IsInstanceOf <ChartDataCollection>(chartData);
                Assert.AreEqual(3, chartData.Collection.Count());
                AssertDikeProfileChartData(dikeProfile, chartData.Collection.ElementAt(dikeProfileIndex));
                AssertForeshoreChartData(dikeProfile, chartData.Collection.ElementAt(foreshoreIndex));
                AssertDikeHeightChartData(dikeProfile, chartData.Collection.ElementAt(dikeHeightIndex));
            }
        }
        public void NotifyObservers_DataUpdatedNotifyObserversOnOldData_NoUpdateInViewData()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                DikeProfile dikeProfile  = GetDikeProfileWithGeometry();
                var         calculation1 = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile = dikeProfile
                    }
                };

                var calculation2 = new GrassCoverErosionInwardsCalculation();

                view.Data = calculation1;
                ChartData dataBeforeUpdate = view.Chart.Data;

                view.Data = calculation2;

                DikeProfile dikeProfile2 = GetSecondDikeProfileWithGeometry();

                calculation1.InputParameters.DikeProfile = dikeProfile2;

                // Call
                calculation1.InputParameters.NotifyObservers();

                // Assert
                Assert.AreEqual(dataBeforeUpdate, view.Chart.Data);
            }
        }
Пример #5
0
        public void CloseForData_ViewCorrespondingToRemovedCalculationContext_ReturnsTrue()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculation        = new GrassCoverErosionInwardsCalculationScenario();
            var calculationContext = new GrassCoverErosionInwardsCalculationScenarioContext(calculation,
                                                                                            new CalculationGroup(),
                                                                                            new GrassCoverErosionInwardsFailureMechanism(),
                                                                                            assessmentSection);

            using (var view = new GrassCoverErosionInwardsInputView
            {
                Data = calculation
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, calculationContext);

                // Assert
                Assert.IsTrue(closeForData);
                mocks.VerifyAll();
            }
        }
Пример #6
0
        public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculation      = new GrassCoverErosionInwardsCalculation();
            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(calculation);

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);

            var context = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection);

            using (var view = new GrassCoverErosionInwardsInputView
            {
                Data = calculation
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, context);

                // Assert
                Assert.IsTrue(closeForData);
                mocks.VerifyAll();
            }
        }
Пример #7
0
        public void CloseForData_NestedViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse()
        {
            // Setup
            var calculation      = new GrassCoverErosionInwardsCalculation();
            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(calculation);

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);

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

            assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[]
            {
                failureMechanism
            });

            mocks.ReplayAll();

            using (var view = new GrassCoverErosionInwardsInputView
            {
                Data = new GrassCoverErosionInwardsCalculation()
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
                mocks.VerifyAll();
            }
        }
Пример #8
0
        public void CloseForData_NestedViewNotCorrespondingWithRemovedParentCalculationGroupContext_ReturnsFalse()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculation      = new GrassCoverErosionInwardsCalculation();
            var calculationGroup = new CalculationGroup();
            var nestedGroup      = new CalculationGroup();

            nestedGroup.Children.Add(calculation);
            calculationGroup.Children.Add(nestedGroup);

            var calculationGroupContext = new GrassCoverErosionInwardsCalculationGroupContext(new CalculationGroup(),
                                                                                              null,
                                                                                              new GrassCoverErosionInwardsFailureMechanism(),
                                                                                              assessmentSection);

            using (var view = new GrassCoverErosionInwardsInputView
            {
                Data = calculation
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, calculationGroupContext);

                // Assert
                Assert.IsFalse(closeForData);
                mocks.VerifyAll();
            }
        }
 public void DefaultConstructor_DefaultValues()
 {
     // Call
     using (var view = new GrassCoverErosionInwardsInputView())
     {
         // Assert
         Assert.IsInstanceOf <UserControl>(view);
         Assert.IsInstanceOf <IChartView>(view);
         Assert.IsNotNull(view.Chart);
         Assert.IsNull(view.Data);
     }
 }
        public void Data_OtherThanGrassCoverErosionInwardsCalculations_DataNull()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                var calculation = new object();

                // Call
                view.Data = calculation;

                // Assert
                Assert.IsNull(view.Data);
            }
        }
        public void Data_GrassCoverErosionInwardsCalculation_DataSet()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                var calculation = new GrassCoverErosionInwardsCalculation();

                // Call
                view.Data = calculation;

                // Assert
                Assert.AreSame(calculation, view.Data);
            }
        }
 public void DefaultConstructor_Always_AddEmptyChartControl()
 {
     // Call
     using (var view = new GrassCoverErosionInwardsInputView())
     {
         // Assert
         Assert.AreEqual(1, view.Controls.Count);
         Assert.AreSame(view.Chart, view.Controls[0]);
         Assert.AreEqual(DockStyle.Fill, ((Control)view.Chart).Dock);
         Assert.AreEqual("Afstand [m]", view.Chart.BottomAxisTitle);
         Assert.AreEqual("Hoogte [m+NAP]", view.Chart.LeftAxisTitle);
         Assert.IsNull(view.Chart.Data);
     }
 }
        public void Data_EmptyGrassCoverErosionInwardsCalculation_NoChartDataSet()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                var calculation = new GrassCoverErosionInwardsCalculation();

                // Call
                view.Data = calculation;

                // Assert
                AssertEmptyChartData(view.Chart.Data);
            }
        }
        public void UpdateObserver_CalculationDikeProfileUpdated_SetNewChartData()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            using (var view = new GrassCoverErosionInwardsInputView())
            {
                DikeProfile dikeProfile = GetDikeProfileWithGeometry();

                var calculation = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile = dikeProfile
                    }
                };

                view.Data = calculation;

                var dikeProfileChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(dikeProfileIndex);
                var foreshoreChartData   = (ChartLineData)view.Chart.Data.Collection.ElementAt(foreshoreIndex);
                var dikeHeightChartData  = (ChartLineData)view.Chart.Data.Collection.ElementAt(dikeHeightIndex);

                dikeProfileChartData.Attach(observer);
                foreshoreChartData.Attach(observer);
                dikeHeightChartData.Attach(observer);

                DikeProfile dikeProfile2 = GetSecondDikeProfileWithGeometry();

                calculation.InputParameters.DikeProfile = dikeProfile2;

                // Call
                calculation.InputParameters.NotifyObservers();

                // Assert
                Assert.AreSame(dikeProfileChartData, (ChartLineData)view.Chart.Data.Collection.ElementAt(dikeProfileIndex));
                AssertDikeProfileChartData(dikeProfile2, dikeProfileChartData);
                Assert.AreSame(foreshoreChartData, (ChartLineData)view.Chart.Data.Collection.ElementAt(foreshoreIndex));
                AssertForeshoreChartData(dikeProfile2, foreshoreChartData);
                Assert.AreSame(dikeHeightChartData, (ChartLineData)view.Chart.Data.Collection.ElementAt(dikeHeightIndex));
                AssertDikeHeightChartData(dikeProfile2, dikeHeightChartData);
                mocks.VerifyAll();
            }
        }
        public void UpdateObserver_DataUpdated_ChartSeriesOrderSame()
        {
            // Setup
            const int updatedDikeProfileIndex = dikeProfileIndex + 1;
            const int updatedForeshoreIndex   = foreshoreIndex;
            const int updatedDikeHeightIndex  = dikeHeightIndex - 1;

            var calculation = new GrassCoverErosionInwardsCalculation();

            using (var view = new GrassCoverErosionInwardsInputView
            {
                Data = calculation
            })
            {
                var dataToMove = (ChartLineData)view.Chart.Data.Collection.ElementAt(dikeProfileIndex);
                view.Chart.Data.Remove(dataToMove);
                view.Chart.Data.Add(dataToMove);

                // Precondition
                var dikeProfileChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(updatedDikeProfileIndex);
                Assert.AreEqual("Dijkprofiel", dikeProfileChartData.Name);

                var foreshoreChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(updatedForeshoreIndex);
                Assert.AreEqual("Voorlandprofiel", foreshoreChartData.Name);

                var dikeHeightChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(updatedDikeHeightIndex);
                Assert.AreEqual("Dijkhoogte", dikeHeightChartData.Name);

                DikeProfile dikeProfile = GetDikeProfileWithGeometry();
                calculation.InputParameters.DikeProfile = dikeProfile;

                // Call
                calculation.InputParameters.NotifyObservers();

                // Assert
                var    actualDikeProfileChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(updatedDikeProfileIndex);
                string expectedDikeProfileName    = $"{dikeProfile.Name} - Dijkprofiel";
                Assert.AreEqual(expectedDikeProfileName, actualDikeProfileChartData.Name);

                var    actualForeshoreChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(updatedForeshoreIndex);
                string expectedForeshoreName    = $"{dikeProfile.Name} - Voorlandprofiel";
                Assert.AreEqual(expectedForeshoreName, actualForeshoreChartData.Name);

                var actualDikeHeightChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(updatedDikeHeightIndex);
                Assert.AreEqual("Dijkhoogte", actualDikeHeightChartData.Name);
            }
        }
        public void UpdateObserver_PreviousGrassCoverErosionInwardsCalculationUpdated_ChartDataNotUpdated()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            mocks.ReplayAll();

            using (var view = new GrassCoverErosionInwardsInputView())
            {
                var calculation = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile = GetDikeProfileWithGeometry()
                    }
                };

                view.Data = calculation;

                var dikeProfileChartData = (ChartLineData)view.Chart.Data.Collection.ElementAt(dikeProfileIndex);
                var foreshoreChartData   = (ChartLineData)view.Chart.Data.Collection.ElementAt(foreshoreIndex);
                var dikeHeightChartData  = (ChartLineData)view.Chart.Data.Collection.ElementAt(dikeHeightIndex);

                dikeProfileChartData.Attach(observer);
                foreshoreChartData.Attach(observer);
                dikeHeightChartData.Attach(observer);

                view.Data = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile = GetDikeProfileWithGeometry()
                    }
                };

                calculation.InputParameters.DikeProfile = GetSecondDikeProfileWithGeometry();

                // Call
                calculation.InputParameters.NotifyObservers();

                // Assert
                mocks.VerifyAll(); // No update observer expected
            }
        }
        public void Data_SetToNull_ChartDataCleared()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView
            {
                Data = new GrassCoverErosionInwardsCalculation()
            })
            {
                // Precondition
                Assert.AreEqual(3, view.Chart.Data.Collection.Count());
                Assert.AreEqual("Nieuwe berekening", view.Chart.ChartTitle);

                // Call
                view.Data = null;

                // Assert
                Assert.IsNull(view.Data);
                Assert.IsNull(view.Chart.Data);
                Assert.IsEmpty(view.Chart.ChartTitle);
            }
        }