public void Import_ImportingFailureMechanismTypeNotInDatabase_ShowProgressAndDoesNotUpdateCollection() { // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); const int totalNrOfStochasticSoilModelInDatabase = 6; var filter = mocks.StrictMock <IStochasticSoilModelMechanismFilter>(); filter.Expect(f => f.IsValidForFailureMechanism(null)) .IgnoreArguments() .Return(false) .WhenCalled(invocation => { FilterFailureMechanismSpecificModel(invocation, FailureMechanismType.None); }) .Repeat .Times(totalNrOfStochasticSoilModelInDatabase); var messageProvider = mocks.StrictMock <IImporterMessageProvider>(); var updateStrategy = mocks.StrictMock <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >(); mocks.ReplayAll(); var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>( new TestStochasticSoilModelCollection(), validFilePath, messageProvider, new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>( transformer, filter, updateStrategy)); var progressChangeNotifications = new List <ProgressNotification>(); importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps))); // Call bool importResult = importer.Import(); // Assert Assert.IsFalse(importResult); var expectedProgressMessages = new List <ProgressNotification> { new ProgressNotification("Inlezen van de D-Soil Model database.", 1, 1) }; for (var i = 1; i <= totalNrOfStochasticSoilModelInDatabase; i++) { expectedProgressMessages.Add(new ProgressNotification( "Inlezen van de stochastische ondergrondmodellen.", i, totalNrOfStochasticSoilModelInDatabase)); } ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages, progressChangeNotifications); }
public void Import_CancelWhileAddingDataToModel_ContinuesImportAndLogs() { // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); const int expectedNrOfStochasticSoilModels = 6; var stochasticSoilModelCollection = new TestStochasticSoilModelCollection(); const string expectedAddDataProgressText = "Adding data..."; var messageProvider = mocks.StrictMock <IImporterMessageProvider>(); messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()) .Return(expectedAddDataProgressText); var updateStrategy = mocks.StrictMock <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >(); updateStrategy.Expect(u => u.UpdateModelWithImportedData(Arg <IMechanismStochasticSoilModel[]> .List.ContainsAll(stochasticSoilModelCollection), Arg <string> .Is.Equal(validFilePath))); var filter = mocks.StrictMock <IStochasticSoilModelMechanismFilter>(); filter.Expect(f => f.IsValidForFailureMechanism(null)) .IgnoreArguments() .Return(true) .Repeat .Times(expectedNrOfStochasticSoilModels); mocks.ReplayAll(); var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>( stochasticSoilModelCollection, validFilePath, messageProvider, new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>( transformer, filter, updateStrategy)); importer.SetProgressChanged((description, step, steps) => { if (description.Contains(expectedAddDataProgressText)) { importer.Cancel(); } }); var importResult = false; // Call Action call = () => importResult = importer.Import(); // Assert const string expectedMessage = "Huidige actie was niet meer te annuleren en is daarom voortgezet."; Tuple <string, LogLevelConstant> expectedLogMessageAndLevel = Tuple.Create(expectedMessage, LogLevelConstant.Warn); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessageAndLevel, 2); Assert.IsTrue(importResult); }
public void Import_CancelWhenTransformingSoilModels_CancelsImportAndLogs() { // Setup const string cancelledLogMessage = "Operation Cancelled"; var messageProvider = mocks.StrictMock <IImporterMessageProvider>(); messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Stochastische ondergrondmodellen")) .Return(cancelledLogMessage); var updateStrategy = mocks.StrictMock <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >(); var filter = mocks.StrictMock <IStochasticSoilModelMechanismFilter>(); filter.Expect(f => f.IsValidForFailureMechanism(null)) .IgnoreArguments() .Return(true) .Repeat .AtLeastOnce(); mocks.ReplayAll(); string validFilePath = Path.Combine(testDataPath, "complete.soil"); var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>( new TestStochasticSoilModelCollection(), validFilePath, messageProvider, new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>( transformer, filter, updateStrategy)); importer.SetProgressChanged((description, step, steps) => { if (description.Contains("Valideren van ingelezen data.")) { importer.Cancel(); } }); var importResult = true; // Call Action call = () => importResult = importer.Import(); // Assert Tuple <string, LogLevelConstant> expectedLogMessage = Tuple.Create(cancelledLogMessage, LogLevelConstant.Info); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); }
public void Import_NonExistingFile_LogErrorReturnFalse() { // Setup var messageProvider = mocks.Stub <IImporterMessageProvider>(); var filter = mocks.Stub <IStochasticSoilModelMechanismFilter>(); var updateStrategy = mocks.Stub <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >(); mocks.ReplayAll(); const string file = "nonexisting.soil"; var collection = new TestStochasticSoilModelCollection(); string validFilePath = Path.Combine(testDataPath, file); var configuration = new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>(transformer, filter, updateStrategy); var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>( collection, validFilePath, messageProvider, configuration); var progress = 0; importer.SetProgressChanged((description, step, steps) => { progress++; }); var importResult = true; // Call Action call = () => importResult = importer.Import(); // Assert TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, messages => { Assert.AreEqual(1, messages.Count()); Tuple <string, Level, Exception> expectedLog = messages.ElementAt(0); Assert.AreEqual(Level.Error, expectedLog.Item2); Exception loggedException = expectedLog.Item3; Assert.IsInstanceOf <CriticalFileReadException>(loggedException); Assert.AreEqual(loggedException.Message, expectedLog.Item1); }); Assert.AreEqual(1, progress); Assert.IsFalse(importResult); }
public void Import_VariousFailureMechanismTypes_ShowProgressAndUpdatesCollection(FailureMechanismType failureMechanismType, int nrOfFailureMechanismSpecificModelsInDatabase) { // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); const int totalNrOfStochasticSoilModelInDatabase = 6; const string expectedAddDataText = "Adding Data"; var filter = mocks.StrictMock <IStochasticSoilModelMechanismFilter>(); filter.Expect(f => f.IsValidForFailureMechanism(null)) .IgnoreArguments() .Return(false) .WhenCalled(invocation => { FilterFailureMechanismSpecificModel(invocation, failureMechanismType); }) .Repeat .Times(totalNrOfStochasticSoilModelInDatabase); var messageProvider = mocks.StrictMock <IImporterMessageProvider>(); messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()) .Return(expectedAddDataText); var updateStrategy = mocks.StrictMock <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >(); updateStrategy.Expect(u => u.UpdateModelWithImportedData(null, null)) .IgnoreArguments() .WhenCalled(invocation => { var soilModels = (IEnumerable <IMechanismStochasticSoilModel>)invocation.Arguments[0]; var filePath = (string)invocation.Arguments[1]; Assert.AreEqual(nrOfFailureMechanismSpecificModelsInDatabase, soilModels.Count()); Assert.AreEqual(validFilePath, filePath); }); mocks.ReplayAll(); var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>( new TestStochasticSoilModelCollection(), validFilePath, messageProvider, new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>( transformer, filter, updateStrategy)); var progressChangeNotifications = new List <ProgressNotification>(); importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps))); // Call var importResult = false; Action call = () => importResult = importer.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{validFilePath}'.", 1); Assert.IsTrue(importResult); var expectedProgressMessages = new List <ProgressNotification> { new ProgressNotification("Inlezen van de D-Soil Model database.", 1, 1) }; for (var i = 1; i <= totalNrOfStochasticSoilModelInDatabase; i++) { expectedProgressMessages.Add(new ProgressNotification( "Inlezen van de stochastische ondergrondmodellen.", i, totalNrOfStochasticSoilModelInDatabase)); } for (var i = 1; i <= nrOfFailureMechanismSpecificModelsInDatabase; i++) { expectedProgressMessages.Add(new ProgressNotification( "Valideren van ingelezen data.", i, nrOfFailureMechanismSpecificModelsInDatabase)); } expectedProgressMessages.Add(new ProgressNotification(expectedAddDataText, 1, 1)); ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages, progressChangeNotifications); }