public void Create_WaternetWithPhreaticLineAndHeadLinesAndWaternetLines_ReturnWaternetCalculatorResult()
        {
            // Setup
            var headLine = new HeadLine
            {
                Name   = "line 1",
                Points =
                {
                    new CSharpWrapperPoint2D(0, 0),
                    new CSharpWrapperPoint2D(1, 1)
                }
            };
            var phreaticLine = new HeadLine
            {
                Name   = "line 2",
                Points =
                {
                    new CSharpWrapperPoint2D(2, 2),
                    new CSharpWrapperPoint2D(3, 3)
                }
            };
            var referenceLine = new ReferenceLine
            {
                Name   = "line 3",
                Points =
                {
                    new CSharpWrapperPoint2D(4, 4),
                    new CSharpWrapperPoint2D(5, 5)
                },
                AssociatedHeadLine = headLine
            };

            var waternet = new Waternet
            {
                HeadLines =
                {
                    headLine
                },
                PhreaticLine   = phreaticLine,
                ReferenceLines =
                {
                    referenceLine
                }
            };

            // Call
            WaternetCalculatorResult result = WaternetCalculatorResultCreator.Create(waternet);

            // Assert
            WaternetCalculatorOutputAssert.AssertPhreaticLines(new[]
            {
                phreaticLine,
                headLine
            }, result.PhreaticLines.ToArray());

            WaternetCalculatorOutputAssert.AssertReferenceLines(new[]
            {
                referenceLine
            }, result.WaternetLines.ToArray());
        }
Exemple #2
0
        public void Import_InvalidCsvFile_LogAndFalse()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <ClosingStructure> >();

            mocks.ReplayAll();
            string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpIncompleteCsv",
                                           "Kunstwerken.shp");

            ReferenceLine referenceLine      = CreateReferenceLine();
            var           importTarget       = new StructureCollection <ClosingStructure>();
            var           structuresImporter = new ClosingStructuresImporter(importTarget, referenceLine,
                                                                             filePath, messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = structuresImporter.Import();

            // Assert
            string csvFilePath = Path.ChangeExtension(filePath, "csv");
            string message     = CreateExpectedErrorMessage(
                csvFilePath, "Coupure Den Oever (90k1)", "KUNST1",
                new[]
            {
                "De waarde voor parameter 'KW_BETSLUIT3' op regel 13, kolom 'Numeriekewaarde', moet in het bereik [0,0, 360,0] liggen.",
                "Parameter 'KW_BETSLUIT5' komt meerdere keren voor."
            });

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error), 1
                                                            );
            Assert.IsFalse(importResult);
            Assert.AreEqual(0, importTarget.Count);
            Assert.IsNull(importTarget.SourcePath);
        }
