Beispiel #1
0
        public void GivenAssessmentSectionWithReferenceLineAndOtherData_WhenImportingReferenceLine_ThenReferenceLineGeometryReplacedAndReferenceLineDependentDataCleared()
        {
            // Given
            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);

            var mocks                    = new MockRepository();
            var viewCommands             = mocks.Stub <IViewCommands>();
            var failureMechanismObserver = mocks.StrictMock <IObserver>();

            failureMechanismObserver.Expect(o => o.UpdateObserver())
            .Repeat.Times(assessmentSection.GetFailureMechanisms().Count());
            var referenceLineObserver = mocks.StrictMock <IObserver>();

            referenceLineObserver.Expect(o => o.UpdateObserver());
            var surfaceLinesObserver = mocks.StrictMock <IObserver>();

            surfaceLinesObserver.Expect(o => o.UpdateObserver());
            var stochasticSoilModelsObserver = mocks.StrictMock <IObserver>();

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

            DataImportHelper.ImportReferenceLine(assessmentSection);
            DataImportHelper.ImportFailureMechanismSections(assessmentSection, assessmentSection.GetFailureMechanisms()
                                                            .Cast <IFailureMechanism <FailureMechanismSectionResult> >());
            DataImportHelper.ImportPipingSurfaceLines(assessmentSection);
            DataImportHelper.ImportPipingStochasticSoilModels(assessmentSection);

            ReferenceLine originalReferenceLine = assessmentSection.ReferenceLine;

            Point2D[] originalReferenceLineGeometry = originalReferenceLine.Points.ToArray();

            var    handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands);
            string path    = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                        Path.Combine("ReferenceLine", "traject_10-2.shp"));

            var importer = new ReferenceLineImporter(assessmentSection.ReferenceLine, handler, path);

            string messageBoxTitle = null, messageBoxText = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var messageBoxTester = new MessageBoxTester(wnd);

                messageBoxTitle = messageBoxTester.Title;
                messageBoxText  = messageBoxTester.Text;

                messageBoxTester.ClickOk();
            };

            assessmentSection.ReferenceLine.Attach(referenceLineObserver);
            foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms())
            {
                failureMechanism.Attach(failureMechanismObserver);
            }

            assessmentSection.Piping.StochasticSoilModels.Attach(stochasticSoilModelsObserver);
            assessmentSection.Piping.SurfaceLines.Attach(surfaceLinesObserver);

            // When
            bool importSuccessful = importer.Import();

            importer.DoPostImport();

            // Then
            Assert.IsTrue(importSuccessful);
            Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine);
            CollectionAssert.AreNotEqual(originalReferenceLineGeometry, assessmentSection.ReferenceLine.Points);
            Point2D[] point2Ds = assessmentSection.ReferenceLine.Points.ToArray();
            Assert.AreEqual(803, point2Ds.Length);
            Assert.AreEqual(198237.375, point2Ds[123].X, 1e-6);
            Assert.AreEqual(514879.781, point2Ds[123].Y, 1e-6);

            foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms())
            {
                CollectionAssert.IsEmpty(failureMechanism.Sections);
            }

            CollectionAssert.IsEmpty(assessmentSection.Piping.SurfaceLines);
            CollectionAssert.IsEmpty(assessmentSection.Piping.StochasticSoilModels);
            CollectionAssert.IsEmpty(assessmentSection.Piping.CalculationsGroup.Children);

            Assert.AreEqual("Bevestigen", messageBoxTitle);
            string expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van alle faalmechanismen worden gewist." + Environment.NewLine +
                                  Environment.NewLine + "Wilt u doorgaan?";

            Assert.AreEqual(expectedText, messageBoxText);

            mocks.VerifyAll();
        }