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_AllOkTestData_CorrectDikeProfileProperties() { // 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); // Call dikeProfilesImporter.Import(); // Assert Assert.IsTrue(updateDataStrategy.Updated); DikeProfile[] dikeProfiles = updateDataStrategy.ReadDikeProfiles; DikeProfile dikeProfile1 = dikeProfiles[0]; Assert.AreEqual("profiel001", dikeProfile1.Id); Assert.AreEqual("profiel001", dikeProfile1.Name); DikeProfile dikeProfile2 = dikeProfiles[1]; Assert.AreEqual("profiel002", dikeProfile2.Id); Assert.AreEqual("profiel002", dikeProfile2.Name); DikeProfile dikeProfile3 = dikeProfiles[2]; Assert.AreEqual("profiel003", dikeProfile3.Id); Assert.AreEqual("profiel003", dikeProfile3.Name); DikeProfile dikeProfile4 = dikeProfiles[3]; Assert.AreEqual(new Point2D(136432.12250000238, 538235.26300000318), dikeProfile4.WorldReferencePoint); Assert.AreEqual("profiel004", dikeProfile4.Id); Assert.AreEqual("Valide naam", dikeProfile4.Name); Assert.AreEqual(-17.93475471, dikeProfile4.X0); Assert.AreEqual(330.0, dikeProfile4.Orientation, dikeProfile4.Orientation.GetAccuracy()); Assert.IsFalse(dikeProfile4.HasBreakWater); DikeProfile dikeProfile5 = dikeProfiles[4]; Assert.AreEqual(new Point2D(136039.49100000039, 533920.28050000477), dikeProfile5.WorldReferencePoint); Assert.AreEqual("profiel005", dikeProfile5.Id); Assert.AreEqual("Heeeeeeeeeeeeeeeeeeeeeeeele laaaaaaaaaaaaaaaaaaaange naaaaaaaaaaam", dikeProfile5.Name); Assert.AreEqual(15.56165507, dikeProfile5.X0); Assert.AreEqual(330.0, dikeProfile5.Orientation, dikeProfile5.Orientation.GetAccuracy()); Assert.IsTrue(dikeProfile5.HasBreakWater); Assert.AreEqual(6.0, dikeProfile5.DikeHeight, dikeProfile5.DikeHeight.GetAccuracy()); }
public void Import_AllOkTestData_TrueAndLogMessagesAndFiveDikeProfiles() { // Setup const string expectedAddDataToModelProgressText = "Adding data"; var messageProvider = mocks.StrictMock <IImporterMessageProvider>(); messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddDataToModelProgressText); mocks.ReplayAll(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var progressChangeNotifications = new List <ProgressNotification>(); var updateDataStrategy = new TestDikeProfileUpdateStrategy(); var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider); dikeProfilesImporter.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps))); // Call var importResult = false; Action call = () => importResult = dikeProfilesImporter.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{filePath}'.", 1); Assert.IsTrue(importResult); var expectedProgressMessages = new List <ProgressNotification> { new ProgressNotification("Inlezen van profiellocaties uit een shapebestand.", 1, 1), new ProgressNotification("Inlezen van profiellocatie.", 1, 5), new ProgressNotification("Inlezen van profiellocatie.", 2, 5), new ProgressNotification("Inlezen van profiellocatie.", 3, 5), new ProgressNotification("Inlezen van profiellocatie.", 4, 5), new ProgressNotification("Inlezen van profiellocatie.", 5, 5), new ProgressNotification("Inlezen van profielgegevens uit een prfl bestand.", 1, 1), new ProgressNotification("Inlezen van profielgegevens.", 1, 5), new ProgressNotification("Inlezen van profielgegevens.", 2, 5), new ProgressNotification("Inlezen van profielgegevens.", 3, 5), new ProgressNotification("Inlezen van profielgegevens.", 4, 5), new ProgressNotification("Inlezen van profielgegevens.", 5, 5), new ProgressNotification(expectedAddDataToModelProgressText, 1, 1) }; ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages, progressChangeNotifications); Assert.IsTrue(updateDataStrategy.Updated); Assert.AreEqual(5, updateDataStrategy.ReadDikeProfiles.Length); }
public void Import_CancelOfImportWhileReadingProfileLocations_CancelImportAndLogInfo() { // Setup const string cancelledLogMessage = "Operation Cancelled"; var messageProvider = mocks.StrictMock <IImporterMessageProvider>(); messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Dijkprofielen")).Return(cancelledLogMessage); 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) => { if (description.Contains("Inlezen van profiellocaties uit een shapebestand.")) { dikeProfilesImporter.Cancel(); } }); var importResult = true; // Call Action call = () => importResult = dikeProfilesImporter.Import(); // Assert Tuple <string, LogLevelConstant> expectedLogMessage = Tuple.Create(cancelledLogMessage, LogLevelConstant.Info); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); Assert.IsFalse(updateDataStrategy.Updated); }
public void Import_OneDikeProfileLocationNotCloseEnoughToReferenceLine_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(131223.2, 548393.4), new Point2D(133854.3, 545323.1), new Point2D(135561.0, 541920.3), new Point2D(136432.1, 538235.2), new Point2D(146039.4, 533920.2) }; var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); var updateDataStrategy = new TestDikeProfileUpdateStrategy(); var dikeProfiles = new DikeProfileCollection(); var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath, updateDataStrategy, messageProvider); var importResult = false; // Call Action call = () => importResult = dikeProfilesImporter.Import(); // Assert const string expectedMessage = "Fout bij het lezen van profiellocatie 5. De profiellocatie met " + "ID 'profiel005' ligt niet op de referentielijn."; TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1); Assert.IsFalse(importResult); CollectionAssert.IsEmpty(dikeProfiles); }
public void DoPostImport_AfterImport_ObserversNotified() { // 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()); mocks.ReplayAll(); var updateDataStrategy = new TestDikeProfileUpdateStrategy(); updateDataStrategy.UpdatedInstances = new[] { observableA, observableB }; string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp")); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var importer = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider); importer.Import(); // Call importer.DoPostImport(); // Assert // Asserts done in TearDown() }
public void Import_ThreeDikeProfilesWithInvalidDefinitions_TrueAndLogWarning() { // Setup var messageProvider = mocks.Stub <IImporterMessageProvider>(); mocks.ReplayAll(); string fileDirectory = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "NoDikeProfileGeometries")); string filePath = Path.Combine(fileDirectory, "Voorlanden 12-2.shp"); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var updateStrategy = new TestDikeProfileUpdateStrategy(); var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateStrategy, messageProvider); // Call var importResult = false; Action call = () => importResult = dikeProfilesImporter.Import(); // Assert Tuple <string, LogLevelConstant>[] expectedMessages = { Tuple.Create($"Profielgegevens definiëren geen dijkgeometrie. Bestand '{Path.Combine(fileDirectory, "profiel001DikeProfileNoGeometry.prfl")}' wordt overgeslagen.", LogLevelConstant.Warn), Tuple.Create($"Profielgegevens definiëren geen geldige dijkgeometrie. De dijkgeometrie moet bestaan uit tenminste 2 punten. Bestand '{Path.Combine(fileDirectory, "profiel002DikeProfileOnePoint.prfl")}' wordt overgeslagen.", LogLevelConstant.Warn), Tuple.Create("Profielgegevens definiëren geen geldige voorlandgeometrie. De voorlandgeometrie moet bestaan uit 0 of tenminste 2 punten." + $" Bestand '{Path.Combine(fileDirectory, "profiel003DikeProfileValidForeshoreProfileInvalid.prfl")}' wordt overgeslagen.", LogLevelConstant.Warn) }; TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 4); Assert.IsTrue(importResult); Assert.IsTrue(updateStrategy.Updated); Assert.AreEqual(5, updateStrategy.ReadDikeProfiles.Length); }