Exemple #3
0
        public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_True()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            ReferenceLine referenceLine        = CreateMatchingReferenceLine();
            var           testProfilesImporter = new TestProfilesImporter(new ObservableList <object>(), referenceLine, filePath, messageProvider);

            testProfilesImporter.SetProgressChanged((description, step, steps) => testProfilesImporter.Cancel());

            bool importResult = testProfilesImporter.Import();

            // Precondition
            Assert.IsFalse(importResult);
            testProfilesImporter.SetProgressChanged(null);

            // Call
            importResult = testProfilesImporter.Import();

            // Assert
            Assert.IsTrue(importResult);
        }
        public void Import_FileDoesNotExist_AbortImportWithErrorMessage()
        {
            // Setup
            var mocks            = new MockRepository();
            var failureMechanism = mocks.Stub <IFailureMechanism>();
            var updateStrategy   = mocks.StrictMock <IFailureMechanismSectionUpdateStrategy>();
            var messageProvider  = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetUpdateDataFailedLogMessageText(sectionsTypeDescriptor)).Return(expectedUpdateDataFailedText);
            mocks.ReplayAll();

            string referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                      Path.Combine("ReferenceLine", "traject_1-1.shp"));
            string sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, "I_dont_exist.shp");

            ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath);

            var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath, updateStrategy, messageProvider);

            // Call
            var importSuccessful = true;

            void Call() => importSuccessful = importer.Import();

            // Assert
            string expectedMessage = string.Format(
                expectedUpdateDataFailedText, $@"Fout bij het lezen van bestand '{sectionsFilePath}': het bestand bestaat niet.");

            TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage, 1);
            Assert.IsFalse(importSuccessful);
            mocks.VerifyAll();
        }
        public void Import_InvalidArtificialFileBecauseSomePointsNotOnReferenceLine_AbortImportWithErrorMessage()
        {
            // Setup
            var mocks            = new MockRepository();
            var failureMechanism = mocks.Stub <IFailureMechanism>();
            var updateStrategy   = mocks.StrictMock <IFailureMechanismSectionUpdateStrategy>();
            var messageProvider  = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetUpdateDataFailedLogMessageText(sectionsTypeDescriptor)).Return(expectedUpdateDataFailedText);
            mocks.ReplayAll();

            string referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                      Path.Combine("ReferenceLine", "Artificial_referencelijn_testA.shp"));
            string sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                 Path.Combine("FailureMechanismSections", "Artificial_referencelijn_testA_InvalidVakken_PointsTooFarFromReferenceLine.shp"));

            ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath);

            var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath, updateStrategy, messageProvider);

            // Call
            var importSuccessful = true;

            void Call() => importSuccessful = importer.Import();

            // Assert
            string expectedMessage = string.Format(expectedUpdateDataFailedText, "De opgetelde lengte van de vakken moet overeenkomen met de trajectlengte");

            TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage, 1);
            Assert.IsFalse(importSuccessful);
            mocks.VerifyAll();
        }
Exemple #6
0
        public void Import_LocationKWKIDENTNull_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("Structures", "StructuresWithNullKWKident", "Kunstwerken.shp"));

            ReferenceLine referenceLine          = CreateReferenceLine();
            var           testStructuresImporter = new TestStructuresImporter(new StructureCollection <TestStructure>(),
                                                                              referenceLine,
                                                                              filePath,
                                                                              updateStrategy,
                                                                              messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testStructuresImporter.Import();

            // Assert
            const string expectedMessages = "Fout bij het lezen van kunstwerk op regel 1. Het kunstwerk heeft geen geldige waarde voor attribuut 'KWKIDENT'.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessages, LogLevelConstant.Error), 1);
            Assert.IsFalse(importResult);
        }
Exemple #7
0
        public void GetSingleReferenceLineIntersection_SurfaceLineThroughReferenceLinePoint_ReturnIntersectionPoint()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            const string surfaceLineName = "somewhere";
            var          surfaceLine     = new SurfaceLine
            {
                Name = surfaceLineName
            };

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(3.0, 4.0, 2.1),
                new Point3D(3.0, 5.0, 2.1)
            });
            referenceLine.SetGeometry(new[]
            {
                new Point2D(2.0, 4.5),
                new Point2D(3.0, 4.5),
                new Point2D(4.0, 4.5)
            });

            // Call
            Point2D result = surfaceLine.GetSingleReferenceLineIntersection(referenceLine);

            // Assert
            Assert.AreEqual(new Point2D(3.0, 4.5), result);
        }
Exemple #8
0
        public void Import_DikeProfileLocationsNotCloseEnoughToReferenceLine_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            var referencePoints = new List <Point2D>
            {
                new Point2D(141223.2, 548393.4),
                new Point2D(143854.3, 545323.1),
                new Point2D(145561.0, 541920.3),
                new Point2D(146432.1, 538235.2),
                new Point2D(146039.4, 533920.2)
            };
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(referencePoints);
            var testProfilesImporter = new TestProfilesImporter(new ObservableList <object>(), referenceLine, filePath, messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testProfilesImporter.Import();

            // Assert
            const string expectedMessages = "Fout bij het lezen van profiellocatie 1. De profiellocatie met ID 'profiel001' ligt niet op de referentielijn.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessages, LogLevelConstant.Error), 1);
            Assert.IsFalse(importResult);
        }
