예제 #1
0
        public void ReadDikeProfileData_ValidFilePath4_ReturnDikeProfileData()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("DikeProfiles", "fileWithEmptyDikeAndForeshore.prfl"));

            const string profielId = "ikBenBestWaardeloos";
            var          reader    = new DikeProfileDataReader(new[]
            {
                profielId
            });

            // Call
            DikeProfileData result = reader.ReadDikeProfileData(validFilePath);

            // Assert
            Assert.AreEqual(profielId, result.Id);
            Assert.AreEqual(123.456, result.Orientation);
            Assert.AreEqual(DamType.None, result.DamType);
            Assert.AreEqual(SheetPileType.Coordinates, result.SheetPileType);
            Assert.AreEqual(0.0, result.DamHeight);
            CollectionAssert.IsEmpty(result.ForeshoreGeometry);
            Assert.AreEqual(6.0, result.DikeHeight);
            CollectionAssert.IsEmpty(result.DikeGeometry);
            string expectedMemo =
                "Verkenning prfl format:" + Environment.NewLine +
                "Basis:" + Environment.NewLine +
                "geen dam" + Environment.NewLine +
                "geen voorland" + Environment.NewLine +
                "geen dijk" + Environment.NewLine +
                "recht talud" + Environment.NewLine;

            Assert.AreEqual(expectedMemo, result.Memo);
        }
예제 #2
0
        public void ReadDikeProfileData_NoFilePath_ThrowArgumentException(string invalidFilePath)
        {
            // Setup
            var reader = new DikeProfileDataReader(new string[0]);

            // Call
            TestDelegate call = () => reader.ReadDikeProfileData(invalidFilePath);

            // Assert
            string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet leeg of ongedefinieerd zijn.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
        }
예제 #3
0
        public void ReadReferenceLine_FilePathIsActuallyDirectoryPath_ThrowArgumentException()
        {
            // Setup
            string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                Path.DirectorySeparatorChar.ToString());

            var reader = new DikeProfileDataReader(new string[0]);

            // Call
            TestDelegate call = () => reader.ReadDikeProfileData(invalidFilePath);

            // Assert
            string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet verwijzen naar een lege bestandsnaam.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
        }
예제 #4
0
        public void ReadDikeProfileData_ValidFilePath2_ReturnDikeProfileData()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("DikeProfiles", "profiel004.prfl"));

            const string profielId = "profiel004";
            var          reader    = new DikeProfileDataReader(new[]
            {
                profielId
            });

            // Call
            DikeProfileData result = reader.ReadDikeProfileData(validFilePath);

            // Assert
            Assert.AreEqual(profielId, result.Id);
            Assert.AreEqual(330.0, result.Orientation);
            Assert.AreEqual(DamType.None, result.DamType);
            Assert.AreEqual(SheetPileType.Coordinates, result.SheetPileType);
            Assert.AreEqual(0.5, result.DamHeight);
            Assert.AreEqual(3, result.ForeshoreGeometry.Length);
            Assert.AreEqual(new Point2D(-150.0, -9.0), result.ForeshoreGeometry[0].Point);
            Assert.AreEqual(1.0, result.ForeshoreGeometry[0].Roughness.Value);
            Assert.AreEqual(new Point2D(-100.0, -6.0), result.ForeshoreGeometry[1].Point);
            Assert.AreEqual(1.0, result.ForeshoreGeometry[1].Roughness.Value);
            Assert.AreEqual(new Point2D(-18.0, -6.0), result.ForeshoreGeometry[2].Point);
            Assert.AreEqual(1.0, result.ForeshoreGeometry[2].Roughness.Value);

            Assert.AreEqual(6.0, result.DikeHeight);
            Assert.AreEqual(4, result.DikeGeometry.Length);
            Assert.AreEqual(new Point2D(-18.0, -6.0), result.DikeGeometry[0].Point);
            Assert.AreEqual(1.0, result.DikeGeometry[0].Roughness.Value);
            Assert.AreEqual(new Point2D(-2.0, -0.1), result.DikeGeometry[1].Point);
            Assert.AreEqual(0.5, result.DikeGeometry[1].Roughness.Value);
            Assert.AreEqual(new Point2D(2.0, 0.1), result.DikeGeometry[2].Point);
            Assert.AreEqual(1.0, result.DikeGeometry[2].Roughness.Value);
            Assert.AreEqual(new Point2D(18.0, 6.0), result.DikeGeometry[3].Point);
            Assert.AreEqual(1.0, result.DikeGeometry[3].Roughness.Value);
            string expectedMemo =
                "Verkenning prfl format:" + Environment.NewLine +
                "geen dam" + Environment.NewLine +
                "voorland" + Environment.NewLine +
                "talud met (ruwe) berm" + Environment.NewLine;

            Assert.AreEqual(expectedMemo, result.Memo);
        }
예제 #5
0
        public void ReadReferenceLine_FilePathHasInvalidPathCharacter_ThrowArgumentException()
        {
            // Setup
            char[] invalidPathChars = Path.GetInvalidPathChars();

            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("DikeProfiles", "profiel001.prfl"));
            string invalidFilePath = validFilePath.Replace("-", invalidPathChars[3].ToString());

            var reader = new DikeProfileDataReader(new string[0]);

            // Call
            TestDelegate call = () => reader.ReadDikeProfileData(invalidFilePath);

            // Assert
            string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': "
                                     + "er zitten ongeldige tekens in het bestandspad. Alle tekens in het bestandspad moeten geldig zijn.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
        }
