Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -r2a90c0c1be6114f72af65c42f0a6f334b30e4755 -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 2a90c0c1be6114f72af65c42f0a6f334b30e4755) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -79,6 +79,7 @@ + Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputSelectionEditor.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputSelectionEditor.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputSelectionEditor.cs (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing.Design; +using System.Linq; +using System.Windows.Forms; +using System.Windows.Forms.Design; +using Core.Common.Utils.PropertyBag.Dynamic; +using Ringtoets.Piping.Forms.PropertyClasses; + +namespace Ringtoets.Piping.Forms.UITypeEditors +{ + /// + /// This class provides a base implementation of and defines a drop down list + /// edit-control used for piping input data. + /// + /// The type of items that populate the list-edit control. + public class PipingCalculationInputSelectionEditor : UITypeEditor where T : class + { + private IWindowsFormsEditorService editorService; + + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + { + return UITypeEditorEditStyle.DropDown; + } + + public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object originalValue) + { + if (provider != null) + { + editorService = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService)); + } + + if (editorService != null && context != null) + { + // Create editor: + ListBox listBox = CreateSelectionControl(context); + + // Open editor for user to select an item: + editorService.DropDownControl(listBox); + + // Return user selected object, or original value if user did not select anything: + return listBox.SelectedItem ?? originalValue; + } + return base.EditValue(context, provider, originalValue); + } + + /// + /// Gets which member to show of in the dropdown editor. + /// + protected string DisplayMember { private get; set; } + + /// + /// Gets the available options which populate the dropdown editor. + /// + /// The context on which to base the available options. + /// A of objects of type which contains all the available options. + protected virtual IEnumerable GetAvailableOptions(ITypeDescriptorContext context) + { + return Enumerable.Empty(); + } + + /// + /// Gets the current option which should be selected in the dropdown editor. + /// + /// The context on which to base the current option. + /// The object of type which is currently selected. + protected virtual T GetCurrentOption(ITypeDescriptorContext context) + { + return null; + } + + /// + /// Takes a context and from this, obtains the object which populates the dropdown editor. + /// + /// The context from which the object is obtained. + /// The object which' properties populates the dropdown editor. + protected static PipingCalculationInputsProperties GetPropertiesObject(ITypeDescriptorContext context) + { + return (PipingCalculationInputsProperties) ((DynamicPropertyBag) context.Instance).WrappedObject; + } + + private ListBox CreateSelectionControl(ITypeDescriptorContext context) + { + var listBox = new ListBox + { + SelectionMode = SelectionMode.One, + DisplayMember = DisplayMember + }; + listBox.SelectedValueChanged += (sender, eventArgs) => editorService.CloseDropDown(); + + foreach (T surfaceLine in GetAvailableOptions(context)) + { + int index = listBox.Items.Add(surfaceLine); + if (ReferenceEquals(GetCurrentOption(context), surfaceLine)) + { + listBox.SelectedIndex = index; + } + } + return listBox; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputsSoilProfileSelectionEditor.cs =================================================================== diff -u -ra950714ad9510756331d862aa35695fa0b2ed03b -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputsSoilProfileSelectionEditor.cs (.../PipingCalculationInputsSoilProfileSelectionEditor.cs) (revision a950714ad9510756331d862aa35695fa0b2ed03b) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputsSoilProfileSelectionEditor.cs (.../PipingCalculationInputsSoilProfileSelectionEditor.cs) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -1,64 +1,32 @@ -using System; +using System.Collections.Generic; using System.ComponentModel; -using System.Drawing.Design; -using System.Windows.Forms; -using System.Windows.Forms.Design; -using Core.Common.Utils.PropertyBag.Dynamic; using Core.Common.Utils.Reflection; using Ringtoets.Piping.Data; -using Ringtoets.Piping.Forms.PropertyClasses; namespace Ringtoets.Piping.Forms.UITypeEditors { - public class PipingCalculationInputsSoilProfileSelectionEditor : UITypeEditor + /// + /// This class defines a drop down list edit-control from which the user can select a + /// from a collection. + /// + public class PipingCalculationInputsSoilProfileSelectionEditor : PipingCalculationInputSelectionEditor { - private IWindowsFormsEditorService editorService; - - public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + /// + /// Creates a new instance of . + /// + public PipingCalculationInputsSoilProfileSelectionEditor() { - return UITypeEditorEditStyle.DropDown; + DisplayMember = TypeUtils.GetMemberName(sl => sl.Name); } - public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) + protected override IEnumerable GetAvailableOptions(ITypeDescriptorContext context) { - if (provider != null) - { - editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); - } - - if (editorService != null) - { - // Create editor: - var listBox = CreateSoilProfileSelectionControl(context); - - // Open editor for user to select an item: - editorService.DropDownControl(listBox); - - // Return user selected object, or original value if user did not select anything: - return listBox.SelectedItem ?? value; - } - return base.EditValue(context, provider, value); + return GetPropertiesObject(context).GetAvailableSoilProfiles(); } - private ListBox CreateSoilProfileSelectionControl(ITypeDescriptorContext context) + protected override PipingSoilProfile GetCurrentOption(ITypeDescriptorContext context) { - var listBox = new ListBox - { - SelectionMode = SelectionMode.One, - DisplayMember = TypeUtils.GetMemberName(sl => sl.Name) - }; - listBox.SelectedValueChanged += (sender, eventArgs) => editorService.CloseDropDown(); - - var properties = (PipingCalculationInputsProperties)((DynamicPropertyBag)context.Instance).WrappedObject; - foreach (var soilProfile in properties.GetAvailableSoilProfiles()) - { - int index = listBox.Items.Add(soilProfile); - if (ReferenceEquals(properties.SoilProfile, soilProfile)) - { - listBox.SelectedIndex = index; - } - } - return listBox; - } + return GetPropertiesObject(context).SoilProfile; + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditor.cs =================================================================== diff -u -r8df04aa7166563cc67a1b7e70f9f4b8867e454b7 -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditor.cs (.../PipingCalculationInputsSurfaceLineSelectionEditor.cs) (revision 8df04aa7166563cc67a1b7e70f9f4b8867e454b7) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditor.cs (.../PipingCalculationInputsSurfaceLineSelectionEditor.cs) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -1,69 +1,32 @@ -using System; +using System.Collections.Generic; using System.ComponentModel; -using System.Drawing.Design; -using System.Windows.Forms; -using System.Windows.Forms.Design; -using Core.Common.Utils.PropertyBag.Dynamic; using Core.Common.Utils.Reflection; using Ringtoets.Piping.Data; -using Ringtoets.Piping.Forms.PropertyClasses; - namespace Ringtoets.Piping.Forms.UITypeEditors { /// /// This class defines a drop down list edit-control from which the user can select a /// from a collection. /// - public class PipingCalculationInputsSurfaceLineSelectionEditor : UITypeEditor + public class PipingCalculationInputsSurfaceLineSelectionEditor : PipingCalculationInputSelectionEditor { - private IWindowsFormsEditorService editorService; - - public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + /// + /// Creates a new instance of . + /// + public PipingCalculationInputsSurfaceLineSelectionEditor() { - return UITypeEditorEditStyle.DropDown; + DisplayMember = TypeUtils.GetMemberName(sl => sl.Name); } - public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object originalValue) + protected override IEnumerable GetAvailableOptions(ITypeDescriptorContext context) { - if (provider != null) - { - editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); - } - - if (editorService != null) - { - // Create editor: - ListBox listBox = CreateSurfaceLinesSelectionControl(context); - - // Open editor for user to select an item: - editorService.DropDownControl(listBox); - - // Return user selected object, or original value if user did not select anything: - return listBox.SelectedItem ?? originalValue; - } - return base.EditValue(context, provider, originalValue); + return GetPropertiesObject(context).GetAvailableSurfaceLines(); } - private ListBox CreateSurfaceLinesSelectionControl(ITypeDescriptorContext context) + protected override RingtoetsPipingSurfaceLine GetCurrentOption(ITypeDescriptorContext context) { - var listBox = new ListBox - { - SelectionMode = SelectionMode.One, - DisplayMember = TypeUtils.GetMemberName(sl => sl.Name) - }; - listBox.SelectedValueChanged += (sender, eventArgs) => editorService.CloseDropDown(); - - var properties = (PipingCalculationInputsProperties)((DynamicPropertyBag)context.Instance).WrappedObject; - foreach (RingtoetsPipingSurfaceLine surfaceLine in properties.GetAvailableSurfaceLines()) - { - int index = listBox.Items.Add(surfaceLine); - if (ReferenceEquals(properties.SurfaceLine, surfaceLine)) - { - listBox.SelectedIndex = index; - } - } - return listBox; + return GetPropertiesObject(context).SurfaceLine; } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingReadResult.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingReadResult.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingReadResult.cs (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -0,0 +1,35 @@ +using System.Collections.Generic; + +namespace Ringtoets.Piping.Plugin.FileImporter +{ + /// + /// This class can be used in importers to return a result from a method where some critical error + /// may have occurred. The type of items which are collected is supplied by . + /// + /// The type of the items which are returned in this result as . + public class PipingReadResult + { + /// + /// Creates a new instance of , for which the + /// is set to . + /// + /// value indicating whether an error has occurred while collecting + /// the import items for this . + public PipingReadResult(bool errorOccurred) + { + CriticalErrorOccurred = errorOccurred; + ImportedItems = new T[0]; + } + + /// + /// Gets or sets the of items that were imported. + /// + public ICollection ImportedItems { get; set; } + + /// + /// Gets or sets the representing whether an critical error has occurred during + /// import. + /// + public bool CriticalErrorOccurred { get; private set; } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs =================================================================== diff -u -rf7d48349feba2a41391fac27dc3fef3028df091d -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision f7d48349feba2a41391fac27dc3fef3028df091d) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -108,7 +108,7 @@ return target; } - private ReadResult ReadSoilProfiles(string path) + private PipingReadResult ReadSoilProfiles(string path) { NotifyProgress(ApplicationResources.PipingSoilProfilesImporter_Reading_database, 1, 1); @@ -131,7 +131,7 @@ { HandleException(path, e); } - return new ReadResult(true); + return new PipingReadResult(true); } private void HandleException(string path, Exception e) @@ -141,7 +141,7 @@ log.Error(message); } - private ReadResult GetProfileReadResult(string path, PipingSoilProfileReader soilProfileReader) + private PipingReadResult GetProfileReadResult(string path, PipingSoilProfileReader soilProfileReader) { var totalNumberOfSteps = soilProfileReader.Count; var currentStep = 1; @@ -153,7 +153,7 @@ { if (ShouldCancel) { - return new ReadResult(false); + return new PipingReadResult(false); } try { @@ -167,13 +167,13 @@ log.Error(message); } } - return new ReadResult(false) + return new PipingReadResult(false) { ImportedItems = profiles }; } - private void AddImportedDataToModel(object target, ReadResult imported) + private void AddImportedDataToModel(object target, PipingReadResult imported) { var targetCollection = (ObservableList)target; Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -r20080bce6a7f240532182e73ee3e638b574fb612 -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 20080bce6a7f240532182e73ee3e638b574fb612) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -125,7 +125,7 @@ } } - private ReadResult ReadPipingSurfaceLines(string path) + private PipingReadResult ReadPipingSurfaceLines(string path) { PipingSurfaceLinesCsvReader reader; try @@ -177,7 +177,7 @@ reader.Dispose(); - return new ReadResult(false) + return new PipingReadResult(false) { ImportedItems = readSurfaceLines }; @@ -208,12 +208,12 @@ } } - private ReadResult HandleCriticalError(string path, Exception e) + private PipingReadResult HandleCriticalError(string path, Exception e) { var message = string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_Critical_error_reading_File_0_Cause_1_, path, e.Message); log.Error(message); - return new ReadResult(true); + return new PipingReadResult(true); } private void AddImportedDataToModel(object target, ICollection readSurfaceLines) Fisheye: Tag 21c58fc28e5675736f50be6e06b2605120991478 refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/ReadResult.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj =================================================================== diff -u -rf7d48349feba2a41391fac27dc3fef3028df091d -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision f7d48349feba2a41391fac27dc3fef3028df091d) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -71,7 +71,7 @@ - + True Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -r2a90c0c1be6114f72af65c42f0a6f334b30e4755 -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 2a90c0c1be6114f72af65c42f0a6f334b30e4755) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -68,6 +68,8 @@ + + Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputSelectionEditorTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputSelectionEditorTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputSelectionEditorTest.cs (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -0,0 +1,88 @@ +using System; +using System.ComponentModel; +using System.Drawing.Design; +using System.Windows.Forms.Design; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Forms.UITypeEditors; + +namespace Ringtoets.Piping.Forms.Test.UITypeEditors +{ + [TestFixture] + public class PipingCalculationInputSelectionEditorTest + { + [Test] + public void GetEditStyle_Always_ReturnDropDown() + { + // Setup + var editor = new PipingCalculationInputSelectionEditor(); + + // Call + var editStyle = editor.GetEditStyle(); + + // Assert + Assert.AreEqual(UITypeEditorEditStyle.DropDown, editStyle); + } + + [Test] + public void EditValue_NoProviderNoContext_ReturnsOriginalValue() + { + // Setup + var editor = new PipingCalculationInputSelectionEditor(); + var someValue = new object(); + + // Call + var result = editor.EditValue(null, null, someValue); + + // Assert + Assert.AreSame(someValue, result); + } + + [Test] + public void EditValue_NoContext_ReturnsOriginalValue() + { + // Setup + var editor = new PipingCalculationInputSelectionEditor(); + var someValue = new object(); + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + + mockRepository.ReplayAll(); + + // Call + var result = editor.EditValue(null, provider, someValue); + + // Assert + Assert.AreSame(someValue, result); + + mockRepository.VerifyAll(); + } + + [Test] + public void EditValue_Always_ReturnsOriginalValue() + { + // Setup + var editor = new PipingCalculationInputSelectionEditor(); + var someValue = new object(); + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + var context = mockRepository.DynamicMock(); + + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); + + mockRepository.ReplayAll(); + + // Call + var result = editor.EditValue(context, provider, someValue); + + // Assert + Assert.AreSame(someValue, result); + + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputSoilProfileSelectionEditorTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputSoilProfileSelectionEditorTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputSoilProfileSelectionEditorTest.cs (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -0,0 +1,101 @@ +using System; +using System.ComponentModel; +using System.Windows.Forms.Design; +using Core.Common.Utils.PropertyBag.Dynamic; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Calculation.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Forms.PropertyClasses; +using Ringtoets.Piping.Forms.UITypeEditors; + +namespace Ringtoets.Piping.Forms.Test.UITypeEditors +{ + [TestFixture] + public class PipingCalculationInputSoilProfileSelectionEditorTest + { + [Test] + public void EditValue_NoCurrentItemInAvailableItems_ReturnsOriginalValue() + { + // Setup + var pipingCalculationInputs = new PipingCalculationInputs + { + AvailablePipingSoilProfiles = new[] { new TestPipingSoilProfile() }, + PipingData = new PipingData + { + SoilProfile = new TestPipingSoilProfile() + } + }; + + var properties = new PipingCalculationInputsProperties + { + Data = pipingCalculationInputs + }; + + var editor = new PipingCalculationInputsSoilProfileSelectionEditor(); + var someValue = new object(); + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + var context = mockRepository.DynamicMock(); + var propertyBag = new DynamicPropertyBag(properties); + + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); + context.Expect(c => c.Instance).Return(propertyBag); + + mockRepository.ReplayAll(); + + // Call + var result = editor.EditValue(context, provider, someValue); + + // Assert + Assert.AreSame(someValue, result); + + mockRepository.VerifyAll(); + } + + [Test] + public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() + { + // Setup + var soilProfile = new TestPipingSoilProfile(); + var pipingCalculationInputs = new PipingCalculationInputs + { + AvailablePipingSoilProfiles = new[] { soilProfile }, + PipingData = new PipingData + { + SoilProfile = soilProfile + } + }; + + var properties = new PipingCalculationInputsProperties + { + Data = pipingCalculationInputs + }; + + var editor = new PipingCalculationInputsSoilProfileSelectionEditor(); + var someValue = new object(); + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + var context = mockRepository.DynamicMock(); + var propertyBag = new DynamicPropertyBag(properties); + + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); + context.Expect(c => c.Instance).Return(propertyBag); + + mockRepository.ReplayAll(); + + // Call + var result = editor.EditValue(context, provider, someValue); + + // Assert + Assert.AreSame(soilProfile, result); + + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditorTest.cs =================================================================== diff -u -ra950714ad9510756331d862aa35695fa0b2ed03b -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditorTest.cs (.../PipingCalculationInputsSurfaceLineSelectionEditorTest.cs) (revision a950714ad9510756331d862aa35695fa0b2ed03b) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditorTest.cs (.../PipingCalculationInputsSurfaceLineSelectionEditorTest.cs) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -1,7 +1,12 @@ -using System.Drawing.Design; - +using System; +using System.ComponentModel; +using System.Windows.Forms.Design; +using Core.Common.Utils.PropertyBag.Dynamic; using NUnit.Framework; - +using Rhino.Mocks; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Forms.PropertyClasses; using Ringtoets.Piping.Forms.UITypeEditors; namespace Ringtoets.Piping.Forms.Test.UITypeEditors @@ -10,26 +15,86 @@ public class PipingCalculationInputsSurfaceLineSelectionEditorTest { [Test] - public void DefaultConstructor_ExpectedValues() + public void EditValue_NoCurrentItemInAvailableItems_ReturnsOriginalValue() { - // Call + // Setup + var pipingCalculationInputs = new PipingCalculationInputs + { + AvailablePipingSurfaceLines = new[] { new RingtoetsPipingSurfaceLine() }, + PipingData = new PipingData + { + SurfaceLine = new RingtoetsPipingSurfaceLine() + } + }; + + var properties = new PipingCalculationInputsProperties + { + Data = pipingCalculationInputs + }; + var editor = new PipingCalculationInputsSurfaceLineSelectionEditor(); + var someValue = new object(); + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + var context = mockRepository.DynamicMock(); + var propertyBag = new DynamicPropertyBag(properties); + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); + context.Expect(c => c.Instance).Return(propertyBag); + + mockRepository.ReplayAll(); + + // Call + var result = editor.EditValue(context, provider, someValue); + // Assert - Assert.IsInstanceOf(editor); + Assert.AreSame(someValue, result); + + mockRepository.VerifyAll(); } [Test] - public void GetEditStyle_Always_ReturnDropDown() + public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() { // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine(); + var pipingCalculationInputs = new PipingCalculationInputs + { + AvailablePipingSurfaceLines = new[] { surfaceLine }, + PipingData = new PipingData + { + SurfaceLine = surfaceLine + } + }; + + var properties = new PipingCalculationInputsProperties + { + Data = pipingCalculationInputs + }; + var editor = new PipingCalculationInputsSurfaceLineSelectionEditor(); + var someValue = new object(); + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + var context = mockRepository.DynamicMock(); + var propertyBag = new DynamicPropertyBag(properties); + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); + context.Expect(c => c.Instance).Return(propertyBag); + + mockRepository.ReplayAll(); + // Call - var editStyle = editor.GetEditStyle(); + var result = editor.EditValue(context, provider, someValue); // Assert - Assert.AreEqual(UITypeEditorEditStyle.DropDown, editStyle); + Assert.AreSame(surfaceLine, result); + + mockRepository.VerifyAll(); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingReadResultTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingReadResultTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingReadResultTest.cs (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -0,0 +1,22 @@ +using NUnit.Framework; +using Ringtoets.Piping.Plugin.FileImporter; + +namespace Ringtoets.Piping.Plugin.Test.FileImporter +{ + [TestFixture] + public class PipingReadResultTest + { + [Test] + [TestCase(true)] + [TestCase(false)] + public void Constructor_CriticalErrorOccuredOrNot_InitializesCollectionAndSetsCriticalErrorOccuredProperty(bool errorOccurred) + { + // Call + var readResult = new PipingReadResult(errorOccurred); + + // Assert + CollectionAssert.IsEmpty(readResult.ImportedItems); + Assert.AreEqual(errorOccurred, readResult.CriticalErrorOccurred); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj =================================================================== diff -u -r2a90c0c1be6114f72af65c42f0a6f334b30e4755 -r21c58fc28e5675736f50be6e06b2605120991478 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 2a90c0c1be6114f72af65c42f0a6f334b30e4755) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 21c58fc28e5675736f50be6e06b2605120991478) @@ -51,6 +51,7 @@ +