Exemple #9
0
        public void Import_InvalidDamType_FalseAndLogMessage()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string testFileDirectory = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                  Path.Combine("DikeProfiles", "InvalidDamType"));
            string filePath = Path.Combine(testFileDirectory, "Voorlanden 12-2.shp");

            ReferenceLine referenceLine        = CreateMatchingReferenceLine();
            var           testProfilesImporter = new TestProfilesImporter(new ObservableList <object>(), referenceLine, filePath, messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testProfilesImporter.Import();

            // Assert
            string erroneousProfileFile = Path.Combine(testFileDirectory, "profiel005.prfl");
            string expectedMessage      = $"Fout bij het lezen van bestand '{erroneousProfileFile}' op regel 6: het ingelezen damtype ('4') moet 0, 1, 2 of 3 zijn.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1);
            Assert.IsFalse(importResult);
        }
Exemple #10
0
        public void Transform_SurfaceLineNotOnReferenceLine_ThrowsImportedDataTransformException()
        {
            // Setup
            var referenceLine = new ReferenceLine();
            var transformer   = new PipingSurfaceLineTransformer(referenceLine);

            const string surfaceLineName = "somewhere";
            var          surfaceLine     = new SurfaceLine
            {
                Name = surfaceLineName
            };

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(3.0, 4.0, 2.1),
                new Point3D(3.0, 5.0, 2.1)
            });
            referenceLine.SetGeometry(new[]
            {
                new Point2D(2.0, 4.0)
            });

            // Call
            TestDelegate test = () => transformer.Transform(surfaceLine, null);

            // Assert
            string message   = $"Profielschematisatie {surfaceLineName} doorkruist de huidige referentielijn niet of op meer dan één punt en kan niet worden geïmporteerd. Dit kan komen doordat de profielschematisatie een lokaal coördinaatsysteem heeft.";
            var    exception = Assert.Throws <ImportedDataTransformException>(test);

            Assert.AreEqual(message, exception.Message);
        }
Exemple #11
0
        private static ReferenceLine CreateReferenceLine(MapLineData lineMapData, string shapeFilePath)
        {
            MapFeature[] lineFeatures = lineMapData.Features.ToArray();

            if (lineFeatures.Length > 1)
            {
                string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                                 .Build(RiskeerCommonIOResources.ReferenceLineReader_File_contains_unsupported_multi_polyline);
                throw new CriticalFileReadException(message);
            }

            var        referenceLine        = new ReferenceLine();
            MapFeature referenceLineFeature = lineMapData.Features.First();

            MapGeometry[] referenceGeometries = referenceLineFeature.MapGeometries.ToArray();

            if (referenceGeometries.Length > 1)
            {
                string message = new FileReaderErrorMessageBuilder(shapeFilePath)
                                 .Build(RiskeerCommonIOResources.ReferenceLineReader_File_contains_unsupported_multi_polyline);
                throw new CriticalFileReadException(message);
            }

            MapGeometry referenceGeometry = referenceGeometries[0];

            referenceLine.SetGeometry(referenceGeometry.PointCollections.First().Select(t => new Point2D(t)).ToArray());
            return(referenceLine);
        }
