public void DoPostImportUpdates_CancelingImport_DoNotNotifyObserversAndNotDoPostReplacementUpdates() { // Setup string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, "traject_10-2.shp"); ReferenceLine referenceLine = ReferenceLineTestFactory.CreateReferenceLineWithGeometry(); var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); var handler = mocks.StrictMock <IReferenceLineUpdateHandler>(); var importer = new ReferenceLineImporter(referenceLine, handler, path); handler.Expect(h => h.ConfirmUpdate()) .WhenCalled(invocation => importer.Cancel()) .Return(true); mocks.ReplayAll(); referenceLine.Attach(observer); // Precondition Assert.IsFalse(importer.Import()); // Call importer.DoPostImport(); // Assert mocks.VerifyAll(); // Expect no NotifyObserver calls }
public void Import_CancelImportDuringAddReferenceLineToData_ContinuesImportAndLogs() { // Setup string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var mocks = new MockRepository(); var handler = mocks.Stub <IReferenceLineUpdateHandler>(); handler.Stub(h => h.Update(null, null)) .IgnoreArguments() .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); var importer = new ReferenceLineImporter(new ReferenceLine(), handler, path); importer.SetProgressChanged((description, step, steps) => { if (description.Contains("Geïmporteerde data toevoegen aan het traject.")) { importer.Cancel(); } }); var importResult = true; // Call importer.Import(); Action call = () => importResult = importer.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, "Huidige actie was niet meer te annuleren en is daarom voortgezet.", 2); Assert.IsTrue(importResult); mocks.VerifyAll(); }
public void Import_WhenSuccessful_GeneratedExpectedProgressMessages() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub <IReferenceLineUpdateHandler>(); handler.Expect(h => h.Update(Arg <ReferenceLine> .Is.NotNull, Arg <ReferenceLine> .Is.NotNull)) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var progressChangeNotifications = new List <ProgressNotification>(); var importer = new ReferenceLineImporter(new ReferenceLine(), handler, path); importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps))); // Call importer.Import(); // Assert var expectedProgressNotifications = new[] { new ProgressNotification("Inlezen referentielijn.", 1, 2), new ProgressNotification("Geïmporteerde data toevoegen aan het traject.", 2, 2) }; ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressNotifications, progressChangeNotifications); mocks.VerifyAll(); }
public void Import_CancelImportDuringReadReferenceLine_CancelsImportAndLogs() { // Setup string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var mocks = new MockRepository(); var handler = mocks.Stub <IReferenceLineUpdateHandler>(); mocks.ReplayAll(); var importer = new ReferenceLineImporter(new ReferenceLine(), handler, path); importer.SetProgressChanged((description, step, steps) => { if (description.Contains("Inlezen referentielijn.")) { importer.Cancel(); } }); var importResult = true; // Call Action call = () => importResult = importer.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, "Referentielijn importeren afgebroken. Geen gegevens gewijzigd.", 1); Assert.IsFalse(importResult); mocks.VerifyAll(); }
public void DoPostImportUpdates_ReuseImporterWithReferenceLineAndAnswerDialogToContinue_NotifyObserversOfTargetAndClearedObjects() { // Setup string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var referenceLine = new ReferenceLine(); var mocks = new MockRepository(); var referenceLineObserver = mocks.Stub <IObserver>(); referenceLineObserver.Expect(o => o.UpdateObserver()); var observable1 = mocks.StrictMock <IObservable>(); observable1.Expect(o => o.NotifyObservers()); var observable2 = mocks.StrictMock <IObservable>(); observable2.Expect(o => o.NotifyObservers()); var handler = mocks.Stub <IReferenceLineUpdateHandler>(); handler.Expect(h => h.Update(Arg <ReferenceLine> .Is.Same(referenceLine), Arg <ReferenceLine> .Is.NotNull)) .Return(new[] { observable1, observable2 }); handler.Expect(h => h.DoPostUpdateActions()); mocks.ReplayAll(); referenceLine.Attach(referenceLineObserver); var importer = new ReferenceLineImporter(referenceLine, handler, path); importer.SetProgressChanged((description, step, steps) => importer.Cancel()); // Precondition Assert.IsFalse(importer.Import()); importer.SetProgressChanged(null); Assert.IsTrue(importer.Import()); // Call importer.DoPostImport(); // Assert mocks.VerifyAll(); // Expect NotifyObservers on cleared calculations }
public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub <IReferenceLineUpdateHandler>(); mocks.ReplayAll(); // Call var importer = new ReferenceLineImporter(new ReferenceLine(), handler, ""); // Assert Assert.IsInstanceOf <FileImporterBase <ReferenceLine> >(importer); mocks.VerifyAll(); }
public void GivenReferenceLineWithGeometry_WhenCancelingReferenceLineImport_ThenKeepOriginalReferenceLine() { // Given var mocks = new MockRepository(); var viewCommands = mocks.Stub <IViewCommands>(); mocks.ReplayAll(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ReferenceLineTestFactory.SetReferenceLineGeometry(assessmentSection.ReferenceLine); Point2D[] originalReferenceLineGeometry = assessmentSection.ReferenceLine.Points.ToArray(); var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, "traject_10-2.shp"); var importer = new ReferenceLineImporter(assessmentSection.ReferenceLine, handler, path); string messageBoxTitle = null, messageBoxText = null; DialogBoxHandler = (name, wnd) => { var messageBoxTester = new MessageBoxTester(wnd); messageBoxTitle = messageBoxTester.Title; messageBoxText = messageBoxTester.Text; messageBoxTester.ClickCancel(); }; // When bool importSuccessful = importer.Import(); // Then Assert.IsFalse(importSuccessful); CollectionAssert.AreEqual(originalReferenceLineGeometry, assessmentSection.ReferenceLine.Points); Assert.AreEqual("Bevestigen", messageBoxTitle); string expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van alle faalmechanismen worden gewist." + Environment.NewLine + Environment.NewLine + "Wilt u doorgaan?"; Assert.AreEqual(expectedText, messageBoxText); mocks.VerifyAll(); }
private static ReferenceLine ImportReferenceLine(string referenceLineFilePath) { var referenceLine = new ReferenceLine(); var mocks = new MockRepository(); var handler = mocks.Stub <IReferenceLineUpdateHandler>(); handler.Stub(h => h.ConfirmUpdate()).Return(true); handler.Stub(h => h.Update(Arg <ReferenceLine> .Is.NotNull, Arg <ReferenceLine> .Is.NotNull)) .WhenCalled(invocation => referenceLine = (ReferenceLine)invocation.Arguments[1]) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); var referenceLineImporter = new ReferenceLineImporter(referenceLine, handler, referenceLineFilePath); referenceLineImporter.Import(); mocks.VerifyAll(); return(referenceLine); }
public void Import_ReusingCanceledImporterForReferenceLineWithoutGeometry_ImportReferenceLine() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IReferenceLineUpdateHandler>(); handler.Expect(h => h.Update(Arg <ReferenceLine> .Is.NotNull, Arg <ReferenceLine> .Is.NotNull)) .WhenCalled(invocation => { var importedReferenceLine = (ReferenceLine)invocation.Arguments[1]; Point2D[] point2Ds = importedReferenceLine.Points.ToArray(); Assert.AreEqual(803, point2Ds.Length); Assert.AreEqual(195203.563, point2Ds[321].X, 1e-6); Assert.AreEqual(512826.406, point2Ds[321].Y, 1e-6); }) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var importer = new ReferenceLineImporter(new ReferenceLine(), handler, path); importer.SetProgressChanged((description, step, steps) => importer.Cancel()); // Precondition bool importSuccessful = importer.Import(); Assert.IsFalse(importSuccessful); importer.SetProgressChanged(null); // Call importSuccessful = importer.Import(); // Assert Assert.IsTrue(importSuccessful); mocks.VerifyAll(); }
public void Import_CancelImportDuringDialogInteraction_GenerateCanceledLogMessageAndReturnsFalse() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IReferenceLineUpdateHandler>(); handler.Expect(h => h.ConfirmUpdate()).Return(false); mocks.ReplayAll(); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, "traject_10-2.shp"); var importer = new ReferenceLineImporter(ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), handler, path); var importResult = true; // Call Action call = () => importResult = importer.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, "Referentielijn importeren afgebroken. Geen gegevens gewijzigd.", 1); Assert.IsFalse(importResult); mocks.VerifyAll(); }
public void Import_WhenSuccessful_UpdatesOriginalReferenceLineWithImportedReferenceLine() { // Setup var originalReferenceLine = new ReferenceLine(); var mocks = new MockRepository(); var handler = mocks.StrictMock <IReferenceLineUpdateHandler>(); handler.Expect(h => h.Update(Arg <ReferenceLine> .Is.NotNull, Arg <ReferenceLine> .Is.NotNull)) .WhenCalled(invocation => { Assert.AreSame(originalReferenceLine, invocation.Arguments[0]); var importedReferenceLine = (ReferenceLine)invocation.Arguments[1]; Point2D[] point2Ds = importedReferenceLine.Points.ToArray(); Assert.AreEqual(803, point2Ds.Length); Assert.AreEqual(193515.719, point2Ds[467].X, 1e-6); Assert.AreEqual(511444.750, point2Ds[467].Y, 1e-6); }) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var importer = new ReferenceLineImporter(originalReferenceLine, handler, path); // Call var importSuccessful = false; Action call = () => importSuccessful = importer.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{path}'.", 1); Assert.IsTrue(importSuccessful); mocks.VerifyAll(); }
public void Import_ShapefileDoesNotExist_CancelImportWithErrorMessage() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IReferenceLineUpdateHandler>(); mocks.ReplayAll(); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, "I_dont_exist"); var importer = new ReferenceLineImporter(new ReferenceLine(), handler, path); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $@"Fout bij het lezen van bestand '{path}': het bestand bestaat niet. " + $"{Environment.NewLine}Er is geen referentielijn geïmporteerd."; TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); Assert.IsFalse(importSuccessful); mocks.VerifyAll(); }
public void Import_FilePathIsDirectory_CancelImportWithErrorMessage() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IReferenceLineUpdateHandler>(); mocks.ReplayAll(); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.DirectorySeparatorChar.ToString()); var importer = new ReferenceLineImporter(new ReferenceLine(), handler, path); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $@"Fout bij het lezen van bestand '{path}': bestandspad mag niet verwijzen naar een lege bestandsnaam. " + $"{Environment.NewLine}Er is geen referentielijn geïmporteerd."; TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); Assert.IsFalse(importSuccessful); mocks.VerifyAll(); }
public void GivenAssessmentSectionWithReferenceLineAndOtherData_WhenImportingReferenceLine_ThenReferenceLineGeometryReplacedAndReferenceLineDependentDataCleared() { // Given var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var mocks = new MockRepository(); var viewCommands = mocks.Stub <IViewCommands>(); var failureMechanismObserver = mocks.StrictMock <IObserver>(); failureMechanismObserver.Expect(o => o.UpdateObserver()) .Repeat.Times(assessmentSection.GetFailureMechanisms().Count()); var referenceLineObserver = mocks.StrictMock <IObserver>(); referenceLineObserver.Expect(o => o.UpdateObserver()); var surfaceLinesObserver = mocks.StrictMock <IObserver>(); surfaceLinesObserver.Expect(o => o.UpdateObserver()); var stochasticSoilModelsObserver = mocks.StrictMock <IObserver>(); stochasticSoilModelsObserver.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); DataImportHelper.ImportReferenceLine(assessmentSection); DataImportHelper.ImportFailureMechanismSections(assessmentSection, assessmentSection.GetFailureMechanisms() .Cast <IFailureMechanism <FailureMechanismSectionResult> >()); DataImportHelper.ImportPipingSurfaceLines(assessmentSection); DataImportHelper.ImportPipingStochasticSoilModels(assessmentSection); ReferenceLine originalReferenceLine = assessmentSection.ReferenceLine; Point2D[] originalReferenceLineGeometry = originalReferenceLine.Points.ToArray(); var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var importer = new ReferenceLineImporter(assessmentSection.ReferenceLine, handler, path); string messageBoxTitle = null, messageBoxText = null; DialogBoxHandler = (name, wnd) => { var messageBoxTester = new MessageBoxTester(wnd); messageBoxTitle = messageBoxTester.Title; messageBoxText = messageBoxTester.Text; messageBoxTester.ClickOk(); }; assessmentSection.ReferenceLine.Attach(referenceLineObserver); foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms()) { failureMechanism.Attach(failureMechanismObserver); } assessmentSection.Piping.StochasticSoilModels.Attach(stochasticSoilModelsObserver); assessmentSection.Piping.SurfaceLines.Attach(surfaceLinesObserver); // When bool importSuccessful = importer.Import(); importer.DoPostImport(); // Then Assert.IsTrue(importSuccessful); Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine); CollectionAssert.AreNotEqual(originalReferenceLineGeometry, assessmentSection.ReferenceLine.Points); Point2D[] point2Ds = assessmentSection.ReferenceLine.Points.ToArray(); Assert.AreEqual(803, point2Ds.Length); Assert.AreEqual(198237.375, point2Ds[123].X, 1e-6); Assert.AreEqual(514879.781, point2Ds[123].Y, 1e-6); foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms()) { CollectionAssert.IsEmpty(failureMechanism.Sections); } CollectionAssert.IsEmpty(assessmentSection.Piping.SurfaceLines); CollectionAssert.IsEmpty(assessmentSection.Piping.StochasticSoilModels); CollectionAssert.IsEmpty(assessmentSection.Piping.CalculationsGroup.Children); Assert.AreEqual("Bevestigen", messageBoxTitle); string expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van alle faalmechanismen worden gewist." + Environment.NewLine + Environment.NewLine + "Wilt u doorgaan?"; Assert.AreEqual(expectedText, messageBoxText); mocks.VerifyAll(); }