Example #1
0
        private ReadResult <FailureMechanismSection> ReadFile(FailureMechanismSectionReader reader)
        {
            try
            {
                int count = reader.GetFailureMechanismSectionCount();
                if (count == 0)
                {
                    LogCriticalError(Resources.FailureMechanismSectionsImporter_ReadFile_File_is_empty);
                    return(new ReadResult <FailureMechanismSection>(true));
                }

                var importedSections = new FailureMechanismSection[count];
                for (var i = 0; i < count; i++)
                {
                    importedSections[i] = reader.ReadFailureMechanismSection();
                }

                return(new ReadResult <FailureMechanismSection>(false)
                {
                    Items = importedSections
                });
            }
            catch (CriticalFileReadException e)
            {
                Log.Error(e.Message);
                return(new ReadResult <FailureMechanismSection>(true));
            }
        }
Example #2
0
        private ReadResult <FailureMechanismSection> ReadFailureMechanismSections()
        {
            using (FailureMechanismSectionReader reader = CreateFileReader())
            {
                if (reader == null)
                {
                    return(new ReadResult <FailureMechanismSection>(true));
                }

                return(ReadFile(reader));
            }
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", "traject_1-1_vakken.shp"));

            // Call
            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                // Assert
                Assert.IsInstanceOf <IDisposable>(reader);
            }
        }
        public void GetFailureMechanismSectionCount_ValidFilePath_ReturnElementCount(string shapeFileName, int expectedElementCount)
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", shapeFileName));

            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                // Call
                int count = reader.GetFailureMechanismSectionCount();

                // Assert
                Assert.AreEqual(expectedElementCount, count);
            }
        }
        public void ReadFailureMechanismSection_FileLacksNameAttribute_ThrowCriticalFileReadException()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", "traject_227_vakken_LacksVaknaamAttribute.shp"));

            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                // Call
                TestDelegate call = () => reader.ReadFailureMechanismSection();

                // Assert
                string message         = Assert.Throws <CriticalFileReadException>(call).Message;
                string expectedMessage = $"Fout bij het lezen van bestand '{validFilePath}': het bestand heeft geen attribuut 'Vaknaam'. Dit attribuut is vereist.";
                Assert.AreEqual(expectedMessage, message);
            }
        }
        public void ReadFailureMechanismSection_ValidFilePath1_ReturnElement()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", "traject_1-1_vakken.shp"));

            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                // Call
                FailureMechanismSection section = reader.ReadFailureMechanismSection();

                // Assert
                Assert.AreEqual("1-1_0", section.Name);
                Point2D[] geometryPoints = section.Points.ToArray();
                Assert.AreEqual(10, geometryPoints.Length);
                Assert.AreEqual(209655.500, geometryPoints[4].X, 1e-6);
                Assert.AreEqual(610800.687, geometryPoints[4].Y, 1e-6);
            }
        }
        public void ReadFailureMechanismSection_ValidFilePathAndForAllElements_CorrectSectionNameRead()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", "traject_1-1_vakken.shp"));

            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                int count = reader.GetFailureMechanismSectionCount();
                for (var i = 0; i < count; i++)
                {
                    // Call
                    FailureMechanismSection section = reader.ReadFailureMechanismSection();

                    // Assert
                    string expectedSectionName = $"1-1_{i}";
                    Assert.AreEqual(expectedSectionName, section.Name, $"Section name is not as expected at index {i}");
                }
            }
        }
        public void ReadFailureMechanismSection_ReadingToEndOfFile_ReturnNull(string shapeFileName)
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", shapeFileName));

            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                int count = reader.GetFailureMechanismSectionCount();
                for (var i = 0; i < count; i++)
                {
                    reader.ReadFailureMechanismSection();
                }

                // Call
                FailureMechanismSection resultBeyondEndOfFile = reader.ReadFailureMechanismSection();

                // Assert
                Assert.IsNull(resultBeyondEndOfFile);
            }
        }
        public void ReadFailureMechanismSection_ValidFilePath2_ReturnElement()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", "traject_227_vakken.shp"));

            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                // Call
                FailureMechanismSection section = reader.ReadFailureMechanismSection();

                // Assert
                Assert.AreEqual("227_0", section.Name);
                Point2D[] geometryPoints = section.Points.ToArray();
                Assert.AreEqual(2, geometryPoints.Length);
                Assert.AreEqual(187518.859, geometryPoints[0].X, 1e-6);
                Assert.AreEqual(503867.688, geometryPoints[0].Y, 1e-6);
                Assert.AreEqual(187448.585284, geometryPoints[1].X, 1e-6);
                Assert.AreEqual(503832.715294, geometryPoints[1].Y, 1e-6);
            }
        }
        public void ReadFailureMechanismSection_FileHadMultiPolylines_ThrowCriticalFileReadException()
        {
            // Setup
            string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                              Path.Combine("FailureMechanismSections", "Artificial_MultiPolyline_vakken.shp"));

            using (var reader = new FailureMechanismSectionReader(validFilePath))
            {
                // Call
                TestDelegate call = () =>
                {
                    reader.ReadFailureMechanismSection();
                    reader.ReadFailureMechanismSection();
                    reader.ReadFailureMechanismSection();
                    reader.ReadFailureMechanismSection();
                };

                // Assert
                string message         = Assert.Throws <CriticalFileReadException>(call).Message;
                string expectedMessage = $"Fout bij het lezen van bestand '{validFilePath}': het bestand bevat een of meerdere multi-polylijnen. " +
                                         "Multi-polylijnen worden niet ondersteund.";
                Assert.AreEqual(expectedMessage, message);
            }
        }