Exemple #12
0
        public void Transform_WithoutCharacteristicPoints_ReturnsSurfaceLineWithoutCharacteristicPointsSet()
        {
            // Setup
            var referenceLine = new ReferenceLine();
            var transformer   = new PipingSurfaceLineTransformer(referenceLine);

            const string surfaceLineName = "somewhere";
            var          surfaceLine     = new SurfaceLine
            {
                Name = surfaceLineName
            };

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(1.0, 5.0, 2.1),
                new Point3D(1.0, 3.0, 2.1)
            });
            referenceLine.SetGeometry(new[]
            {
                new Point2D(0.0, 4.0),
                new Point2D(2.0, 4.0)
            });

            // Call
            PipingSurfaceLine result = transformer.Transform(surfaceLine, null);

            // Assert
            Assert.IsNull(result.DitchDikeSide);
            Assert.IsNull(result.BottomDitchDikeSide);
            Assert.IsNull(result.BottomDitchPolderSide);
            Assert.IsNull(result.DitchPolderSide);
            Assert.IsNull(result.DikeToeAtPolder);
            Assert.IsNull(result.DikeToeAtRiver);
        }
        public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_TrueAndLogMessagesAndFiveDikeProfiles()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            ReferenceLine referenceLine = CreateMatchingReferenceLine();

            var updateDataStrategy   = new TestDikeProfileUpdateStrategy();
            var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider);

            dikeProfilesImporter.SetProgressChanged((description, step, steps) => dikeProfilesImporter.Cancel());

            // Precondition
            bool importResult = dikeProfilesImporter.Import();

            Assert.IsFalse(importResult);
            CollectionAssert.IsEmpty(new DikeProfileCollection());

            dikeProfilesImporter.SetProgressChanged(null);

            // Call
            importResult = dikeProfilesImporter.Import();

            // Assert
            Assert.IsTrue(importResult);
            Assert.IsTrue(updateDataStrategy.Updated);
            Assert.AreEqual(5, updateDataStrategy.ReadDikeProfiles.Length);
        }
        public void Import_FromFileWithUnmatchableId_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "IpflWithUnmatchableId", "Voorlanden_12-2_UnmatchableId.shp"));

            ReferenceLine referenceLine        = CreateMatchingReferenceLine();
            var           dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(),
                                                                          referenceLine, filePath,
                                                                          new TestDikeProfileUpdateStrategy(), messageProvider);
            var importResult = false;

            // Call
            Action call = () => importResult = dikeProfilesImporter.Import();

            // Assert
            const string expectedMessage = "Kan geen geldige gegevens vinden voor dijkprofiellocatie met ID 'unmatchable'.";
            Tuple <string, LogLevelConstant> expectedLogMessage = Tuple.Create(expectedMessage, LogLevelConstant.Error);

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1);
            Assert.IsFalse(importResult);
        }
Exemple #15
0
        public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_ReturnsTrue()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp"));

            ReferenceLine referenceLine          = CreateReferenceLine();
            var           importTarget           = new StructureCollection <TestStructure>();
            var           testStructuresImporter = new TestStructuresImporter(importTarget,
                                                                              referenceLine,
                                                                              filePath,
                                                                              updateStrategy,
                                                                              messageProvider);

            testStructuresImporter.SetProgressChanged((description, step, steps) => testStructuresImporter.Cancel());

            bool importResult = testStructuresImporter.Import();

            // Precondition
            Assert.IsFalse(importResult);
            testStructuresImporter.SetProgressChanged(null);

            // Call
            importResult = testStructuresImporter.Import();

            // Assert
            Assert.IsTrue(importResult);
        }
Exemple #16
0
        public void Import_TwoPrflWithSameId_FalseAndErrorLog()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string testFileDirectory = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                  Path.Combine("DikeProfiles", "TwoPrflWithSameId"));
            string filePath = Path.Combine(testFileDirectory, "profiel001.shp");

            var referencePoints = new List <Point2D>
            {
                new Point2D(130074.3, 543717.4),
                new Point2D(130084.3, 543727.4)
            };
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(referencePoints);
            var testProfilesImporter = new TestProfilesImporter(new ObservableList <object>(), referenceLine, filePath, messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testProfilesImporter.Import();

            // Assert
            string erroneousProfileFile = Path.Combine(testFileDirectory, "profiel001_2.prfl");
            string expectedMessage      = $"Meerdere definities gevonden voor profiel 'profiel001'. Bestand '{erroneousProfileFile}' wordt overgeslagen.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1);
            Assert.IsFalse(importResult);
        }
Exemple #17
0
        public void Import_DuplicateLocation_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("Structures", "DuplicateLocation", "Kunstwerken.shp"));

            ReferenceLine referenceLine          = CreateReferenceLine();
            var           testStructuresImporter = new TestStructuresImporter(new StructureCollection <TestStructure>(),
                                                                              referenceLine,
                                                                              filePath,
                                                                              updateStrategy,
                                                                              messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testStructuresImporter.Import();

            // Assert
            const string expectedMessage = "Kunstwerklocatie met KWKIDENT 'KUNST3' is opnieuw ingelezen.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1);
            Assert.IsFalse(importResult);
        }
