Index: Core/Common/src/Core.Common.Base/Core.Common.Base.csproj =================================================================== diff -u -rc6dd26c14af11a7e13f783f578466e46b463165a -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision c6dd26c14af11a7e13f783f578466e46b463165a) +++ Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -89,6 +89,7 @@ + Index: Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (revision 0) +++ Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; + +namespace Core.Common.Base.IO +{ + /// + /// Abstract class for file importers, providing an implementation of sending object + /// change notifications for objects that have been affected + /// during the import. + /// + /// + public abstract class FileImporterBase : IFileImporter + { + public abstract string Name { get; } + public abstract string Category { get; } + public abstract Bitmap Image { get; } + public abstract Type SupportedItemType { get; } + public abstract string FileFilter { get; } + public abstract ProgressChangedDelegate ProgressChanged { protected get; set; } + + public abstract bool Import(object targetItem, string filePath); + + public abstract void Cancel(); + + public void DoPostImportUpdates(object targetItem) + { + var observableTarget = targetItem as IObservable; + if (observableTarget != null) + { + observableTarget.NotifyObservers(); + } + + foreach (var changedObservableObject in GetAffectedNonTargetObservableInstances()) + { + changedObservableObject.NotifyObservers(); + } + } + + /// + /// Returns all objects that have been affected during the call + /// that implement and which are were not the targeted object + /// to import the data to. + /// + /// If no changes were made to the data model (for example during a cancel), + /// no elements should be returned by the implementer. + protected virtual IEnumerable GetAffectedNonTargetObservableInstances() + { + return Enumerable.Empty(); + } + } +} \ No newline at end of file Index: Core/Common/src/Core.Common.Base/IO/IFileImporter.cs =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Core/Common/src/Core.Common.Base/IO/IFileImporter.cs (.../IFileImporter.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Core/Common/src/Core.Common.Base/IO/IFileImporter.cs (.../IFileImporter.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -77,5 +77,14 @@ /// This method cancels an import. /// void Cancel(); + + /// + /// Notifies all observers of instances that have been + /// changed during the import. + /// + /// The item on which the import has been performed upon. + /// This method should be called by caller who calls + /// on this importer. + void DoPostImportUpdates(object targetItem); } } \ No newline at end of file Index: Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs (.../FileImportActivity.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs (.../FileImportActivity.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -89,11 +89,7 @@ protected override void OnFinish() { - var observableTarget = target as IObservable; - if (observableTarget != null) - { - observableTarget.NotifyObservers(); - } + fileImporter.DoPostImportUpdates(target); } } } \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj =================================================================== diff -u -r985570095b487598c6c2ae93b92e2bce65bf7e90 -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90) +++ Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -77,6 +77,7 @@ + Index: Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs (revision 0) +++ Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Drawing; + +using Core.Common.Base.IO; + +using NUnit.Framework; + +using Rhino.Mocks; + +namespace Core.Common.Base.Test.IO +{ + [TestFixture] + public class FileImporterBaseTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + + // Call + var simpleImporter = new SimpleFileImporter(); + + // Assert + Assert.IsInstanceOf(simpleImporter); + } + + [Test] + public void DoPostImportUpdates_TargetIsObservable_NotifyObservers() + { + // Setup + var mocks = new MockRepository(); + var observableInstance = mocks.Stub(); + observableInstance.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var simpleImporter = new SimpleFileImporter(); + + // Call + simpleImporter.DoPostImportUpdates(observableInstance); + + // Assert + mocks.VerifyAll(); // Assert NotifyObservers is called + } + + [Test] + public void DoPostImportUpdates_HasAffectedOtherObjects_NotifyObservers() + { + // Setup + var mocks = new MockRepository(); + var observableInstance = mocks.Stub(); + observableInstance.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var simpleImporter = new SimpleFileImporter(); + simpleImporter.GetAffectedNonTargetObservableInstancesOverride = new[] + { + observableInstance + }; + + // Call + simpleImporter.DoPostImportUpdates(new object()); + + // Assert + mocks.VerifyAll(); // Assert NotifyObservers is called + } + + private class SimpleFileImporter : FileImporterBase + { + public override string Name + { + get + { + throw new NotImplementedException(); + } + } + + public override string Category + { + get + { + throw new NotImplementedException(); + } + } + + public override Bitmap Image + { + get + { + throw new NotImplementedException(); + } + } + + public override Type SupportedItemType + { + get + { + throw new NotImplementedException(); + } + } + + public override string FileFilter + { + get + { + throw new NotImplementedException(); + } + } + + public override ProgressChangedDelegate ProgressChanged { protected get; set; } + public IObservable[] GetAffectedNonTargetObservableInstancesOverride { get; set; } + + protected override IEnumerable GetAffectedNonTargetObservableInstances() + { + return GetAffectedNonTargetObservableInstancesOverride ?? base.GetAffectedNonTargetObservableInstances(); + } + + public override bool Import(object targetItem, string filePath) + { + throw new NotImplementedException(); + } + + public override void Cancel() + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs =================================================================== diff -u -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs (.../FileImportActivityTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) +++ Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs (.../FileImportActivityTest.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -142,7 +142,6 @@ { // Setup var mocks = new MockRepository(); - var fileImporter = mocks.Stub(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); @@ -151,7 +150,7 @@ var target = new ObservableList(); target.Attach(observer); - + var fileImporter = new SimpleFileImporter(); var fileImportActivity = new FileImportActivity(fileImporter, target, ""); // Call @@ -161,51 +160,51 @@ mocks.VerifyAll(); } - private class SimpleFileImporter : IFileImporter + private class SimpleFileImporter : FileImporterBase { - public string Name + public override string Name { get { return ""; } } - public string Category + public override string Category { get { return ""; } } - public Bitmap Image + public override Bitmap Image { get { return null; } } - public Type SupportedItemType + public override Type SupportedItemType { get { return null; } } - public string FileFilter + public override string FileFilter { get { return ""; } } - public ProgressChangedDelegate ProgressChanged { private get; set; } + public override ProgressChangedDelegate ProgressChanged { protected get; set; } - public bool Import(object targetItem, string filePath) + public override bool Import(object targetItem, string filePath) { if (ProgressChanged != null) { @@ -215,7 +214,7 @@ return true; } - public void Cancel() + public override void Cancel() { } Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Plugin/HydraulicBoundaryLocationsImporter.cs =================================================================== diff -u -rbb0c146c092dadc5f82f0fad45ed92658d436d5c -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Plugin/HydraulicBoundaryLocationsImporter.cs (.../HydraulicBoundaryLocationsImporter.cs) (revision bb0c146c092dadc5f82f0fad45ed92658d436d5c) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Plugin/HydraulicBoundaryLocationsImporter.cs (.../HydraulicBoundaryLocationsImporter.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -40,7 +40,7 @@ /// /// Imports Hydraulic boundary .sqlite files (SqlLite database files). /// - public class HydraulicBoundaryLocationsImporter : IFileImporter + public class HydraulicBoundaryLocationsImporter : FileImporterBase { private readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationsImporter)); private bool shouldCancel; @@ -53,7 +53,7 @@ /// /// Gets the name of the . /// - public string Name + public override string Name { get { @@ -64,7 +64,7 @@ /// /// Gets the category of the . /// - public string Category + public override string Category { get { @@ -76,7 +76,7 @@ /// Gets the image of the . /// /// This image can be used in selection and/or progress dialogs. - public Bitmap Image + public override Bitmap Image { get { @@ -87,7 +87,7 @@ /// /// Gets the of the item supported by the . /// /// Gets the file filter of the . /// - public string FileFilter + public override string FileFilter { get { @@ -109,7 +109,7 @@ /// /// Sets the action to perform when progress has changed. /// - public ProgressChangedDelegate ProgressChanged { get; set; } + public override ProgressChangedDelegate ProgressChanged { protected get; set; } /// /// Validates the file at and sets the version. @@ -136,7 +136,7 @@ /// The item to perform the import on. /// The path of the file to import the data from. /// True if the import was successful. False otherwise. - public bool Import(object targetItem, string filePath) + public override bool Import(object targetItem, string filePath) { var importResult = ReadHydraulicBoundaryLocations(filePath); @@ -159,7 +159,7 @@ /// /// This method cancels an import. /// - public void Cancel() + public override void Cancel() { shouldCancel = true; } Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Plugin.Test/HydraulicBoundaryLocationsImporterTest.cs =================================================================== diff -u -rc6dd26c14af11a7e13f783f578466e46b463165a -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Plugin.Test/HydraulicBoundaryLocationsImporterTest.cs (.../HydraulicBoundaryLocationsImporterTest.cs) (revision c6dd26c14af11a7e13f783f578466e46b463165a) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Plugin.Test/HydraulicBoundaryLocationsImporterTest.cs (.../HydraulicBoundaryLocationsImporterTest.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -67,7 +67,6 @@ Assert.AreEqual(16, importer.Image.Height); Assert.AreEqual(typeof(HydraulicBoundaryLocation), importer.SupportedItemType); Assert.AreEqual(expectedFileFilter, importer.FileFilter); - Assert.IsNull(importer.ProgressChanged); Assert.IsNull(importer.Version); } Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ReferenceLineImporter.cs =================================================================== diff -u -r249fd5e4604012895724a9d7df67201332c9e7dc -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision 249fd5e4604012895724a9d7df67201332c9e7dc) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -20,8 +20,11 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Drawing; +using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Base.IO; using Core.Common.IO.Exceptions; @@ -42,43 +45,45 @@ /// Imports a and stores in on a , /// taking data from a shapefile containing a single polyline. /// - public class ReferenceLineImporter : IFileImporter + public class ReferenceLineImporter : FileImporterBase { private static readonly ILog log = LogManager.GetLogger(typeof(ReferenceLineImporter)); - public string Name + private readonly IList changedObservables = new List(); + + public override string Name { get { return RingtoetsIntegrationFormsResources.ReferenceLine_DisplayName; } } - public string Category + public override string Category { get { return RingtoetsFormsResources.Ringtoets_Category; } } - public Bitmap Image + public override Bitmap Image { get { return RingtoetsIntegrationFormsResources.ReferenceLineIcon; } } - public Type SupportedItemType + public override Type SupportedItemType { get { return typeof(ReferenceLineContext); } } - public string FileFilter + public override string FileFilter { get { @@ -87,16 +92,32 @@ } } - public ProgressChangedDelegate ProgressChanged { get; set; } + public override ProgressChangedDelegate ProgressChanged { protected get; set; } - public bool Import(object targetItem, string filePath) + public override bool Import(object targetItem, string filePath) { + bool clearReferenceLineDependentData = false; + var importTarget = (ReferenceLineContext)targetItem; + if (importTarget.Parent.ReferenceLine != null) + { + var title = "Referentielijn vervangen?"; + var text = "Weet u zeker dat u de referentielijn wilt vervangen?" + Environment.NewLine + + "Als u door gaat zullen alle vakindelingen, berekende hydrolische randvoorwaarden en berekeningsresultaten worden verwijderd."; + DialogResult result = MessageBox.Show(text, title, MessageBoxButtons.OKCancel); + if (result == DialogResult.Cancel) + { + return false; + } + else + { + clearReferenceLineDependentData = true; + } + } + + ReferenceLine importedReferenceLine; try { - var importTarget = (ReferenceLineContext)targetItem; - var importedReferenceLine = new ReferenceLineReader().ReadReferenceLine(filePath); - importTarget.Parent.ReferenceLine = importedReferenceLine; - return true; + importedReferenceLine = new ReferenceLineReader().ReadReferenceLine(filePath); } catch (ArgumentException e) { @@ -108,10 +129,59 @@ HandleCriticalFileReadError(e); return false; } + + AddReferenceLineToDataModel(importTarget.Parent, importedReferenceLine, clearReferenceLineDependentData); + return true; } - public void Cancel() {} + public override void Cancel() {} + protected override IEnumerable GetAffectedNonTargetObservableInstances() + { + return changedObservables; + } + + private void AddReferenceLineToDataModel(AssessmentSectionBase assessmentSection, ReferenceLine importedReferenceLine, bool clearReferenceLineDependentData) + { + assessmentSection.ReferenceLine = importedReferenceLine; + + if (clearReferenceLineDependentData) + { + ClearReferenceLineDependentData(assessmentSection); + } + } + + private void ClearReferenceLineDependentData(AssessmentSectionBase assessmentSection) + { + foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) + { + ClearCalculationOutput(failureMechanism); + ClearFailureMechanismSections(failureMechanism); + } + ClearHydraulicBoundaryOutput(assessmentSection); + } + + private void ClearCalculationOutput(IFailureMechanism failureMechanism) + { + foreach (var calculationItem in failureMechanism.CalculationItems) + { + calculationItem.ClearOutput(); + changedObservables.Add(calculationItem); + } + } + + private void ClearFailureMechanismSections(IFailureMechanism failureMechanisms) + { + // TODO: WTI-365 - Clear all 'vakindelingen' + //changedObservables.Add(clearedInstance); + } + + private void ClearHydraulicBoundaryOutput(AssessmentSectionBase assessmentSection) + { + // TODO: WTI-360 - Clear all 'Toetspeil' calculation output + //changedObservables.Add(clearedInstance); + } + private static void HandleCriticalFileReadError(Exception e) { var errorMessage = String.Format(Resources.ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_imported, Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ReferenceLineImporterTest.cs =================================================================== diff -u -r249fd5e4604012895724a9d7df67201332c9e7dc -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision 249fd5e4604012895724a9d7df67201332c9e7dc) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -2,10 +2,12 @@ using System.IO; using System.Linq; +using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Base.IO; using Core.Common.TestUtil; +using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -20,7 +22,7 @@ namespace Ringtoets.Integration.Plugin.Test.FileImporters { [TestFixture] - public class ReferenceLineImporterTest + public class ReferenceLineImporterTest : NUnitFormsAssertTest { [Test] public void DefaultConstructor_ExpectedValues() @@ -35,7 +37,6 @@ TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.ReferenceLineIcon, importer.Image); Assert.AreEqual(typeof(ReferenceLineContext), importer.SupportedItemType); Assert.AreEqual("Referentielijn shapefile (*.shp)|*.shp", importer.FileFilter); - Assert.IsNull(importer.ProgressChanged); } [Test] @@ -89,6 +90,8 @@ "Er is geen referentielijn geïmporteerd."; TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); Assert.IsFalse(importSuccesful); + Assert.IsNull(assessmentSection.ReferenceLine); + Assert.IsNull(referenceLineContext.WrappedData); mocks.VerifyAll(); } @@ -112,14 +115,225 @@ // Assert var expectedMessage = string.Format(@"Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", path) + Environment.NewLine + - "Er is geen referentielijn geïmporteerd."; + "Er is geen referentielijn geïmporteerd."; TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); Assert.IsFalse(importSuccesful); + Assert.IsNull(assessmentSection.ReferenceLine); + Assert.IsNull(referenceLineContext.WrappedData); mocks.VerifyAll(); } + [Test] + public void Import_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToCancel_NoChanges() + { + // Setup + var originalReferenceLine = new ReferenceLine(); + + var mocks = new MockRepository(); + var calculation1 = mocks.StrictMock(); + var calculation3 = mocks.StrictMock(); + + var failureMechanism1 = mocks.Stub(); + failureMechanism1.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation1, + }); + + var failureMechanism2 = mocks.Stub(); + failureMechanism2.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation3, + }); + + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = originalReferenceLine; + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism1, + failureMechanism2 + }); + mocks.ReplayAll(); + + var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + string messageBoxTitle = null, messageBoxText = null; + DialogBoxHandler = (name, wnd) => + { + var messageBoxTester = new MessageBoxTester(wnd); + + messageBoxTitle = messageBoxTester.Title; + messageBoxText = messageBoxTester.Text; + + messageBoxTester.ClickCancel(); + }; + + // Call + bool importSuccesful = importer.Import(referenceLineContext, path); + + // Assert + Assert.IsFalse(importSuccesful); + Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine); + Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); + + Assert.AreEqual("Referentielijn vervangen?", messageBoxTitle); + var expectedText = "Weet u zeker dat u de referentielijn wilt vervangen?" + Environment.NewLine + + "Als u door gaat zullen alle vakindelingen, berekende hydrolische randvoorwaarden en berekeningsresultaten worden verwijderd."; + Assert.AreEqual(expectedText, messageBoxText); + + mocks.VerifyAll(); + } + + [Test] + public void Import_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToContinue_ClearDataDependentOnReferenceLine() + { + // Setup + var originalReferenceLine = new ReferenceLine(); + + var mocks = new MockRepository(); + var calculation1 = mocks.Stub(); + calculation1.Expect(c => c.ClearOutput()); + var calculation2 = mocks.Stub(); + calculation2.Expect(c => c.ClearOutput()); + var calculation3 = mocks.Stub(); + calculation3.Expect(c => c.ClearOutput()); + var calculation4 = mocks.Stub(); + calculation4.Expect(c => c.ClearOutput()); + + var failureMechanism1 = mocks.Stub(); + failureMechanism1.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation1, + calculation2 + }); + + var failureMechanism2 = mocks.Stub(); + failureMechanism2.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation3, + calculation4 + }); + + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = originalReferenceLine; + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism1, + failureMechanism2 + }); + mocks.ReplayAll(); + + var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + + string messageBoxTitle = null, messageBoxText = null; + DialogBoxHandler = (name, wnd) => + { + var messageBoxTester = new MessageBoxTester(wnd); + + messageBoxTitle = messageBoxTester.Title; + messageBoxText = messageBoxTester.Text; + + messageBoxTester.ClickOk(); + }; + + // Call + bool importSuccesful = importer.Import(referenceLineContext, path); + + // Assert + Assert.IsTrue(importSuccesful); + Assert.AreNotSame(originalReferenceLine, assessmentSection.ReferenceLine); + Point2D[] point2Ds = assessmentSection.ReferenceLine.Points.ToArray(); + Assert.AreEqual(803, point2Ds.Length); + Assert.AreEqual(198237.375, point2Ds[123].X, 1e-6); + Assert.AreEqual(514879.781, point2Ds[123].Y, 1e-6); + + Assert.AreEqual("Referentielijn vervangen?", messageBoxTitle); + var expectedText = "Weet u zeker dat u de referentielijn wilt vervangen?" + Environment.NewLine + + "Als u door gaat zullen alle vakindelingen, berekende hydrolische randvoorwaarden en berekeningsresultaten worden verwijderd."; + Assert.AreEqual(expectedText, messageBoxText); + + // TODO: Clear 'vakindelingen' on all failure mechanisms + // TODO: Clear calculated HR + mocks.VerifyAll(); // Expect calculation output cleared + } + + [Test] + public void DoPostImportUpdates_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToContinue_NotifyObserversOfTargetContextAndClearedObjects() + { + // Setup + var originalReferenceLine = new ReferenceLine(); + + var mocks = new MockRepository(); + var calculation1 = mocks.Stub(); + calculation1.Stub(c => c.ClearOutput()); + calculation1.Expect(c => c.NotifyObservers()); + var calculation2 = mocks.Stub(); + calculation2.Stub(c => c.ClearOutput()); + calculation2.Expect(c => c.NotifyObservers()); + var calculation3 = mocks.Stub(); + calculation3.Stub(c => c.ClearOutput()); + calculation3.Expect(c => c.NotifyObservers()); + var calculation4 = mocks.Stub(); + calculation4.Stub(c => c.ClearOutput()); + calculation4.Expect(c => c.NotifyObservers()); + + var failureMechanism1 = mocks.Stub(); + failureMechanism1.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation1, + calculation2 + }); + + var failureMechanism2 = mocks.Stub(); + failureMechanism2.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation3, + calculation4 + }); + + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = originalReferenceLine; + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism1, + failureMechanism2 + }); + + var contextObserver = mocks.Stub(); + contextObserver.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + referenceLineContext.Attach(contextObserver); + + var importer = new ReferenceLineImporter(); + + DialogBoxHandler = (name, wnd) => + { + var messageBoxTester = new MessageBoxTester(wnd); + messageBoxTester.ClickOk(); + }; + + // Precondition + Assert.IsTrue(importer.Import(referenceLineContext, path)); + + // Call + importer.DoPostImportUpdates(referenceLineContext); + + // Assert + mocks.VerifyAll(); // Expect NotifyObservers on cleared calculations and context + } + // TODO: Cancel - // TODO: Import when ReferenceLine already exists // TODO: Progress reporting + // TODO: Instance reuse } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r80f41e842173e15c34c76faa14385b596e7ee34f -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 80f41e842173e15c34c76faa14385b596e7ee34f) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -48,6 +48,9 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\..\..\..\lib\NUnitForms.dll + Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs =================================================================== diff -u -r98fc85d8cecf9edae9fe7c1f2f47b60ecda5e187 -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision 98fc85d8cecf9edae9fe7c1f2f47b60ecda5e187) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -39,44 +39,44 @@ /// /// Imports .soil files (SqlLite database files) created with the DSoilModel application. /// - public class PipingSoilProfilesImporter : IFileImporter + public class PipingSoilProfilesImporter : FileImporterBase { private readonly ILog log = LogManager.GetLogger(typeof(PipingSoilProfilesImporter)); private bool shouldCancel; - public string Name + public override string Name { get { return PipingFormsResources.PipingSoilProfilesCollection_DisplayName; } } - public string Category + public override string Category { get { return RingtoetsFormsResources.Ringtoets_Category; } } - public Bitmap Image + public override Bitmap Image { get { return PipingFormsResources.PipingSoilProfileIcon; } } - public Type SupportedItemType + public override Type SupportedItemType { get { return typeof(ICollection); } } - public string FileFilter + public override string FileFilter { get { @@ -85,14 +85,14 @@ } } - public ProgressChangedDelegate ProgressChanged { get; set; } + public override ProgressChangedDelegate ProgressChanged { protected get; set; } - public void Cancel() + public override void Cancel() { shouldCancel = true; } - public bool Import(object targetItem, string filePath) + public override bool Import(object targetItem, string filePath) { var importResult = ReadSoilProfiles(filePath); Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -rfea3332b5f7a5cea6b41de4a6368c1f1c2bf1282 -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision fea3332b5f7a5cea6b41de4a6368c1f1c2bf1282) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -24,6 +24,7 @@ using System.Drawing; using System.IO; using System.Linq; + using Core.Common.Base.Geometry; using Core.Common.Base.IO; using Core.Common.IO.Exceptions; @@ -43,7 +44,7 @@ /// Id;X1;Y1;Z1;...(Xn;Yn;Zn) /// Where Xn;Yn;Zn form the n-th 3D point describing the geometry of the surface line. /// - public class PipingSurfaceLinesCsvImporter : IFileImporter + public class PipingSurfaceLinesCsvImporter : FileImporterBase { private readonly ILog log; private bool shouldCancel; @@ -54,39 +55,39 @@ log = LogManager.GetLogger(GetType()); } - public string Name + public override string Name { get { return PipingFormsResources.PipingSurfaceLinesCollection_DisplayName; } } - public string Category + public override string Category { get { return RingtoetsFormsResources.Ringtoets_Category; } } - public Bitmap Image + public override Bitmap Image { get { return PipingFormsResources.PipingSurfaceLineIcon; } } - public Type SupportedItemType + public override Type SupportedItemType { get { return typeof(ICollection); } } - public string FileFilter + public override string FileFilter { get { @@ -95,17 +96,16 @@ } } - public ProgressChangedDelegate ProgressChanged { get; set; } + public override ProgressChangedDelegate ProgressChanged { protected get; set; } - public void Cancel() + public override void Cancel() { shouldCancel = true; } - public bool Import(object targetItem, string filePath) + public override bool Import(object targetItem, string filePath) { var importSurfaceLinesResult = ReadPipingSurfaceLines(filePath); - if (importSurfaceLinesResult.CriticalErrorOccurred) { return false; Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs =================================================================== diff -u -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -47,7 +47,6 @@ Assert.AreEqual(16, importer.Image.Height); Assert.AreEqual(typeof(ICollection), importer.SupportedItemType); Assert.AreEqual(expectedFileFilter, importer.FileFilter); - Assert.IsNull(importer.ProgressChanged); } [Test] Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs =================================================================== diff -u -rfea3332b5f7a5cea6b41de4a6368c1f1c2bf1282 -rdcd6469f6000957bc1604da8e92bd5ea09e43769 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision fea3332b5f7a5cea6b41de4a6368c1f1c2bf1282) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) @@ -41,7 +41,6 @@ var expectedFileFilter = String.Format("{0} {1} (*.csv)|*.csv", PipingFormsResources.PipingSurfaceLinesCollection_DisplayName, ApplicationResources.Csv_file_name); Assert.AreEqual(expectedFileFilter, importer.FileFilter); - Assert.IsNull(importer.ProgressChanged); } [Test] @@ -61,7 +60,7 @@ var importer = new PipingSurfaceLinesCsvImporter(); int callCount = 0; - importer.ProgressChanged += delegate(string currentStepName, int currentStep, int totalNumberOfSteps) + importer.ProgressChanged = delegate(string currentStepName, int currentStep, int totalNumberOfSteps) { if (callCount <= expectedNumberOfSurfaceLines) { @@ -407,7 +406,7 @@ mocks.ReplayAll(); var importer = new PipingSurfaceLinesCsvImporter(); - importer.ProgressChanged += (name, step, steps) => + importer.ProgressChanged = (name, step, steps) => { // Delete the file being read by the import during the import itself: File.Delete(copyTargetPath); @@ -453,7 +452,7 @@ var importer = new PipingSurfaceLinesCsvImporter(); int progressCallCount = 0; - importer.ProgressChanged += (name, step, steps) => { progressCallCount++; }; + importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var observableSurfaceLinesList = new ObservableList(); observableSurfaceLinesList.Attach(observer); @@ -701,7 +700,7 @@ mocks.ReplayAll(); var importer = new PipingSurfaceLinesCsvImporter(); - importer.ProgressChanged += (name, step, steps) => + importer.ProgressChanged = (name, step, steps) => { // Delete the file being read by the import during the import itself: if (name == string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_Read_PipingCharacteristicPoints_0_, @@ -796,7 +795,7 @@ var importer = new PipingSurfaceLinesCsvImporter(); int progressCallCount = 0; - importer.ProgressChanged += (name, step, steps) => { progressCallCount++; }; + importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var observableSurfaceLinesList = new ObservableList(); observableSurfaceLinesList.Attach(observer); @@ -846,7 +845,7 @@ var importer = new PipingSurfaceLinesCsvImporter(); int progressCallCount = 0; - importer.ProgressChanged += (name, step, steps) => { progressCallCount++; }; + importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var observableSurfaceLinesList = new ObservableList(); observableSurfaceLinesList.Attach(observer); @@ -890,7 +889,7 @@ var importer = new PipingSurfaceLinesCsvImporter(); int progressCallCount = 0; - importer.ProgressChanged += (name, step, steps) => { progressCallCount++; }; + importer.ProgressChanged = (name, step, steps) => { progressCallCount++; }; var observableSurfaceLinesList = new ObservableList(); observableSurfaceLinesList.Attach(observer); @@ -944,7 +943,7 @@ var importer = new PipingSurfaceLinesCsvImporter(); int callCount = 0; - importer.ProgressChanged += delegate(string currentStepName, int currentStep, int totalNumberOfSteps) + importer.ProgressChanged = delegate(string currentStepName, int currentStep, int totalNumberOfSteps) { if (callCount <= expectedNumberOfSurfaceLines) {