Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -r990491306518ecad9b61955f972fc5dfc1df144e -r8b5f0a2d2a65af3a54d892810e14e2b0499e8dca --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 8b5f0a2d2a65af3a54d892810e14e2b0499e8dca) @@ -37,7 +37,6 @@ using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.FileImporters; using Ringtoets.Piping.Data; -using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Plugin.FileImporter; namespace Demo.Ringtoets.Commands @@ -152,9 +151,8 @@ using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(GetType().Assembly, true, "DR6.soil")) { - var soilProfilesImporter = new PipingSoilProfilesImporter(); - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, demoAssessmentSection); - soilProfilesImporter.Import(context, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil")); + var soilProfilesImporter = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels); + soilProfilesImporter.Import(null, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil")); } var calculation = new PipingCalculationScenario(pipingFailureMechanism.GeneralInput); Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs =================================================================== diff -u -rf62076c7d8b6a65856fbab6a1b34b4234aa319e5 -r8b5f0a2d2a65af3a54d892810e14e2b0499e8dca --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision f62076c7d8b6a65856fbab6a1b34b4234aa319e5) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision 8b5f0a2d2a65af3a54d892810e14e2b0499e8dca) @@ -24,6 +24,7 @@ using System.Collections.ObjectModel; using System.Drawing; using System.Linq; +using Core.Common.Base; using Core.Common.Base.IO; using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; @@ -45,7 +46,22 @@ public class PipingSoilProfilesImporter : FileImporterBase { private readonly ILog log = LogManager.GetLogger(typeof(PipingSoilProfilesImporter)); + private readonly ObservableList importTarget; + /// + /// Initializes a new instance of the class. + /// + /// The collection to update. + /// Thrown when is null. + public PipingSoilProfilesImporter(ObservableList importTarget) + { + if (importTarget == null) + { + throw new ArgumentNullException("importTarget"); + } + this.importTarget = importTarget; + } + public override string Name { get @@ -88,13 +104,6 @@ public override bool Import(object targetItem, string filePath) { - var stochasticSoilModelContext = (StochasticSoilModelContext) targetItem; - if (!IsReferenceLineAvailable(stochasticSoilModelContext)) - { - log.Error(RingtoetsPluginResources.PipingSoilProfilesImporter_Import_Required_referenceline_missing); - return false; - } - var importSoilProfileResult = ReadSoilProfiles(filePath); if (importSoilProfileResult.CriticalErrorOccurred) { @@ -129,7 +138,7 @@ return false; } - AddImportedDataToModel(stochasticSoilModelContext, importStochasticSoilModelResult.ImportedItems); + AddImportedDataToModel(importStochasticSoilModelResult.ImportedItems); return true; } @@ -162,9 +171,8 @@ return stochasticSoilModels.Any(stochasticSoilModel => stochasticSoilModel.StochasticSoilProfiles.Any(stochasticSoilProfile => stochasticSoilProfile.SoilProfile == soilProfile)); } - private void AddImportedDataToModel(StochasticSoilModelContext target, ICollection readStochasticSoilModels) + private void AddImportedDataToModel(ICollection readStochasticSoilModels) { - var targetCollection = target.WrappedData; var stochasticSoilModelCount = readStochasticSoilModels.Count; var currentIndex = 1; foreach (var readStochasticSoilModel in readStochasticSoilModels) @@ -174,12 +182,12 @@ { continue; } - var stochasticSoilModel = targetCollection.FirstOrDefault(ssm => ssm.Id == readStochasticSoilModel.Id); + var stochasticSoilModel = importTarget.FirstOrDefault(ssm => ssm.Id == readStochasticSoilModel.Id); if (stochasticSoilModel != null) { log.WarnFormat(RingtoetsPluginResources.PipingSoilProfilesImporter_AddImportedDataToModel_Stochastisch_soil_model_0_already_exists, stochasticSoilModel.Name); } - targetCollection.Add(readStochasticSoilModel); + importTarget.Add(readStochasticSoilModel); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -rc43715cf3e6dce0c427b10c4852d5ae54e6d668d -r8b5f0a2d2a65af3a54d892810e14e2b0499e8dca --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision c43715cf3e6dce0c427b10c4852d5ae54e6d668d) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 8b5f0a2d2a65af3a54d892810e14e2b0499e8dca) @@ -90,11 +90,18 @@ CreateFileImporter = context => new PipingSurfaceLinesCsvImporter(context.WrappedData.SurfaceLines, context.AssessmentSection.ReferenceLine) }; - } - public override IEnumerable GetFileImporters() - { - yield return new PipingSoilProfilesImporter(); + yield return new ImportInfo + { + Name = PipingFormsResources.StochasticSoilProfileCollection_DisplayName, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = PipingFormsResources.PipingSoilProfileIcon, + FileFilter = string.Format("{0} {1} (*.soil)|*.soil", + PipingFormsResources.StochasticSoilProfileCollection_DisplayName, + PipingPluginResources.Soil_file_name), + IsEnabled = context => context.AssessmentSection.ReferenceLine != null, + CreateFileImporter = context => new PipingSoilProfilesImporter(context.WrappedData) + }; } public override IEnumerable GetViewInfos() Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/ImportSoilProfileFromDatabaseTest.cs =================================================================== diff -u -rea8d46d1ac88024537a4316b3020b6281986c063 -r8b5f0a2d2a65af3a54d892810e14e2b0499e8dca --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/ImportSoilProfileFromDatabaseTest.cs (.../ImportSoilProfileFromDatabaseTest.cs) (revision ea8d46d1ac88024537a4316b3020b6281986c063) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/ImportSoilProfileFromDatabaseTest.cs (.../ImportSoilProfileFromDatabaseTest.cs) (revision 8b5f0a2d2a65af3a54d892810e14e2b0499e8dca) @@ -21,14 +21,10 @@ using System.IO; using System.Linq; -using Core.Common.Base; using Core.Common.TestUtil; using Deltares.WTIPiping; using NUnit.Framework; -using Rhino.Mocks; -using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Piping.Data; -using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.KernelWrapper; using Ringtoets.Piping.Plugin.FileImporter; using Ringtoets.Piping.Primitives; @@ -47,18 +43,9 @@ string databasePath = Path.Combine(testDataPath, "1dprofile.soil"); var pipingFailureMechanism = new PipingFailureMechanism(); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, assessmentSection); - context.Attach(observer); - // When - var importer = new PipingSoilProfilesImporter(); - importer.Import(context, databasePath); + var importer = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels); + importer.Import(null, databasePath); // Then Assert.AreEqual(1, pipingFailureMechanism.StochasticSoilModels.Count); @@ -80,8 +67,6 @@ 2.2, 1.1 }, pipingProfile.Layers.Select(l => l.TopLevel)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } /// @@ -95,18 +80,9 @@ string databasePath = Path.Combine(testDataPath, "invalid2dGeometry.soil"); var pipingFailureMechanism = new PipingFailureMechanism(); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, assessmentSection); - context.Attach(observer); - // When - var importer = new PipingSoilProfilesImporter(); - importer.Import(context, databasePath); + var importer = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels); + importer.Import(null, databasePath); // Then Assert.AreEqual(1, pipingFailureMechanism.StochasticSoilModels.Count); @@ -128,8 +104,6 @@ 3.75, 2.75 }, pipingProfile.Layers.Select(l => l.TopLevel)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -139,18 +113,9 @@ var databasePath = Path.Combine(testDataPath, "1dprofileNoValues.soil"); var pipingFailureMechanism = new PipingFailureMechanism(); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, assessmentSection); - context.Attach(observer); - // When - var importer = new PipingSoilProfilesImporter(); - importer.Import(context, databasePath); + var importer = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels); + importer.Import(null, databasePath); // Then Assert.AreEqual(1, pipingFailureMechanism.StochasticSoilModels.Count); @@ -167,7 +132,6 @@ 2.2, 1.1 }, pipingProfile.Layers.Select(l => l.TopLevel)); - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs =================================================================== diff -u -r990491306518ecad9b61955f972fc5dfc1df144e -r8b5f0a2d2a65af3a54d892810e14e2b0499e8dca --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision 8b5f0a2d2a65af3a54d892810e14e2b0499e8dca) @@ -130,7 +130,7 @@ true, "DR6.soil")) { - var activity = new FileImportActivity(new PipingSoilProfilesImporter(), + var activity = new FileImportActivity(new PipingSoilProfilesImporter(assessmentSection.PipingFailureMechanism.StochasticSoilModels), new StochasticSoilModelContext(assessmentSection.PipingFailureMechanism.StochasticSoilModels, assessmentSection.PipingFailureMechanism, assessmentSection), Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil")); activity.Run(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs =================================================================== diff -u -rf64dceaa32788bad28dcf09f4a1c3150595f1327 -r8b5f0a2d2a65af3a54d892810e14e2b0499e8dca --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision f64dceaa32788bad28dcf09f4a1c3150595f1327) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision 8b5f0a2d2a65af3a54d892810e14e2b0499e8dca) @@ -45,25 +45,36 @@ public class PipingSoilProfilesImporterTest { private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "PipingSoilProfilesReader"); - private MockRepository mockRepository; private int progress; [SetUp] public void SetUp() { - mockRepository = new MockRepository(); progress = 0; } [Test] - public void DefaultConstructor_ExpectedValues() + public void Constructor_ObservableListNull_ThrowsArgumentNullException() { - // Prepare + // Call + TestDelegate call = () => new PipingSoilProfilesImporter(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("importTarget", paramName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup var expectedFileFilter = string.Format("{0} {1} (*.soil)|*.soil", PipingFormsResources.StochasticSoilProfileCollection_DisplayName, ApplicationResources.Soil_file_name); + var list = new ObservableList(); + // Call - var importer = new PipingSoilProfilesImporter(); + var importer = new PipingSoilProfilesImporter(list); // Assert Assert.IsInstanceOf>(importer); @@ -86,7 +97,7 @@ var targetContext = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - var importer = new PipingSoilProfilesImporter(); + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels); // Call var canImport = importer.CanImportOn(targetContext); @@ -108,7 +119,7 @@ var targetContext = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - var importer = new PipingSoilProfilesImporter(); + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels); // Call var canImport = importer.CanImportOn(targetContext); @@ -125,27 +136,19 @@ var file = "nonexisting.soil"; string validFilePath = Path.Combine(testDataPath, file); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; // Precondition - CollectionAssert.IsEmpty(context.WrappedData); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); var importResult = true; // Call - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert TestHelper.AssertLogMessages(call, messages => @@ -155,10 +158,8 @@ StringAssert.EndsWith(message, messageArray[0]); }); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); Assert.AreEqual(1, progress); - - mockRepository.VerifyAll(); // 'observer' should not be notified } [Test] @@ -168,27 +169,19 @@ var file = "/"; string invalidFilePath = Path.Combine(testDataPath, file); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; // Precondition - CollectionAssert.IsEmpty(context.WrappedData); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); var importResult = true; // Call - Action call = () => importResult = importer.Import(context, invalidFilePath); + Action call = () => importResult = importer.Import(null, invalidFilePath); // Assert TestHelper.AssertLogMessages(call, messages => @@ -198,72 +191,26 @@ StringAssert.EndsWith(message, messageArray[0]); }); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); Assert.AreEqual(1, progress); - - mockRepository.VerifyAll(); // 'observer' should not be notified } [Test] - public void Import_NoReferenceLine_CancelImportWithErrorMessage() - { - // Setup - var file = "file"; - string invalidFilePath = Path.Combine(testDataPath, file); - - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter - { - ProgressChanged = IncrementProgress - }; - - // Precondition - CollectionAssert.IsEmpty(context.WrappedData); - var importResult = true; - - // Call - Action call = () => importResult = importer.Import(context, invalidFilePath); - - // Assert - var expectedMessage = "Er is geen referentielijn beschikbaar. Geen data ingelezen."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); - Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData); - Assert.AreEqual(0, progress); - - mockRepository.VerifyAll(); // 'observer' should not be notified - } - - [Test] public void Import_ImportingToValidTargetWithValidFile_ImportSoilModelToCollection() { // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); - var observer = mockRepository.StrictMock(); var pipingFailureMechanism = new PipingFailureMechanism(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mockRepository.ReplayAll(); var progressChangeNotifications = new List(); - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels) { ProgressChanged = (description, step, steps) => { progressChangeNotifications.Add(new ProgressNotification(description, step, steps)); } }; - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, assessmentSection); - context.Attach(observer); - // Call - var importResult = importer.Import(context, validFilePath); + var importResult = importer.Import(null, validFilePath); // Assert Assert.IsTrue(importResult); @@ -297,8 +244,6 @@ Assert.AreEqual(notification.CurrentStep, actualNotification.CurrentStep); Assert.AreEqual(notification.TotalSteps, actualNotification.TotalSteps); } - - mockRepository.VerifyAll(); } [Test] @@ -307,36 +252,27 @@ // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); - var observer = mockRepository.StrictMock(); var pipingFailureMechanism = new PipingFailureMechanism(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mockRepository.ReplayAll(); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, assessmentSection); - context.Attach(observer); var importResult = false; // Precondition - importer.Import(context, validFilePath); - var alreadyImportedSoilModelNames = context.WrappedData.Select(ssm => ssm.Name); + importer.Import(null, validFilePath); + var alreadyImportedSoilModelNames = pipingFailureMechanism.StochasticSoilModels.Select(ssm => ssm.Name); // Call - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var expectedLogMessages = alreadyImportedSoilModelNames.Select(name => string.Format("Het stochastische ondergrondmodel '{0}' bestaat al in het toetsspoor.", name)).ToArray(); TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, expectedLogMessages.Length); Assert.IsTrue(importResult); Assert.AreEqual(35*2, progress); - - mockRepository.VerifyAll(); } [Test] @@ -345,38 +281,28 @@ // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; // Precondition - CollectionAssert.IsEmpty(context.WrappedData); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); Assert.IsTrue(File.Exists(validFilePath)); importer.Cancel(); var importResult = true; // Call - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert TestHelper.AssertLogMessageIsGenerated(call, ApplicationResources.PipingSoilProfilesImporter_Import_Import_cancelled, 1); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels); Assert.AreEqual(1, progress); - - mockRepository.VerifyAll(); // 'observer' should not be notified } [Test] @@ -385,14 +311,8 @@ // Setup string validFilePath = Path.Combine(testDataPath, "complete.soil"); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; @@ -403,16 +323,15 @@ // Setup (second part) importer.Cancel(); - var importResult = importer.Import(context, validFilePath); + var importResult = importer.Import(null, validFilePath); Assert.IsFalse(importResult); // Call - importResult = importer.Import(context, validFilePath); + importResult = importer.Import(null, validFilePath); // Assert Assert.IsTrue(importResult); Assert.AreEqual(36, progress); - mockRepository.VerifyAll(); } [Test] @@ -421,35 +340,25 @@ // Setup string corruptPath = Path.Combine(testDataPath, "empty.soil"); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; var importResult = true; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath).Build(RingtoetsIOResources.PipingSoilProfileReader_Critical_Unexpected_value_on_column); var expectedLogMessage = string.Format(ApplicationResources.PipingSoilProfilesImporter_CriticalErrorMessage_0_File_Skipped, internalErrorMessage); TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData, "No items should be added to collection when import is aborted."); + CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels, "No items should be added to collection when import is aborted."); Assert.AreEqual(1, progress); - - mockRepository.VerifyAll(); // Expect no calls on 'observer' } [Test] @@ -458,24 +367,16 @@ // Setup string corruptPath = Path.Combine(testDataPath, "invalidAtX2dProperty.soil"); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) @@ -491,10 +392,8 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 2); Assert.IsTrue(importResult); - Assert.AreEqual(0, context.WrappedData.Count); + Assert.AreEqual(0, failureMechanism.StochasticSoilModels.Count); Assert.AreEqual(7, progress); - - mockRepository.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -503,27 +402,17 @@ // Setup string corruptPath = Path.Combine(testDataPath, "incorrectValue2dProperty.soil"); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; // Call - var importResult = importer.Import(context, corruptPath); + var importResult = importer.Import(null, corruptPath); Assert.IsTrue(importResult); - Assert.AreEqual(0, context.WrappedData.Count); - - mockRepository.VerifyAll(); // Ensure there are no calls to UpdateObserver + Assert.AreEqual(0, failureMechanism.StochasticSoilModels.Count); } [Test] @@ -532,33 +421,23 @@ // Setup string validFilePath = Path.Combine(testDataPath, "invalidStochasticSoilProfiles.soil"); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var expectedLogMessage = string.Format("Fout bij het lezen van bestand '{0}': De ondergrondschematisatie verwijst naar een ongeldige waarde." + " Dit stochastische ondergrondmodel wordt overgeslagen.", validFilePath); TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); Assert.AreEqual(0, failureMechanism.StochasticSoilModels.Count); Assert.IsTrue(importResult); - - mockRepository.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -567,32 +446,22 @@ // Setup string validFilePath = Path.Combine(testDataPath, "incorrectProbability.soil"); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var expectedLogMessages = "De som van de kansen van voorkomen in het stochastich ondergrondmodel 'Name' is niet gelijk aan 100%."; TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessages, 1); Assert.AreEqual(1, failureMechanism.StochasticSoilModels.Count); Assert.IsTrue(importResult); - - mockRepository.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -602,16 +471,10 @@ string validFilePath = Path.Combine(testDataPath, "reusedSoilProfile1D.soil"); var pipingFailureMechanism = new PipingFailureMechanism(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mockRepository.ReplayAll(); + var importer = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels); - var importer = new PipingSoilProfilesImporter(); - - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, assessmentSection); - // Call - var importResult = importer.Import(context, validFilePath); + var importResult = importer.Import(null, validFilePath); // Assert Assert.IsTrue(importResult); @@ -632,8 +495,6 @@ "Expected database to have 1D profiles."); Assert.AreEqual(SoilProfileType.SoilProfile1D, profile2.SoilProfileType, "Expected database to have 1D profiles."); - - mockRepository.VerifyAll(); } [Test] @@ -643,16 +504,10 @@ string validFilePath = Path.Combine(testDataPath, "reusedSoilProfile2D.soil"); var pipingFailureMechanism = new PipingFailureMechanism(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mockRepository.ReplayAll(); + var importer = new PipingSoilProfilesImporter(pipingFailureMechanism.StochasticSoilModels); - var importer = new PipingSoilProfilesImporter(); - - var context = new StochasticSoilModelContext(pipingFailureMechanism.StochasticSoilModels, pipingFailureMechanism, assessmentSection); - // Call - var importResult = importer.Import(context, validFilePath); + var importResult = importer.Import(null, validFilePath); // Assert Assert.IsTrue(importResult); @@ -673,8 +528,6 @@ "Expected database to have 2D profiles."); Assert.AreEqual(SoilProfileType.SoilProfile2D, profile2.SoilProfileType, "Expected database to have 2D profiles."); - - mockRepository.VerifyAll(); } [Test] @@ -683,29 +536,19 @@ // Setup string validFilePath = Path.Combine(testDataPath, "EmptySoilModel.soil"); - var observer = mockRepository.StrictMock(); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels); - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSoilProfilesImporter(); - var importResult = false; // Call - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var expectedLogMessage = @"Er zijn geen ondergrondschematisaties gevonden in het stochastische ondergrondmodel 'Model'. Dit model wordt overgeslagen."; TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); Assert.AreEqual(0, failureMechanism.StochasticSoilModels.Count); Assert.IsTrue(importResult); - - mockRepository.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -714,14 +557,8 @@ // Setup string validFilePath = Path.Combine(testDataPath, "SingleSoilProfile2D_noLayerProperties.soil"); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; @@ -731,7 +568,7 @@ Assert.IsTrue(File.Exists(validFilePath)); // Call - bool importResult = importer.Import(context, validFilePath); + bool importResult = importer.Import(null, validFilePath); // Assert Assert.IsTrue(importResult); @@ -768,7 +605,6 @@ profile.Layers.Select(l => l.BelowPhreaticLevelMean)); Assert.AreEqual(6, progress); - mockRepository.VerifyAll(); } [Test] @@ -777,14 +613,8 @@ // Setup string validFilePath = Path.Combine(testDataPath, "SingleSoilProfile2D_withLayerProperties.soil"); - var assessmentSection = mockRepository.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - mockRepository.ReplayAll(); - - var context = new StochasticSoilModelContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); - - var importer = new PipingSoilProfilesImporter + var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels) { ProgressChanged = IncrementProgress }; @@ -794,7 +624,7 @@ Assert.IsTrue(File.Exists(validFilePath)); // Call - bool importResult = importer.Import(context, validFilePath); + bool importResult = importer.Import(null, validFilePath); // Assert Assert.IsTrue(importResult); @@ -855,7 +685,6 @@ profile.Layers.Select(l => l.BelowPhreaticLevelMean)); Assert.AreEqual(6, progress); - mockRepository.VerifyAll(); } private void IncrementProgress(string a, int b, int c) Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingPluginTest.cs =================================================================== diff -u -rc43715cf3e6dce0c427b10c4852d5ae54e6d668d -r8b5f0a2d2a65af3a54d892810e14e2b0499e8dca --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingPluginTest.cs (.../PipingPluginTest.cs) (revision c43715cf3e6dce0c427b10c4852d5ae54e6d668d) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingPluginTest.cs (.../PipingPluginTest.cs) (revision 8b5f0a2d2a65af3a54d892810e14e2b0499e8dca) @@ -33,7 +33,6 @@ using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.PropertyClasses; using Ringtoets.Piping.Forms.Views; -using Ringtoets.Piping.Plugin.FileImporter; using Ringtoets.Piping.Primitives; using PipingPluginResources = Ringtoets.Piping.Plugin.Properties.Resources; using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; @@ -194,34 +193,11 @@ ImportInfo[] importInfos = plugin.GetImportInfos().ToArray(); // Assert - Assert.AreEqual(1, importInfos.Length); + Assert.AreEqual(2, importInfos.Length); Assert.AreEqual(1, importInfos.Count(i => i.DataType == typeof(RingtoetsPipingSurfaceLinesContext))); + Assert.AreEqual(1, importInfos.Count(i => i.DataType == typeof(StochasticSoilModelContext))); } mocks.VerifyAll(); } - - [Test] - public void GetFileImporters_Always_ReturnsExpectedFileImporters() - { - // Setup - var mocks = new MockRepository(); - var guiStub = mocks.Stub(); - guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); - mocks.ReplayAll(); - - using (var plugin = new PipingPlugin - { - Gui = guiStub - }) - { - // Call - var importers = plugin.GetFileImporters().ToArray(); - - // Assert - Assert.AreEqual(1, importers.Length); - Assert.IsInstanceOf(importers[0]); - } - mocks.VerifyAll(); - } } } \ No newline at end of file