Exemple #18
0
        public void Import_PrflWithProfileNotZero_FalseAndErrorLog()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "PrflWithProfileNotZero", "Voorland_12-2.shp"));

            ReferenceLine referenceLine        = CreateMatchingReferenceLine();
            var           testProfilesImporter = new TestProfilesImporter(new ObservableList <object>(), referenceLine, filePath, messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testProfilesImporter.Import();

            // Assert
            Action <IEnumerable <string> > asserts = messages =>
            {
                bool found = messages.Any(message => message.StartsWith("Profielgegevens definiëren een damwand waarde ongelijk aan 0. Bestand wordt overgeslagen:"));
                Assert.IsTrue(found);
            };

            TestHelper.AssertLogMessages(call, asserts);
            Assert.IsTrue(importResult);
        }
Exemple #19
0
        public void GetSingleReferenceLineIntersection_SurfaceLineIntersectsReferenceLineMultipleTimesInDifferentPoints_ThrowImportedDataTransformException()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            const string surfaceLineName = "somewhere";
            var          surfaceLine     = new SurfaceLine
            {
                Name = surfaceLineName
            };

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(1.0, 5.0, 2.1),
                new Point3D(1.0, 3.0, 2.1)
            });
            referenceLine.SetGeometry(new[]
            {
                new Point2D(0.0, 5.0),
                new Point2D(2.0, 4.0),
                new Point2D(0.0, 3.0)
            });

            // Call
            TestDelegate test = () => surfaceLine.GetSingleReferenceLineIntersection(referenceLine);

            // Assert
            string message   = $"Profielschematisatie {surfaceLineName} doorkruist de huidige referentielijn niet of op meer dan één punt en kan niet worden geïmporteerd.";
            var    exception = Assert.Throws <ImportedDataTransformException>(test);

            Assert.AreEqual(message, exception.Message);
        }
Exemple #20
0
        public void Import_PrflIsIncomplete_FalseAndErrorLog()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "PrflIsIncomplete", "Voorland_12-2.shp"));

            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(130074.3, 543717.4),
                new Point2D(130084.3, 543727.4)
            });
            var testProfilesImporter = new TestProfilesImporter(new ObservableList <object>(), referenceLine, filePath, messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = testProfilesImporter.Import();

            // Assert
            Action <IEnumerable <string> > asserts = messages =>
            {
                bool found = messages.First().Contains(": de volgende parameters zijn niet aanwezig in het bestand: VOORLAND, DAMWAND, KRUINHOOGTE, DIJK, MEMO");
                Assert.IsTrue(found);
            };

            TestHelper.AssertLogMessages(call, asserts);
            Assert.IsFalse(importResult);
        }
 private static WaternetLineResult CreateWaternetLineResult(ReferenceLine waternetLine,
                                                            IDictionary <HeadLine, WaternetPhreaticLineResult> phreaticLines)
 {
     return(new WaternetLineResult(waternetLine.Name,
                                   waternetLine.Points.Select(p => new Point2D(p.X, p.Z)).ToArray(),
                                   phreaticLines[waternetLine.AssociatedHeadLine]));
 }
Exemple #22
0
        public void Import_CancelOfImportWhileReadingDikeProfileLocations_ReturnsFalse()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            ReferenceLine referenceLine        = CreateMatchingReferenceLine();
            var           testProfilesImporter = new TestProfilesImporter(testImportTarget, referenceLine, filePath, messageProvider);

            testProfilesImporter.SetProgressChanged((description, step, steps) =>
            {
                if (description.Contains("Inlezen van profielgegevens uit een prfl bestand."))
                {
                    testProfilesImporter.Cancel();
                }
            });

            // Call
            bool importResult = testProfilesImporter.Import();

            // Assert
            Assert.IsFalse(importResult);
        }
        public void Import_InvalidArtificialFileBecauseUnchainedSections_AbortImportWithErrorMessage()
        {
            // Setup
            var mocks            = new MockRepository();
            var failureMechanism = mocks.Stub <IFailureMechanism>();
            var updateStrategy   = mocks.StrictMock <IFailureMechanismSectionUpdateStrategy>();
            var messageProvider  = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetUpdateDataFailedLogMessageText(sectionsTypeDescriptor)).Return(expectedUpdateDataFailedText);
            mocks.ReplayAll();

            string referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                      Path.Combine("ReferenceLine", "Artificial_referencelijn_testA.shp"));
            string sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                 Path.Combine("FailureMechanismSections", "Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.shp"));

            ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath);

            var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath, updateStrategy, messageProvider);

            // Call
            var importSuccessful = true;

            void Call() => importSuccessful = importer.Import();

            // Assert
            string expectedMessage = string.Format(expectedUpdateDataFailedText, "Het bestand moet vakken bevatten die allen op elkaar aansluiten");

            TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage, 1);
            Assert.IsFalse(importSuccessful);
            mocks.VerifyAll();
        }
