public void Import_CancelImportDuringDialogInteraction_GenerateCanceledLogMessageAndReturnsFalse() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Expect(h => h.InquireConfirmation()).Return(false); mocks.ReplayAll(); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(validHrdFilePath); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, validHlcdFilePath); var importResult = true; // Call Action call = () => importResult = importer.Import(); // Assert const string expectedMessage = "HLCD bestand importeren afgebroken. Geen gegevens gewijzigd."; TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Info), 1); Assert.IsFalse(importResult); mocks.VerifyAll(); }
public void Import_ValidFileWithScenarioInformation_UpdatesHydraulicBoundaryDatabaseWithImportedData() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportHydraulicBoundaryDatabase(assessmentSection, validHrdFilePath); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; string filePath = Path.Combine(testDataPath, "hlcdWithValidScenarioInformation.sqlite"); var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Expect(h => h.InquireConfirmation()).Return(true); handler.Expect(h => h.Update(Arg <HydraulicBoundaryDatabase> .Is.Same(hydraulicBoundaryDatabase), Arg <ReadHydraulicLocationConfigurationDatabaseSettings> .Is.NotNull, Arg <bool> .Is.Equal(false), Arg <string> .Is.Equal(filePath))) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); var importer = new HydraulicLocationConfigurationDatabaseImporter(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings, handler, hydraulicBoundaryDatabase, filePath); // Call var importResult = false; Action call = () => importResult = importer.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{filePath}'.", 1); Assert.IsTrue(importResult); mocks.VerifyAll(); }
public void Import_CancelOfImportWhilePerformingStep_CancelsImportAndLogs(int stepNumber) { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); mocks.ReplayAll(); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(validHrdFilePath); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, validHlcdFilePath); importer.SetProgressChanged((description, currentStep, steps) => { if (currentStep == stepNumber) { importer.Cancel(); } }); // Call var importResult = true; Action call = () => importResult = importer.Import(); // Assert const string expectedMessage = "HLCD bestand importeren afgebroken. Geen gegevens gewijzigd."; TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Info), 1); Assert.IsFalse(importResult); mocks.VerifyAll(); }
public void Import_HlcdWithUsePreprocessorClosureTrueAndWithoutPreprocessorClosure_CancelImportWithErrorMessage() { // Setup string directory = Path.Combine(testDataPath, "missingPreprocessorClosure"); string filePath = Path.Combine(directory, "newHlcd.sqlite"); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(Path.Combine(directory, "completeHrd.sqlite")); var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Expect(h => h.InquireConfirmation()).Return(true); mocks.ReplayAll(); var importer = new HydraulicLocationConfigurationDatabaseImporter(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings, handler, hydraulicBoundaryDatabase, filePath); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het bijbehorende preprocessor closure bestand is niet gevonden in dezelfde map als het HLCD bestand."; AssertImportFailed(call, expectedMessage, ref importSuccessful); mocks.VerifyAll(); }
public void Import_ValidFiles_ExpectedProgressNotifications() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); handler.Stub(h => h.Update(null, null, false, null)).IgnoreArguments().Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); var progressChangeNotifications = new List <ProgressNotification>(); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(validHrdFilePath); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, validHlcdFilePath); importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps))); // Call bool importResult = importer.Import(); // Assert Assert.IsTrue(importResult); var expectedProgressNotifications = new[] { new ProgressNotification("Inlezen van het hydraulische belastingen bestand.", 1, totalNumberOfSteps), new ProgressNotification("Inlezen van het hydraulische locatie configuratie bestand.", 2, totalNumberOfSteps), new ProgressNotification("Geïmporteerde data toevoegen aan het traject.", 3, totalNumberOfSteps) }; ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressNotifications, progressChangeNotifications); mocks.VerifyAll(); }
public void Import_LocationIdNotInHlcd_CancelImportWithErrorMessage() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportHydraulicBoundaryDatabase(assessmentSection, validHrdFilePath); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; hydraulicBoundaryDatabase.Locations.Add(new TestHydraulicBoundaryLocation()); var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); mocks.ReplayAll(); var importer = new HydraulicLocationConfigurationDatabaseImporter(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings, handler, hydraulicBoundaryDatabase, validHlcdFilePath); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{validHlcdFilePath}': 1 of meerdere locaties komen niet voor in de HLCD."; AssertImportFailed(call, expectedMessage, ref importSuccessful); mocks.VerifyAll(); }
public void Import_InvalidNumberOfScenarioInformationEntries_CancelImportWithErrorMessage(string fileName) { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); mocks.ReplayAll(); string path = Path.Combine(testDataPath, $"{fileName}.sqlite"); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(validHrdFilePath); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, path); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{path}': de tabel 'ScenarioInformation' moet exact 1 rij bevatten."; AssertImportFailed(call, expectedMessage, ref importSuccessful); mocks.VerifyAll(); }
public void Import_InvalidSchema_CancelImportWithErrorMessage() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); mocks.ReplayAll(); string path = Path.Combine(testDataPath, "invalid.sqlite"); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(validHrdFilePath); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, path); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{path}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; AssertImportFailed(call, expectedMessage, ref importSuccessful); mocks.VerifyAll(); }
public void Import_HrdEmptySchema_CancelImportWithErrorMessage() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); mocks.ReplayAll(); string path = Path.Combine(testDataPath, "EmptyHrd"); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(Path.Combine(path, "empty.sqlite")); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, Path.Combine(path, "HLCD.sqlite")); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabase.FilePath}': kon geen locaties verkrijgen van de database."; AssertImportFailed(call, expectedMessage, ref importSuccessful); mocks.VerifyAll(); }
public void Import_HlcdInDifferentDirectoryThanHydraulicBoundaryDatabase_CancelImportWithErrorMessage() { // Setup var mocks = new MockRepository(); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); mocks.ReplayAll(); string hydraulicBoundaryDatabasePath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO, nameof(HydraulicBoundaryDatabaseImporter)), "complete.sqlite"); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(hydraulicBoundaryDatabasePath); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, validHlcdFilePath); // Call var importSuccessful = true; Action call = () => importSuccessful = importer.Import(); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{validHlcdFilePath}': het HLCD bestand is niet gevonden in dezelfde map als het HRD bestand."; AssertImportFailed(call, expectedMessage, ref importSuccessful); mocks.VerifyAll(); }
public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); mocks.ReplayAll(); // Call var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, new HydraulicBoundaryDatabase(), validHlcdFilePath); // Assert Assert.IsInstanceOf <FileImporterBase <HydraulicLocationConfigurationSettings> >(importer); mocks.VerifyAll(); }
public void DoPostImportUpdates_WhenImportSuccessful_NotifyObserversOfReturnedObjects() { // Setup HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(validHrdFilePath); var mocks = new MockRepository(); var observable1 = mocks.StrictMock <IObservable>(); observable1.Expect(o => o.NotifyObservers()); var observable2 = mocks.StrictMock <IObservable>(); observable2.Expect(o => o.NotifyObservers()); var handler = mocks.StrictMock <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Expect(h => h.InquireConfirmation()).Return(true); handler.Expect(h => h.Update(Arg <HydraulicBoundaryDatabase> .Is.NotNull, Arg <ReadHydraulicLocationConfigurationDatabaseSettings> .Is.Null, Arg <bool> .Is.Equal(false), Arg <string> .Is.NotNull)) .Return(new[] { observable1, observable2 }); mocks.ReplayAll(); var importer = new HydraulicLocationConfigurationDatabaseImporter(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings, handler, hydraulicBoundaryDatabase, validHlcdFilePath); // Precondition Assert.IsTrue(importer.Import()); // Call importer.DoPostImport(); // Assert mocks.VerifyAll(); // Expect NotifyObservers on updated observables }
public void Import_CancelImportDuringAddReadDataToDataModel_ContinuesImportAndLogs() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub <IHydraulicLocationConfigurationDatabaseUpdateHandler>(); handler.Stub(h => h.InquireConfirmation()).Return(true); handler.Stub(h => h.Update(null, null, false, null)).IgnoreArguments().Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateHydraulicBoundaryDatabase(validHrdFilePath); var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, validHlcdFilePath); importer.SetProgressChanged((description, step, steps) => { if (step == totalNumberOfSteps) { importer.Cancel(); } }); var importResult = true; // Call importer.Import(); Action call = () => importResult = importer.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); mocks.VerifyAll(); }