Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public void Import_FromFileWithNonPointFeatures_FalseAndLogError(string shapeFileName)
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
                                                         shapeFileName);

            var profilesImporter = new TestStructuresImporter(testImportTarget,
                                                              testReferenceLine,
                                                              filePath,
                                                              updateStrategy,
                                                              messageProvider);

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

            // Assert
            string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': kon geen punten vinden in dit bestand.";

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

            mocks.ReplayAll();

            string folderPath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO) + Path.DirectorySeparatorChar;

            var testStructuresImporter = new TestStructuresImporter(testImportTarget,
                                                                    testReferenceLine,
                                                                    folderPath,
                                                                    updateStrategy,
                                                                    messageProvider);

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

            // Assert
            string expectedMessage = new FileReaderErrorMessageBuilder(folderPath)
                                     .Build(CoreCommonUtilResources.Error_Path_must_not_point_to_empty_file_name);

            TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
            Assert.IsFalse(importResult);
        }
Beispiel #6
0
        public void Import_FromPathContainingInvalidPathCharacters_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            const string filePath = "c:\\Invalid_Characters.shp";

            char[] invalidPathChars = Path.GetInvalidPathChars();
            string invalidPath      = filePath.Replace('_', invalidPathChars[0]);

            var testStructuresImporter = new TestStructuresImporter(testImportTarget,
                                                                    testReferenceLine,
                                                                    invalidPath,
                                                                    updateStrategy,
                                                                    messageProvider);

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

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string expectedMessage = new FileReaderErrorMessageBuilder(invalidPath)
                                         .Build("Er zitten ongeldige tekens in het bestandspad. Alle tekens in het bestandspad moeten geldig zijn.");
                StringAssert.StartsWith(expectedMessage, messages.First());
            });
            Assert.IsFalse(importResult);
        }
Beispiel #7
0
        public void Import_FromInvalidEmptyPath_FalseAndLogError(string filePath)
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            mocks.ReplayAll();

            var testStructuresImporter = new TestStructuresImporter(testImportTarget,
                                                                    testReferenceLine,
                                                                    filePath,
                                                                    updateStrategy,
                                                                    messageProvider);

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

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string[] messageArray  = messages.ToArray();
                string expectedMessage = new FileReaderErrorMessageBuilder(filePath)
                                         .Build(CoreCommonUtilResources.Error_Path_must_be_specified);
                StringAssert.StartsWith(expectedMessage, messageArray[0]);
            });
            Assert.IsFalse(importResult);
        }
Beispiel #8
0
        public void DoPostImport_UpdateWithCreatedStructuresReturnsObservables_ObservablesNotified()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            var observableA = mocks.StrictMock <IObservable>();

            observableA.Expect(o => o.NotifyObservers());
            var observableB = mocks.StrictMock <IObservable>();

            observableB.Expect(o => o.NotifyObservers());

            var updateStrategy = mocks.StrictMock <IStructureUpdateStrategy <TestStructure> >();

            updateStrategy.Expect(strat => strat.UpdateStructuresWithImportedData(null, null))
            .IgnoreArguments()
            .Return(new[]
            {
                observableA,
                observableB
            });
            mocks.ReplayAll();

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

            ReferenceLine referenceLine = CreateReferenceLine();

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

            importer.Import();

            // Call
            importer.DoPostImport();

            // Then
            // Assertions performed in TearDown
        }
Beispiel #9
0
        public void Import_CancelOfImportWhenCreatingStructures_ContinueImportAndLogWarning()
        {
            // Setup
            const string addDataToModelProgressText = "addDataToModelProgressText";
            var          messageProvider            = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(addDataToModelProgressText);
            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) =>
            {
                if (description.Contains(addDataToModelProgressText))
                {
                    testStructuresImporter.Cancel();
                }
            });

            var importResult = true;

            // Call
            Action call = () => importResult = testStructuresImporter.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);
        }
Beispiel #10
0
        public void Import_CancelOfImportWhenReadingStructureData_FalseAndLogInfo()
        {
            // Setup
            const string messageText     = "importeren is afgebroken";
            var          messageProvider = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Kunstwerken")).Return(messageText);
            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) =>
            {
                if (description.Contains("Inlezen van kunstwerkgegevens uit een kommagescheiden bestand."))
                {
                    testStructuresImporter.Cancel();
                }
            });

            var importResult = true;

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

            // Assert
            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(messageText, LogLevelConstant.Info), 1);
            Assert.IsFalse(importResult);
        }
Beispiel #11
0
        public void Import_ValidImportFile_CallsUpdateStrategyWithExpectedArguments()
        {
            // Setup
            var    targetCollection = new StructureCollection <TestStructure>();
            string filePath         = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                 Path.Combine("Structures", "CorrectFiles",
                                                                              "Kunstwerken.shp"));

            var createdStructures = new[]
            {
                new TestStructure()
            };

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <TestStructure> >();

            updateStrategy.Expect(strat => strat.UpdateStructuresWithImportedData(createdStructures, filePath));
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var importer = new TestStructuresImporter(targetCollection,
                                                      referenceLine,
                                                      filePath,
                                                      updateStrategy,
                                                      messageProvider)
            {
                CreatedTestStructures = createdStructures
            };

            // Call
            importer.Import();

            // Assert
            Assert.IsTrue(importer.CreateStructuresCalled);

            // Further assertions done in the TearDown
        }
Beispiel #12
0
        public void Import_LocationOutsideReferenceLine_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", "CorrectFiles", "Kunstwerken.shp"));

            var referencePoints = new List <Point2D>
            {
                new Point2D(131144.094, 549979.893),
                new Point2D(131538.705, 548316.752),
                new Point2D(135878.442, 532149.859),
                new Point2D(131225.017, 548395.948),
                new Point2D(131270.38, 548367.462)
            };
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(referencePoints);
            var testStructuresImporter = new TestStructuresImporter(new StructureCollection <TestStructure>(),
                                                                    referenceLine,
                                                                    filePath,
                                                                    updateStrategy,
                                                                    messageProvider);

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

            // Assert
            const string expectedMessage = "Een kunstwerklocatie met KWKIDENT 'KUNST6' ligt niet op de referentielijn.";

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

            mocks.ReplayAll();

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

            var profilesImporter = new TestStructuresImporter(testImportTarget,
                                                              testReferenceLine,
                                                              invalidFilePath,
                                                              updateStrategy,
                                                              messageProvider);

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

            // Assert
            Assert.IsFalse(importResult);
        }
Beispiel #14
0
        public void Import_UpdateWithCreatedStructuresThrowsUpdateDataException_ReturnFalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return("");
            messageProvider.Expect(mp => mp.GetUpdateDataFailedLogMessageText("Kunstwerken")).Return("error {0}");
            var updateStrategy = mocks.Stub <IStructureUpdateStrategy <TestStructure> >();

            updateStrategy.Expect(us => us.UpdateStructuresWithImportedData(null, null))
            .IgnoreArguments()
            .Throw(new UpdateDataException("Exception message"));
            mocks.ReplayAll();

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

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

            var importResult = true;

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

            // Then
            const string expectedMessage = "error Exception message";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1);
            Assert.IsFalse(importResult);
        }
Beispiel #15
0
        public void Import_IllegalCsvFile_ReturnsFalse()
        {
            // 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", "IllegalCsv", "Kunstwerken.shp"));

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

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

            // Assert
            Assert.IsFalse(importResult);
        }