Exemple #24
0
        public void Import_CancelOfImportWhileCreateProfiles_ContinueImportAndLogWarning()
        {
            // Setup
            const string addingDataToModel = "Adding Data to Model";
            var          messageProvider   = mocks.Stub <IImporterMessageProvider>();

            messageProvider.Stub(mp => mp.GetAddDataToModelProgressText()).Return(addingDataToModel);
            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            ReferenceLine referenceLine        = CreateMatchingReferenceLine();
            var           testProfilesImporter = new TestProfilesImporter(testImportTarget, referenceLine, filePath, messageProvider);

            testProfilesImporter.SetProgressChanged((description, step, steps) =>
            {
                if (description.Contains(addingDataToModel))
                {
                    testProfilesImporter.Cancel();
                }
            });

            var importResult = false;

            // Call
            Action call = () => importResult = testProfilesImporter.Import();

            // Assert
            const string expectedMessage = "Huidige actie was niet meer te annuleren en is daarom voortgezet.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Warn), 2);
            Assert.IsTrue(importResult);
        }
Exemple #25
0
        public void Import_ValidIncompleteFile_LogAndFalse()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <ClosingStructure> >();

            mocks.ReplayAll();

            string filePath = Path.Combine(commonIoTestDataPath, "CorrectFiles", "Kunstwerken.shp");

            ReferenceLine referenceLine = CreateReferenceLine();
            var           importTarget  = new StructureCollection <ClosingStructure>();
            var           importer      = new ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                                        messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.Import();

            // Assert
            string csvFilePath = Path.ChangeExtension(filePath, "csv");
            string message     = CreateExpectedErrorMessage(csvFilePath, "Gemaal Leemans (93k3)", "KUNST2", new[]
            {
                "Geen geldige parameter definities gevonden."
            });

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error));
            Assert.IsFalse(importResult);
            Assert.AreEqual(0, importTarget.Count);
            Assert.IsNull(importTarget.SourcePath);
        }
Exemple #26
0
        public void Import_AddingDataToModel_SetsProgressText()
        {
            // Setup
            const string expectedProgressText = "Adding Data to model";
            var          messageProvider      = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedProgressText);
            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            ReferenceLine referenceLine        = CreateMatchingReferenceLine();
            var           testProfilesImporter = new TestProfilesImporter(new ObservableList <object>(), referenceLine, filePath, messageProvider);

            var callcount = 0;

            testProfilesImporter.SetProgressChanged((description, step, steps) =>
            {
                if (callcount == 12)
                {
                    Assert.AreEqual(expectedProgressText, description);
                }

                callcount++;
            });

            // Call
            testProfilesImporter.Import();

            // Assert
            // Assert done in TearDown
        }
Exemple #27
0
        /// <summary>
        /// Initializes a new instance of <see cref="ProfilesImporter{T}"/>.
        /// </summary>
        /// <param name="referenceLine">The reference line used to check if the imported profiles are intersecting it.</param>
        /// <param name="filePath">The path to the file to import from.</param>
        /// <param name="importTarget">The import target.</param>
        /// <param name="messageProvider">The message provider to provide messages during the import.</param>
        /// <param name="typeDescriptor">The description of the profiles that are imported.</param>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        protected ProfilesImporter(ReferenceLine referenceLine,
                                   string filePath,
                                   T importTarget,
                                   IImporterMessageProvider messageProvider,
                                   string typeDescriptor) : base(filePath, importTarget)
        {
            if (referenceLine == null)
            {
                throw new ArgumentNullException(nameof(referenceLine));
            }

            if (messageProvider == null)
            {
                throw new ArgumentNullException(nameof(messageProvider));
            }

            if (typeDescriptor == null)
            {
                throw new ArgumentNullException(nameof(typeDescriptor));
            }

            this.referenceLine  = referenceLine;
            this.typeDescriptor = typeDescriptor;
            MessageProvider     = messageProvider;
        }