예제 #6
0
        private void ReadFileAndExpectCriticalFileReadException(string acceptedId, string fileName, string errorMessage)
        {
            // Setup
            string faultyFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                               Path.Combine("DikeProfiles", fileName));

            var reader = new DikeProfileDataReader(new[]
            {
                acceptedId
            });

            // Call
            TestDelegate call = () => reader.ReadDikeProfileData(faultyFilePath);

            // Assert
            string message         = Assert.Throws <CriticalFileReadException>(call).Message;
            string expectedMessage = $"Fout bij het lezen van bestand '{faultyFilePath}': {errorMessage}";

            Assert.AreEqual(expectedMessage, message);
        }
예제 #7
0
        public void ReadDikeProfileData_FileWithWrongId_ThrowsCriticalValidationException()
        {
            // Setup
            string faultyFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                               Path.Combine("DikeProfiles", "profiel001.prfl"));

            var reader = new DikeProfileDataReader(new[]
            {
                "SomeOtherId"
            });

            // Call
            TestDelegate call = () => reader.ReadDikeProfileData(faultyFilePath);

            // Assert
            string       message         = Assert.Throws <CriticalFileValidationException>(call).Message;
            const string expectedMessage = "De ingelezen ID ('profiel001') is ongeldig.";

            Assert.AreEqual(expectedMessage, message);
        }
예제 #8
0
        public void ReadDikeProfileData_ValidFilePath1_ReturnDikeProfileData(
            string validFileName)
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("DikeProfiles", validFileName));

            const string profielId = "profiel001";
            var          reader    = new DikeProfileDataReader(new[]
            {
                profielId
            });

            // Call
            DikeProfileData result = reader.ReadDikeProfileData(validFilePath);

            // Assert
            Assert.AreEqual(profielId, result.Id);
            Assert.AreEqual(330.0, result.Orientation);
            Assert.AreEqual(DamType.None, result.DamType);
            Assert.AreEqual(SheetPileType.Coordinates, result.SheetPileType);
            Assert.AreEqual(0.0, result.DamHeight);
            CollectionAssert.IsEmpty(result.ForeshoreGeometry);
            Assert.AreEqual(6.0, result.DikeHeight);
            Assert.AreEqual(2, result.DikeGeometry.Length);
            Assert.AreEqual(new Point2D(0.0, 0.0), result.DikeGeometry[0].Point);
            Assert.AreEqual(1.0, result.DikeGeometry[0].Roughness.Value);
            Assert.AreEqual(new Point2D(18.0, 6.0), result.DikeGeometry[1].Point);
            Assert.AreEqual(1.0, result.DikeGeometry[1].Roughness.Value);
            string expectedMemo =
                "Verkenning prfl format:" + Environment.NewLine +
                "Basis:" + Environment.NewLine +
                "geen dam" + Environment.NewLine +
                "geen voorland" + Environment.NewLine +
                "recht talud" + Environment.NewLine;

            Assert.AreEqual(expectedMemo, result.Memo);
        }
예제 #9
0
        private ReadResult <DikeProfileData> ReadDikeProfileData(string folderPath, string[] acceptedIds)
        {
            NotifyProgress(Resources.ProfilesImporter_ReadDikeProfileData_reading_profile_data, 1, 1);

            // No exception handling for GetFiles, as folderPath is derived from an existing, read file.
            string[] prflFilePaths = Directory.GetFiles(folderPath, "*.prfl");

            int totalNumberOfSteps = prflFilePaths.Length;

            var dikeProfileData       = new Collection <DikeProfileData>();
            var dikeProfileDataReader = new DikeProfileDataReader(acceptedIds);

            for (var i = 0; i < totalNumberOfSteps; i++)
            {
                if (Canceled)
                {
                    return(new ReadResult <DikeProfileData>(false));
                }

                string prflFilePath = prflFilePaths[i];

                try
                {
                    NotifyProgress(Resources.ProfilesImporter_ReadDikeProfileData_reading_profiledata, i + 1, totalNumberOfSteps);

                    DikeProfileData data = dikeProfileDataReader.ReadDikeProfileData(prflFilePath);

                    if (!DikeProfileDataIsValid(data, prflFilePath))
                    {
                        continue;
                    }

                    if (data.SheetPileType != SheetPileType.Coordinates)
                    {
                        Log.Error(string.Format(Resources.ProfilesImporter_ReadDikeProfileData_sheet_piling_not_zero_skipping_0_, prflFilePath));
                        continue;
                    }

                    if (dikeProfileData.Any(d => d.Id.Equals(data.Id)))
                    {
                        string errorMessage = string.Format(
                            Resources.ProfilesImporter_LogDuplicateDikeProfileData_Multiple_DikeProfileData_found_for_DikeProfile_0_File_1_skipped,
                            data.Id,
                            prflFilePath);
                        throw new CriticalFileReadException(errorMessage);
                    }

                    dikeProfileData.Add(data);
                }
                catch (CriticalFileReadException exception)
                {
                    Log.Error(exception.Message);
                    return(new ReadResult <DikeProfileData>(true));
                }
                catch (CriticalFileValidationException)
                {
                    // Ignore file
                }
            }

            return(new ReadResult <DikeProfileData>(false)
            {
                Items = dikeProfileData
            });
        }