Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -re58ce50bf65d8fa430a1ea7c651256a244f5d2b5 -r990491306518ecad9b61955f972fc5dfc1df144e --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision e58ce50bf65d8fa430a1ea7c651256a244f5d2b5) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -146,9 +146,8 @@ using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(GetType().Assembly, true, "DR6_surfacelines.csv", "DR6_surfacelines.krp.csv")) { - var surfaceLinesImporter = new PipingSurfaceLinesCsvImporter(); - var context = new RingtoetsPipingSurfaceLinesContext(pipingFailureMechanism, demoAssessmentSection); - surfaceLinesImporter.Import(context, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6_surfacelines.csv")); + var surfaceLinesImporter = new PipingSurfaceLinesCsvImporter(pipingFailureMechanism.SurfaceLines, demoAssessmentSection.ReferenceLine); + surfaceLinesImporter.Import(null, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6_surfacelines.csv")); } using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(GetType().Assembly, true, "DR6.soil")) Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -rf62076c7d8b6a65856fbab6a1b34b4234aa319e5 -r990491306518ecad9b61955f972fc5dfc1df144e --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision f62076c7d8b6a65856fbab6a1b34b4234aa319e5) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -58,6 +58,24 @@ private const string csvFileExtension = ".csv"; private readonly ILog log = LogManager.GetLogger(typeof(PipingSurfaceLinesCsvImporter)); + private readonly ICollection importTarget; + private readonly ReferenceLine referenceLine; + + public PipingSurfaceLinesCsvImporter(ICollection importTarget, ReferenceLine referenceLine) + { + if (importTarget == null) + { + throw new ArgumentNullException("importTarget"); + } + if (referenceLine == null) + { + throw new ArgumentNullException("referenceLine"); + } + + this.importTarget = importTarget; + this.referenceLine = referenceLine; + } + public override string Name { get @@ -100,14 +118,6 @@ public override bool Import(object targetItem, string filePath) { - if (!IsReferenceLineAvailable(targetItem)) - { - LogCriticalFileReadError(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Import_Required_referenceline_missing); - return false; - } - - var surfaceLinesContext = (RingtoetsPipingSurfaceLinesContext) targetItem; - var importSurfaceLinesResult = ReadPipingSurfaceLines(filePath); if (importSurfaceLinesResult.CriticalErrorOccurred) { @@ -132,7 +142,7 @@ return false; } - AddImportedDataToModel(surfaceLinesContext, importSurfaceLinesResult.ImportedItems, importCharacteristicPointsResult.ImportedItems); + AddImportedDataToModel(importSurfaceLinesResult.ImportedItems, importCharacteristicPointsResult.ImportedItems); return true; } @@ -149,27 +159,19 @@ return new ReadResult(true); } - private void LogCriticalFileReadError(string message) + private void AddImportedDataToModel(ICollection readSurfaceLines, ICollection readCharacteristicPointsLocations) { - var errorMessage = string.Format(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_No_sections_imported, - message); - log.Error(errorMessage); - } - - private void AddImportedDataToModel(RingtoetsPipingSurfaceLinesContext target, ICollection readSurfaceLines, ICollection readCharacteristicPointsLocations) - { NotifyProgress(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Adding_imported_data_to_model, 0, readSurfaceLines.Count); log.Info(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Start_adding_surface_lines); - var targetCollection = target.WrappedData.SurfaceLines; List readCharacteristicPointsLocationNames = readCharacteristicPointsLocations.Select(cpl => cpl.Name).ToList(); int surfaceLineNumber = 1; foreach (var readSurfaceLine in readSurfaceLines) { NotifyProgress(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Adding_imported_data_to_model, surfaceLineNumber++, readSurfaceLines.Count); - ReferenceLineIntersectionResult result = CheckReferenceLineInterSections(readSurfaceLine, target.AssessmentSection.ReferenceLine); + ReferenceLineIntersectionResult result = CheckReferenceLineInterSections(readSurfaceLine); if (result.TypeOfIntersection != ReferenceLineIntersectionsResult.OneIntersection) { continue; @@ -192,7 +194,7 @@ log.WarnFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_No_characteristic_points_for_SurfaceLine_0_, readSurfaceLine.Name); } - targetCollection.Add(readSurfaceLine); + importTarget.Add(readSurfaceLine); } foreach (string name in readCharacteristicPointsLocationNames) { @@ -221,7 +223,7 @@ return true; } - private ReferenceLineIntersectionResult CheckReferenceLineInterSections(RingtoetsPipingSurfaceLine readSurfaceLine, ReferenceLine referenceLine) + private ReferenceLineIntersectionResult CheckReferenceLineInterSections(RingtoetsPipingSurfaceLine readSurfaceLine) { ReferenceLineIntersectionResult result = GetReferenceLineIntersections(referenceLine, readSurfaceLine); Fisheye: Tag 990491306518ecad9b61955f972fc5dfc1df144e refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingFileImporterProvider.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -r776558d53b8a73cf16bdd5b50ff4d1eeff933b2f -r990491306518ecad9b61955f972fc5dfc1df144e --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 776558d53b8a73cf16bdd5b50ff4d1eeff933b2f) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -48,6 +48,7 @@ using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; +using PipingPluginResources = Ringtoets.Piping.Plugin.Properties.Resources; using BaseResources = Core.Common.Base.Properties.Resources; namespace Ringtoets.Piping.Plugin @@ -75,9 +76,24 @@ yield return new PropertyInfo(); } + public override IEnumerable GetImportInfos() + { + yield return new ImportInfo + { + Name = PipingFormsResources.PipingSurfaceLinesCollection_DisplayName, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = PipingFormsResources.PipingSurfaceLineIcon, + FileFilter = string.Format("{0} {1} (*.csv)|*.csv", + PipingFormsResources.PipingSurfaceLinesCollection_DisplayName, + PipingPluginResources.Csv_file_name), + IsEnabled = context => context.AssessmentSection.ReferenceLine != null, + CreateFileImporter = context => new PipingSurfaceLinesCsvImporter(context.WrappedData.SurfaceLines, + context.AssessmentSection.ReferenceLine) + }; + } + public override IEnumerable GetFileImporters() { - yield return new PipingSurfaceLinesCsvImporter(); yield return new PipingSoilProfilesImporter(); } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj =================================================================== diff -u -rb1b25abeb595bff11389bbf0e695851995ef5221 -r990491306518ecad9b61955f972fc5dfc1df144e --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision b1b25abeb595bff11389bbf0e695851995ef5221) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -62,7 +62,6 @@ - True Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs =================================================================== diff -u -re58ce50bf65d8fa430a1ea7c651256a244f5d2b5 -r990491306518ecad9b61955f972fc5dfc1df144e --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision e58ce50bf65d8fa430a1ea7c651256a244f5d2b5) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -111,7 +111,7 @@ "DR6_surfacelines.csv", "DR6_surfacelines.krp.csv")) { - var activity = new FileImportActivity(new PipingSurfaceLinesCsvImporter(), + var activity = new FileImportActivity(new PipingSurfaceLinesCsvImporter(assessmentSection.PipingFailureMechanism.SurfaceLines, assessmentSection.ReferenceLine), new RingtoetsPipingSurfaceLinesContext(assessmentSection.PipingFailureMechanism, assessmentSection), Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6_surfacelines.csv")); activity.Run(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs =================================================================== diff -u -r99f3b343f5ac4aed453d9f6d291217de76ef5314 -r990491306518ecad9b61955f972fc5dfc1df144e --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 99f3b343f5ac4aed453d9f6d291217de76ef5314) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -20,10 +20,10 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Base.IO; using Core.Common.TestUtil; @@ -56,8 +56,11 @@ [Test] public void DefaultConstructor_ExpectedValues() { + var list = new List(); + var referenceLine = new ReferenceLine(); + // Call - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(list, referenceLine); // Assert Assert.IsInstanceOf>(importer); @@ -83,7 +86,7 @@ var targetContext = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, assessmentSection.ReferenceLine); // Call bool canImport = importer.CanImportOn(targetContext); @@ -106,7 +109,7 @@ var targetContext = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); // Call bool canImport = importer.CanImportOn(targetContext); @@ -117,35 +120,6 @@ } [Test] - public void Import_NoReferenceLine_CancelImportWithErrorMessage() - { - // Setup - var twovalidsurfacelinesCsv = "TwoValidSurfaceLines.csv"; - string validFilePath = Path.Combine(ioTestDataPath, twovalidsurfacelinesCsv); - - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var failureMechanism = new PipingFailureMechanism(); - - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - - var importer = new PipingSurfaceLinesCsvImporter(); - - // Call - bool importSuccessful = true; - Action call = () => importSuccessful = importer.Import(context, validFilePath); - - // Assert - var expectedMessage = "Er is geen referentielijn beschikbaar om profielschematisaties voor te definiëren. Er zijn geen profielschematisaties geïmporteerd."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); - Assert.IsFalse(importSuccessful); - CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); - mocks.VerifyAll(); - } - - [Test] public void Import_ImportingToValidTargetWithValidFile_ImportSurfaceLinesToCollection() { // Setup @@ -162,63 +136,57 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter(); int callCount = 0; bool progressStarted = false; bool progressCharacteristicPointsStarted = false; - importer.ProgressChanged = delegate(string currentStepName, int currentStep, int totalNumberOfSteps) + + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine) { - if (!progressStarted && callCount == 0) + ProgressChanged = delegate(string currentStepName, int currentStep, int totalNumberOfSteps) { - progressStarted = true; - Assert.AreEqual(PipingPluginResources.PipingSurfaceLinesCsvImporter_Reading_surface_line_file, currentStepName); - return; - } - if (!progressCharacteristicPointsStarted && callCount == expectedNumberOfSurfaceLines + 1) - { - progressCharacteristicPointsStarted = true; - Assert.AreEqual(PipingPluginResources.PipingSurfaceLinesCsvImporter_Reading_characteristic_points_file, currentStepName); - return; - } + if (!progressStarted && callCount == 0) + { + progressStarted = true; + Assert.AreEqual(PipingPluginResources.PipingSurfaceLinesCsvImporter_Reading_surface_line_file, currentStepName); + return; + } + if (!progressCharacteristicPointsStarted && callCount == expectedNumberOfSurfaceLines + 1) + { + progressCharacteristicPointsStarted = true; + Assert.AreEqual(PipingPluginResources.PipingSurfaceLinesCsvImporter_Reading_characteristic_points_file, currentStepName); + return; + } - if (callCount <= expectedNumberOfSurfaceLines) - { - Assert.AreEqual(string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_Read_PipingSurfaceLines_0_, twovalidsurfacelinesCsv), currentStepName); - } - else if (callCount <= expectedNumberOfSurfaceLines + 1 + expectedNumberOfSurfaceLines) - { - Assert.AreEqual(PipingPluginResources.PipingSurfaceLinesCsvImporter_Adding_imported_data_to_model, currentStepName); - } - else - { - Assert.Fail("Not expecting progress: \"{0}: {1} out of {2}\".", currentStepName, currentStep, totalNumberOfSteps); - } + if (callCount <= expectedNumberOfSurfaceLines) + { + Assert.AreEqual(string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_Read_PipingSurfaceLines_0_, twovalidsurfacelinesCsv), currentStepName); + } + else if (callCount <= expectedNumberOfSurfaceLines + 1 + expectedNumberOfSurfaceLines) + { + Assert.AreEqual(PipingPluginResources.PipingSurfaceLinesCsvImporter_Adding_imported_data_to_model, currentStepName); + } + else + { + Assert.Fail("Not expecting progress: \"{0}: {1} out of {2}\".", currentStepName, currentStep, totalNumberOfSteps); + } - Assert.AreEqual(expectedNumberOfSurfaceLines, totalNumberOfSteps); - callCount++; + Assert.AreEqual(expectedNumberOfSurfaceLines, totalNumberOfSteps); + callCount++; + } }; // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); // Call - bool importResult = importer.Import(context, validFilePath); + bool importResult = importer.Import(null, validFilePath); // Assert Assert.IsTrue(importResult); - var importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + var importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.AreEqual(expectedNumberOfSurfaceLines, importTargetArray.Length); // Sample some of the imported data: @@ -237,8 +205,6 @@ Assert.AreEqual(6, callCount); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -255,26 +221,17 @@ new Point2D(94270, 427850) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); // Call bool importResult = false; - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var mesages = new[] @@ -292,7 +249,7 @@ TestHelper.AssertLogMessagesAreGenerated(call, mesages, 6); Assert.IsTrue(importResult); - var importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + var importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.AreEqual(1, importTargetArray.Length); // Sample some of the imported data: @@ -309,8 +266,6 @@ AssertAreEqualPoint2D(new Point2D(94270.0, 427795.313769642), firstSurfaceLine.ReferenceLineIntersectionWorldPoint); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -319,36 +274,26 @@ // Setup string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv"); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - + var referenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); importer.Cancel(); bool importResult = true; // Call - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert TestHelper.AssertLogMessageIsGenerated(call, PipingPluginResources.PipingSurfaceLinesCsvImporter_Import_Import_cancelled, 3); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); - - mocks.VerifyAll(); // 'observer' should not be notified + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); } [Test] @@ -367,36 +312,26 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); // 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); - RingtoetsPipingSurfaceLine[] importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + RingtoetsPipingSurfaceLine[] importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.AreEqual(expectedNumberOfSurfaceLines, importTargetArray.Length); - mocks.VerifyAll(); } [Test] @@ -406,23 +341,14 @@ string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv"); string corruptPath = validFilePath.Replace('S', Path.GetInvalidPathChars().First()); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - bool importResult = true; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath).Build(string.Format(UtilsResources.Error_Path_cannot_contain_Characters_0_, @@ -431,9 +357,8 @@ internalErrorMessage); TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } [Test] @@ -442,23 +367,14 @@ // Setup string corruptPath = Path.Combine(ioTestDataPath, "I_dont_exists.csv"); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - var importResult = true; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath).Build(UtilsResources.Error_File_does_not_exist); @@ -473,9 +389,8 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 3); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } [Test] @@ -484,23 +399,14 @@ // Setup string corruptPath = Path.Combine(ioTestDataPath, "empty.csv"); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - var importResult = true; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) @@ -517,9 +423,8 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 3); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } [Test] @@ -528,23 +433,14 @@ // Setup string corruptPath = Path.Combine(ioTestDataPath, "InvalidHeader_LacksY1.csv"); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - bool importResult = true; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) @@ -561,9 +457,8 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 3); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } [Test] @@ -576,18 +471,9 @@ try { - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()) { ProgressChanged = (name, step, steps) => { @@ -599,7 +485,7 @@ var importResult = true; // Call - Action call = () => importResult = importer.Import(context, copyTargetPath); + Action call = () => importResult = importer.Import(null, copyTargetPath); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(copyTargetPath).Build(UtilsResources.Error_File_does_not_exist); @@ -614,9 +500,8 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 3); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } finally { @@ -643,23 +528,14 @@ new Point2D(94270, 427900) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - var importResult = true; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert string duplicateDefinitionMessage = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Duplicate_definitions_for_same_location_0_, @@ -679,11 +555,10 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 6); Assert.IsTrue(importResult); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count, + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count, "Ensure only the one valid surfaceline has been imported."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); - Assert.AreEqual(3, context.WrappedData.SurfaceLines.First(sl => sl.Name == "Rotterdam1").Points.Length, "First line should have been added to the model."); - mocks.VerifyAll(); // Expect no calls on 'observer' + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); + Assert.AreEqual(3, failureMechanism.SurfaceLines.First(sl => sl.Name == "Rotterdam1").Points.Length, "First line should have been added to the model."); } [Test] @@ -701,25 +576,16 @@ new Point2D(9.8, 1) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); int progressCallCount = 0; importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, corruptPath); + Action call = () => importResult = importer.Import(null, corruptPath); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) @@ -743,10 +609,10 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 6); Assert.IsTrue(importResult); - Assert.AreEqual(2, context.WrappedData.SurfaceLines.Count, + Assert.AreEqual(2, failureMechanism.SurfaceLines.Count, "Ensure only the two valid surfacelines have been imported."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); Assert.AreEqual(9, progressCallCount, new StringBuilder() @@ -759,7 +625,6 @@ .AppendLine("-- +") .AppendLine("9") .ToString()); - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -769,26 +634,17 @@ var twovalidsurfacelinesCsv = "InvalidRow_DuplicatePointsCausingRecline.csv"; string path = Path.Combine(ioTestDataPath, twovalidsurfacelinesCsv); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(path)); // Call var importResult = false; - Action call = () => importResult = importer.Import(context, path); + Action call = () => importResult = importer.Import(null, path); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(path) @@ -810,12 +666,10 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 6); Assert.IsTrue(importResult); - RingtoetsPipingSurfaceLine[] importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + RingtoetsPipingSurfaceLine[] importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.AreEqual(0, importTargetArray.Length); Assert.IsTrue(TestHelper.CanOpenFileForWrite(path)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -825,26 +679,17 @@ var twovalidsurfacelinesCsv = "InvalidRow_DuplicatePointsCausingZeroLength.csv"; string path = Path.Combine(ioTestDataPath, twovalidsurfacelinesCsv); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(path)); // Call var importResult = false; - Action call = () => importResult = importer.Import(context, path); + Action call = () => importResult = importer.Import(null, path); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(path) @@ -866,12 +711,10 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 6); Assert.IsTrue(importResult); - var importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + var importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.AreEqual(0, importTargetArray.Length); Assert.IsTrue(TestHelper.CanOpenFileForWrite(path)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -880,36 +723,25 @@ // Setup string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv"); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); 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, PipingPluginResources.PipingSurfaceLinesCsvImporter_Import_Import_cancelled, 3); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); - - mocks.VerifyAll(); // 'observer' should not be notified + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); } [Test] @@ -929,35 +761,25 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - var importResult = true; // Precondition Assert.IsTrue(File.Exists(surfaceLinesFile)); Assert.IsFalse(File.Exists(nonExistingCharacteristicFile)); // Call - Action call = () => importResult = importer.Import(context, surfaceLinesFile); + Action call = () => importResult = importer.Import(null, surfaceLinesFile); // Assert var expectedLogMessage = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, nonExistingCharacteristicFile); TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 5); Assert.IsTrue(importResult); - Assert.AreEqual(2, context.WrappedData.SurfaceLines.Count); - mocks.VerifyAll(); // Expect no calls on 'observer' + Assert.AreEqual(2, failureMechanism.SurfaceLines.Count); } [Test] @@ -968,23 +790,14 @@ string surfaceLinesFile = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - var importResult = true; // Call - Action call = () => importResult = importer.Import(context, surfaceLinesFile); + Action call = () => importResult = importer.Import(null, surfaceLinesFile); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) @@ -1006,9 +819,8 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 5); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } [Test] @@ -1019,23 +831,14 @@ string surfaceLinesFile = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()); - var importer = new PipingSurfaceLinesCsvImporter(); - var importResult = true; // Call - Action call = () => importResult = importer.Import(context, surfaceLinesFile); + Action call = () => importResult = importer.Import(null, surfaceLinesFile); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) @@ -1058,9 +861,8 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 5); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } [Test] @@ -1079,18 +881,9 @@ try { - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = new ReferenceLine(); - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine()) { ProgressChanged = (name, step, steps) => { @@ -1106,7 +899,7 @@ var importResult = true; // Call - Action call = () => importResult = importer.Import(context, copyTargetPath); + Action call = () => importResult = importer.Import(null, copyTargetPath); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(copyCharacteristicPointsTargetPath).Build(UtilsResources.Error_File_does_not_exist); @@ -1125,9 +918,8 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 5); Assert.IsFalse(importResult); - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines, + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines, "No items should be added to collection when import is aborted."); - mocks.VerifyAll(); // Expect no calls on 'observer' } finally { @@ -1161,23 +953,14 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - var importResult = true; // Call - Action call = () => importResult = importer.Import(context, surfaceLinesFile); + Action call = () => importResult = importer.Import(null, surfaceLinesFile); // Assert string duplicateDefinitionMessage = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_Duplicate_definitions_for_same_characteristic_point_location_0_, @@ -1199,12 +982,11 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 7); Assert.IsTrue(importResult); - Assert.AreEqual(2, context.WrappedData.SurfaceLines.Count, + Assert.AreEqual(2, failureMechanism.SurfaceLines.Count, "Ensure only the two valid surfacelines have been imported."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); - Assert.AreEqual(-1.02, context.WrappedData.SurfaceLines.First(sl => sl.Name == "Rotterdam1").DitchPolderSide.Z, "First characteristic points definition should be added to data model."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); - mocks.VerifyAll(); // Expect no calls on 'observer' + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); + Assert.AreEqual(-1.02, failureMechanism.SurfaceLines.First(sl => sl.Name == "Rotterdam1").DitchPolderSide.Z, "First characteristic points definition should be added to data model."); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); } [Test] @@ -1224,25 +1006,16 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); int progressCallCount = 0; importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, surfaceLinesFile); + Action call = () => importResult = importer.Import(null, surfaceLinesFile); // Assert string internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) @@ -1269,10 +1042,10 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 8); Assert.IsTrue(importResult); - Assert.AreEqual(2, context.WrappedData.SurfaceLines.Count, + Assert.AreEqual(2, failureMechanism.SurfaceLines.Count, "Ensure only the two valid surfacelines have been imported."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "Rotterdam1Invalid")); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "Rotterdam1Invalid")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); Assert.AreEqual(11, progressCallCount, new StringBuilder() @@ -1286,7 +1059,6 @@ .AppendLine("-- +") .AppendLine("11") .ToString()); - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -1306,25 +1078,16 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); int progressCallCount = 0; importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, surfaceLinesPath); + Action call = () => importResult = importer.Import(null, surfaceLinesPath); // Assert string[] expectedLogMessages = @@ -1345,10 +1108,10 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 7); Assert.IsTrue(importResult); - Assert.AreEqual(2, context.WrappedData.SurfaceLines.Count, + Assert.AreEqual(2, failureMechanism.SurfaceLines.Count, "Ensure only the two valid surfacelines have been imported."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); Assert.AreEqual(10, progressCallCount, new StringBuilder() @@ -1362,7 +1125,6 @@ .AppendLine("-- +") .AppendLine("10") .ToString()); - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -1382,25 +1144,16 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); int progressCallCount = 0; importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, surfaceLinesPath); + Action call = () => importResult = importer.Import(null, surfaceLinesPath); // Assert string[] expectedLogMessages = @@ -1421,10 +1174,10 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 7); Assert.IsTrue(importResult); - Assert.AreEqual(2, context.WrappedData.SurfaceLines.Count, + Assert.AreEqual(2, failureMechanism.SurfaceLines.Count, "Ensure only the two valid surfacelines have been imported."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "Rotterdam1")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); Assert.AreEqual(12, progressCallCount, new StringBuilder() @@ -1438,7 +1191,6 @@ .AppendLine("-- +") .AppendLine("12") .ToString()); - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -1463,25 +1215,16 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); int progressCallCount = 0; importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var importResult = false; // Call - Action call = () => importResult = importer.Import(context, surfaceLinesPath); + Action call = () => importResult = importer.Import(null, surfaceLinesPath); // Assert var pointFormat = string.Format(PipingDataResources.RingtoetsPipingSurfaceLine_SetCharacteristicPointAt_Geometry_does_not_contain_point_at_0_to_assign_as_characteristic_point_1_, @@ -1506,10 +1249,10 @@ TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages); Assert.IsTrue(importResult); - Assert.AreEqual(2, context.WrappedData.SurfaceLines.Count, + Assert.AreEqual(2, failureMechanism.SurfaceLines.Count, "Ensure only the two valid surfacelines have been imported."); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "Rotterdam1Invalid")); - Assert.AreEqual(1, context.WrappedData.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "Rotterdam1Invalid")); + Assert.AreEqual(1, failureMechanism.SurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); Assert.AreEqual(11, progressCallCount, new StringBuilder() @@ -1523,7 +1266,6 @@ .AppendLine("-- +") .AppendLine("11") .ToString()); - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -1549,18 +1291,9 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); - - var importer = new PipingSurfaceLinesCsvImporter(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); int callCount = 0; bool progressStarted = false; bool progressCharacteristicPointsStarted = false; @@ -1601,16 +1334,16 @@ }; // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validSurfaceLinesFilePath)); Assert.IsTrue(File.Exists(validCharacteristicPointsFilePath)); // Call - bool importResult = importer.Import(context, validSurfaceLinesFilePath); + bool importResult = importer.Import(null, validSurfaceLinesFilePath); // Assert Assert.IsTrue(importResult); - RingtoetsPipingSurfaceLine[] importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + RingtoetsPipingSurfaceLine[] importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.AreEqual(expectedNumberOfSurfaceLines, importTargetArray.Length); // Sample some of the imported data: @@ -1640,8 +1373,6 @@ Assert.IsTrue(TestHelper.CanOpenFileForWrite(validSurfaceLinesFilePath)); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validCharacteristicPointsFilePath)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -1659,31 +1390,22 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); // Call var importResult = false; - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var mesagge = "Profielschematisatie ArtifcialLocal doorkruist de huidige referentielijn niet of op meer dan 1 punt en kan niet worden geïmporteerd. Dit kan komen doordat de profielschematisatie een lokaal coördinaatsysteem heeft."; TestHelper.AssertLogMessageIsGenerated(call, mesagge); - RingtoetsPipingSurfaceLine[] importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + RingtoetsPipingSurfaceLine[] importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.IsTrue(importResult); Assert.AreEqual(expectedNumberOfSurfaceLines, importTargetArray.Length); @@ -1694,8 +1416,6 @@ Assert.AreEqual(427776.654093, firstSurfaceLine.StartingWorldPoint.Y); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -1717,31 +1437,22 @@ new Point2D(94271, 427813) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); // Call var importResult = false; - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var mesagge = "Profielschematisatie Rotterdam1 doorkruist de huidige referentielijn niet of op meer dan 1 punt en kan niet worden geïmporteerd."; TestHelper.AssertLogMessageIsGenerated(call, mesagge); - RingtoetsPipingSurfaceLine[] importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + RingtoetsPipingSurfaceLine[] importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.IsTrue(importResult); Assert.AreEqual(expectedNumberOfSurfaceLines, importTargetArray.Length); @@ -1752,8 +1463,6 @@ Assert.AreEqual(0.0, firstSurfaceLine.StartingWorldPoint.Y); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); - - mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -1773,43 +1482,32 @@ new Point2D(94270, 427812.08) }); - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - assessmentSection.ReferenceLine = referenceLine; - mocks.ReplayAll(); - var failureMechanism = new PipingFailureMechanism(); - var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); - context.Attach(observer); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine); - var importer = new PipingSurfaceLinesCsvImporter(); - // Precondition - CollectionAssert.IsEmpty(context.WrappedData.SurfaceLines); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); Assert.IsTrue(File.Exists(validFilePath)); // Call var importResult = false; - Action call = () => importResult = importer.Import(context, validFilePath); + Action call = () => importResult = importer.Import(null, validFilePath); // Assert var message = string.Format(PipingPluginResources.PipingSurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, "ArtifcialLocal"); TestHelper.AssertLogMessageIsGenerated(call, message); Assert.IsTrue(importResult); - RingtoetsPipingSurfaceLine[] importTargetArray = context.WrappedData.SurfaceLines.ToArray(); + RingtoetsPipingSurfaceLine[] importTargetArray = failureMechanism.SurfaceLines.ToArray(); Assert.AreEqual(1, importTargetArray.Length); // Sample some of the imported data: RingtoetsPipingSurfaceLine firstSurfaceLine = importTargetArray[0]; Assert.AreEqual("Rotterdam1", firstSurfaceLine.Name); Assert.AreEqual(8, firstSurfaceLine.Points.Length); Assert.AreEqual(427776.654093, firstSurfaceLine.StartingWorldPoint.Y); - - mocks.VerifyAll(); // No observer notified } private static void AssertAreEqualPoint2D(Point2D expectedPoint, Point2D actualPoint) Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/RingtoetsPipingSurfaceLinesContextImportInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/RingtoetsPipingSurfaceLinesContextImportInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ImportInfos/RingtoetsPipingSurfaceLinesContextImportInfoTest.cs (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -0,0 +1,172 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Drawing; +using System.IO; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.Base.IO; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.PresentationObjects; +using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; + +namespace Ringtoets.Piping.Plugin.Test.ImportInfos +{ + [TestFixture] + public class RingtoetsPipingSurfaceLinesContextImportInfoTest + { + private ImportInfo importInfo; + private PipingPlugin plugin; + + [SetUp] + public void SetUp() + { + plugin = new PipingPlugin(); + importInfo = plugin.GetImportInfos().First(i => i.DataType == typeof(RingtoetsPipingSurfaceLinesContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Name_Always_ReturnExpectedName() + { + // Call + string name = importInfo.Name; + + // Assert + Assert.AreEqual("Profielschematisaties", name); + } + + [Test] + public void Category_Always_ReturnExpectedCategory() + { + // Call + string category = importInfo.Category; + + // Assert + Assert.AreEqual("Algemeen", category); + } + + [Test] + public void Image_Always_ReturnExpectedIcon() + { + // Call + Image image = importInfo.Image; + + // Assert + TestHelper.AssertImagesAreEqual(PipingFormsResources.PipingSurfaceLineIcon, image); + } + + [Test] + public void IsEnabled_ReferenceLineNull_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = null; + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); + + // Call + bool isEnabled = importInfo.IsEnabled(context); + + // Assert + Assert.IsFalse(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void IsEnabled_ReferenceLineSet_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + var context = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); + + // Call + bool isEnabled = importInfo.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void FileFilter_Always_ReturnExpectedFileFilter() + { + // Call + string fileFilter = importInfo.FileFilter; + + // Assert + Assert.AreEqual("Profielschematisaties Kommagescheiden bestand (*.csv)|*.csv", fileFilter); + } + + [Test] + public void CreateFileImporter_ValidInput_SuccesfullImport() + { + // Setup + var filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, + Path.Combine("SurfaceLines", "TwoValidSurfaceLines.csv")); + + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = referenceLine; + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + var importTarget = new RingtoetsPipingSurfaceLinesContext(failureMechanism, assessmentSection); + + // Call + IFileImporter importer = importInfo.CreateFileImporter(importTarget); + + // Assert + Assert.IsTrue(importer.Import(null, filePath)); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Fisheye: Tag 990491306518ecad9b61955f972fc5dfc1df144e refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingFileImporterProviderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingPluginTest.cs =================================================================== diff -u -rf64dceaa32788bad28dcf09f4a1c3150595f1327 -r990491306518ecad9b61955f972fc5dfc1df144e --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingPluginTest.cs (.../PipingPluginTest.cs) (revision f64dceaa32788bad28dcf09f4a1c3150595f1327) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingPluginTest.cs (.../PipingPluginTest.cs) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -176,6 +176,30 @@ } [Test] + public void GetFileInfos_Always_ReturnsExpectedFileInfos() + { + // 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 + ImportInfo[] importInfos = plugin.GetImportInfos().ToArray(); + + // Assert + Assert.AreEqual(1, importInfos.Length); + Assert.AreEqual(1, importInfos.Count(i => i.DataType == typeof(RingtoetsPipingSurfaceLinesContext))); + } + mocks.VerifyAll(); + } + + [Test] public void GetFileImporters_Always_ReturnsExpectedFileImporters() { // Setup @@ -193,9 +217,8 @@ var importers = plugin.GetFileImporters().ToArray(); // Assert - Assert.AreEqual(2, importers.Length); - Assert.IsInstanceOf(importers[0]); - Assert.IsInstanceOf(importers[1]); + Assert.AreEqual(1, importers.Length); + Assert.IsInstanceOf(importers[0]); } mocks.VerifyAll(); } Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj =================================================================== diff -u -rb1b25abeb595bff11389bbf0e695851995ef5221 -r990491306518ecad9b61955f972fc5dfc1df144e --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision b1b25abeb595bff11389bbf0e695851995ef5221) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 990491306518ecad9b61955f972fc5dfc1df144e) @@ -65,7 +65,7 @@ - +