Exemple #28
0
        public void GetFailureMechanismSectionGeometry_SectionStartAndEndExactlyOnReferenceLinePoints_ReturnExpectedPoints()
        {
            // Setup
            const int sectionStart = 10;
            const int sectionEnd   = 30;
            var       points       = new[]
            {
                new Point2D(0, 0),
                new Point2D(sectionStart, 0),
                new Point2D(20, 0),
                new Point2D(sectionEnd, 0)
            };

            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(points);

            // Call
            IEnumerable <Point2D> sectionPoints = FailureMechanismSectionHelper.GetFailureMechanismSectionGeometry(referenceLine, sectionStart, sectionEnd);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                new Point2D(sectionStart, 0),
                new Point2D(20, 0),
                new Point2D(sectionEnd, 0)
            }, sectionPoints);
        }
        public void Import_FromFileWithUnmatchableId_FalseAndLogError()
        {
            // Setup
            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "IpflWithUnmatchableId", "Voorlanden_12-2_UnmatchableId.shp"));

            ReferenceLine referenceLine = CreateMatchingReferenceLine();

            var foreshoreProfiles = new ForeshoreProfileCollection();

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

            assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine);
            var messageProvider = mockRepository.Stub <IImporterMessageProvider>();
            var strategy        = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>();

            mockRepository.ReplayAll();

            var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider);

            // Call
            var    importResult = true;
            Action call         = () => importResult = foreshoreProfilesImporter.Import();

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string[] messageArray        = messages.ToArray();
                const string expectedMessage = "Kan geen geldige gegevens vinden voor voorlandprofiellocatie met ID 'unmatchable'.";
                Assert.AreEqual(expectedMessage, messageArray[0]);
            });
            Assert.IsFalse(importResult);
        }
Exemple #30
0
        private IEnumerable <ReferenceLine> GetAllReferenceLines(DicomImagePlane targetImagePlane)
        {
            ReferenceLine firstReferenceLine = null;
            ReferenceLine lastReferenceLine  = null;

            if (ShowFirstAndLastReferenceLines)
            {
                GetFirstAndLastReferenceLines(targetImagePlane, out firstReferenceLine, out lastReferenceLine);
            }

            if (firstReferenceLine != null)
            {
                yield return(firstReferenceLine);
            }

            if (lastReferenceLine != null)
            {
                yield return(lastReferenceLine);
            }

            //return 'current' last, so it draws on top of the others.
            ReferenceLine currentReferenceLine = GetReferenceLine(_currentReferenceImagePlane, targetImagePlane);

            if (currentReferenceLine != null)
            {
                yield return(currentReferenceLine);
            }
        }
		private void GetFirstAndLastReferenceLines(DicomImagePlane targetImagePlane, out ReferenceLine firstReferenceLine, out ReferenceLine lastReferenceLine)
		{
			firstReferenceLine = lastReferenceLine = null;

			float firstReferenceImageZComponent = float.MaxValue;
			float lastReferenceImageZComponent = float.MinValue;

			// 1. Find all images in the same plane as the current reference image.
			foreach (DicomImagePlane parallelPlane in GetPlanesParallelToReferencePlane())
			{
				// 2. Use the Image Position (in the coordinate system of the Image Plane without moving the origin!) 
				//    to determine the first and last reference line.  By transforming the Image Position (Patient) to 
				//    the coordinate system of the image plane, we can then simply take the 2 images with
				//    the smallest and largest z-components, respectively, as the 'first' and 'last' reference images.

				// < keeps the first image as close to the beginning of the display set as possible.
				if (parallelPlane.PositionImagePlaneTopLeft.Z < firstReferenceImageZComponent)
				{
					ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
					if (referenceLine != null)
					{
						firstReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
						firstReferenceLine = referenceLine;
					}
				}

				// >= keeps the last image as close to the end of the display set as possible.
				if (parallelPlane.PositionImagePlaneTopLeft.Z >= lastReferenceImageZComponent)
				{
					ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
					if (referenceLine != null)
					{
						lastReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
						lastReferenceLine = referenceLine;
					}
				}
			}
		}