Fisheye: Tag cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Commands/HydraulicBoundaryLocationCalculationCommandHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Commands/IHydraulicBoundaryLocationCalculationCommandHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/GuiServices/HydraulicBoundaryLocationCalculationGuiService.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/GuiServices/HydraulicBoundaryLocationCalculationGuiService.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/GuiServices/HydraulicBoundaryLocationCalculationGuiService.cs (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -0,0 +1,107 @@ +// 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; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base.Service; +using Core.Common.Gui.Forms.ProgressDialog; +using log4net; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.HydraRing.Data; +using Ringtoets.HydraRing.IO; +using Ringtoets.Integration.Forms.Properties; +using Ringtoets.Integration.Service; + +namespace Ringtoets.Integration.Forms.GuiServices +{ + /// + /// This class is responsible for calculating the + /// and . + /// + public class HydraulicBoundaryLocationCalculationGuiService : IHydraulicBoundaryLocationCalculationGuiService + { + private static readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationCalculationGuiService)); + private readonly IWin32Window viewParent; + + /// + /// Initializes a new instance of the class. + /// + /// The parent of the view. + public HydraulicBoundaryLocationCalculationGuiService(IWin32Window viewParent) + { + if (viewParent == null) + { + throw new ArgumentNullException("viewParent"); + } + this.viewParent = viewParent; + } + + public void CalculateDesignWaterLevels(IAssessmentSection assessmentSection, + IEnumerable locations) + { + if (assessmentSection == null) + { + throw new ArgumentNullException("assessmentSection"); + } + if (locations == null) + { + throw new ArgumentNullException("locations"); + } + var activities = locations.Select(hbl => new DesignWaterLevelCalculationActivity(assessmentSection, hbl)).ToArray(); + RunActivities(assessmentSection, activities); + } + + public void CalculateWaveHeights(IAssessmentSection assessmentSection, + IEnumerable locations) + { + if (assessmentSection == null) + { + throw new ArgumentNullException("assessmentSection"); + } + if (locations == null) + { + throw new ArgumentNullException("locations"); + } + var activities = locations.Select(hbl => new WaveHeightCalculationActivity(assessmentSection, hbl)).ToArray(); + RunActivities(assessmentSection, activities); + } + + private void RunActivities(IAssessmentSection assessmentSection, + IList activities) where TActivity : Activity + { + var hrdFile = assessmentSection.HydraulicBoundaryDatabase.FilePath; + var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(hrdFile); + if (string.IsNullOrEmpty(validationProblem)) + { + ActivityProgressDialogRunner.Run(viewParent, activities); + + assessmentSection.HydraulicBoundaryDatabase.NotifyObservers(); + } + else + { + log.ErrorFormat(Resources.CalculateHydraulicBoundaryLocation_ContextMenuStrip_Start_calculation_failed_0_, + validationProblem); + } + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/GuiServices/IHydraulicBoundaryLocationCalculationGuiService.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/GuiServices/IHydraulicBoundaryLocationCalculationGuiService.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/GuiServices/IHydraulicBoundaryLocationCalculationGuiService.cs (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -0,0 +1,53 @@ +// 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; +using System.Collections.Generic; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.HydraRing.Data; + +namespace Ringtoets.Integration.Forms.GuiServices +{ + /// + /// Interface for and + /// calculations. + /// + public interface IHydraulicBoundaryLocationCalculationGuiService + { + /// + /// Performs the calculation for all . + /// + /// The assessment section. + /// The objects to calculate + /// the for. + /// Thrown when any input argument is null. + void CalculateDesignWaterLevels(IAssessmentSection assessmentSection, IEnumerable locations); + + /// + /// Performs the calculation for all . + /// + /// The assessment section. + /// The objects to calculate + /// the for. + /// Thrown when any input argument is null. + void CalculateWaveHeights(IAssessmentSection assessmentSection, IEnumerable locations); + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -re05b8947a4f5a41c2cb8b3f5460daf20ab77b2c8 -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision e05b8947a4f5a41c2cb8b3f5460daf20ab77b2c8) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -47,9 +47,9 @@ - + - + Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/DesignWaterLevelLocationsView.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/DesignWaterLevelLocationsView.cs (.../DesignWaterLevelLocationsView.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/DesignWaterLevelLocationsView.cs (.../DesignWaterLevelLocationsView.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -52,7 +52,7 @@ protected override void HandleCalculateSelectedLocations(IEnumerable locations) { - CalculationCommandHandler.CalculateDesignWaterLevels(AssessmentSection, locations); + CalculationGuiService.CalculateDesignWaterLevels(AssessmentSection, locations); } protected override void InitializeDataGridView() Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/HydraulicBoundaryLocationsView.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/HydraulicBoundaryLocationsView.cs (.../HydraulicBoundaryLocationsView.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/HydraulicBoundaryLocationsView.cs (.../HydraulicBoundaryLocationsView.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -30,7 +30,7 @@ using Core.Common.Utils.Reflection; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.Properties; @@ -59,33 +59,15 @@ hydraulicBoundaryDatabaseObserver = new Observer(() => dataGridViewControl.RefreshDataGridView()); } - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - InitializeDataGridView(); - } - - protected virtual void InitializeDataGridView() - { - dataGridViewControl.AddCheckBoxColumn(TypeUtils.GetMemberName(row => row.ToCalculate), - Resources.HydraulicBoundaryLocationsView_Calculate); - dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Name), - Resources.HydraulicBoundaryDatabase_Locations_Name_DisplayName); - dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Id), - Resources.HydraulicBoundaryDatabase_Locations_Id_DisplayName); - dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Location), - Resources.HydraulicBoundaryDatabase_Locations_Coordinates_DisplayName); - } - /// /// Gets or sets the . /// public IApplicationSelection ApplicationSelection { get; set; } /// - /// Gets or sets the . + /// Gets or sets the . /// - public IHydraulicBoundaryLocationCalculationCommandHandler CalculationCommandHandler { get; set; } + public IHydraulicBoundaryLocationCalculationGuiService CalculationGuiService { get; set; } public object Data { @@ -110,6 +92,24 @@ } } + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + InitializeDataGridView(); + } + + protected virtual void InitializeDataGridView() + { + dataGridViewControl.AddCheckBoxColumn(TypeUtils.GetMemberName(row => row.ToCalculate), + Resources.HydraulicBoundaryLocationsView_Calculate); + dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Name), + Resources.HydraulicBoundaryDatabase_Locations_Name_DisplayName); + dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Id), + Resources.HydraulicBoundaryDatabase_Locations_Id_DisplayName); + dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Location), + Resources.HydraulicBoundaryDatabase_Locations_Coordinates_DisplayName); + } + protected override void Dispose(bool disposing) { assessmentSectionObserver.Dispose(); @@ -229,7 +229,7 @@ private void CalculateForSelectedButton_Click(object sender, EventArgs e) { - if (CalculationCommandHandler == null) + if (CalculationGuiService == null) { return; } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs (.../WaveHeightLocationsView.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs (.../WaveHeightLocationsView.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -52,7 +52,7 @@ protected override void HandleCalculateSelectedLocations(IEnumerable locations) { - CalculationCommandHandler.CalculateWaveHeights(AssessmentSection, locations); + CalculationGuiService.CalculateWaveHeights(AssessmentSection, locations); } protected override void InitializeDataGridView() Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -62,6 +62,7 @@ using Ringtoets.Integration.Data.StandAlone; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; @@ -211,7 +212,7 @@ private RingtoetsRibbon ribbonCommandHandler; private IAssessmentSectionFromFileCommandHandler assessmentSectionFromFileCommandHandler; - private IHydraulicBoundaryLocationCalculationCommandHandler hydraulicBoundaryLocationCalculationCommandHandler; + private IHydraulicBoundaryLocationCalculationGuiService hydraulicBoundaryLocationCalculationGuiService; public override IRibbonCommandHandler RibbonCommandHandler { @@ -244,7 +245,7 @@ throw new InvalidOperationException("Gui cannot be null"); } assessmentSectionFromFileCommandHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow, Gui, Gui.DocumentViewController); - hydraulicBoundaryLocationCalculationCommandHandler = new HydraulicBoundaryLocationCalculationCommandHandler(Gui.MainWindow); + hydraulicBoundaryLocationCalculationGuiService = new HydraulicBoundaryLocationCalculationGuiService(Gui.MainWindow); ribbonCommandHandler = new RingtoetsRibbon { @@ -302,7 +303,7 @@ AfterCreate = (view, context) => { view.ApplicationSelection = Gui; - view.CalculationCommandHandler = hydraulicBoundaryLocationCalculationCommandHandler; + view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; } }; @@ -314,7 +315,7 @@ AfterCreate = (view, context) => { view.ApplicationSelection = Gui; - view.CalculationCommandHandler = hydraulicBoundaryLocationCalculationCommandHandler; + view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; } }; @@ -1037,11 +1038,11 @@ RingtoetsCommonFormsResources.CalculateAllIcon, (sender, args) => { - if (hydraulicBoundaryLocationCalculationCommandHandler == null) + if (hydraulicBoundaryLocationCalculationGuiService == null) { return; } - hydraulicBoundaryLocationCalculationCommandHandler.CalculateDesignWaterLevels( + hydraulicBoundaryLocationCalculationGuiService.CalculateDesignWaterLevels( nodeData.WrappedData, nodeData.WrappedData.HydraulicBoundaryDatabase.Locations); }); @@ -1069,11 +1070,11 @@ RingtoetsCommonFormsResources.CalculateAllIcon, (sender, args) => { - if (hydraulicBoundaryLocationCalculationCommandHandler == null) + if (hydraulicBoundaryLocationCalculationGuiService == null) { return; } - hydraulicBoundaryLocationCalculationCommandHandler.CalculateWaveHeights( + hydraulicBoundaryLocationCalculationGuiService.CalculateWaveHeights( nodeData.WrappedData, nodeData.WrappedData.HydraulicBoundaryDatabase.Locations); }); Fisheye: Tag cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Commands/HydraulicBoundaryLocationCommandHandlerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/GuiServices/HydraulicBoundaryLocationGuiServiceTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/GuiServices/HydraulicBoundaryLocationGuiServiceTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/GuiServices/HydraulicBoundaryLocationGuiServiceTest.cs (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -0,0 +1,423 @@ +// 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; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.HydraRing.Data; +using Ringtoets.Integration.Forms.GuiServices; + +namespace Ringtoets.Integration.Forms.Test.GuiServices +{ + [TestFixture] + public class HydraulicBoundaryLocationGuiServiceTest : NUnitFormTest + { + private MockRepository mockRepository; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); + + [SetUp] + public void SetUp() + { + mockRepository = new MockRepository(); + } + + [Test] + public void Constructor_NullMainWindow_ThrowsArgumentNullException() + { + // Setup & Call + TestDelegate test = () => new HydraulicBoundaryLocationCalculationGuiService(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + const string expectedParamName = "viewParent"; + Assert.AreEqual(expectedParamName, paramName); + } + + [Test] + public void Constructor_DefaultValues() + { + // Setup + using (var viewParent = new Form()) + { + // Call + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Assert + Assert.IsInstanceOf(guiService); + } + } + + [Test] + public void CalculateDesignWaterLevels_NullIAssessmentSection_ThrowsArgumentNullException() + { + // Setup + var locations = Enumerable.Empty(); + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + TestDelegate test = () => guiService.CalculateDesignWaterLevels(null, locations); + + // Assert + string paramName = Assert.Throws(test).ParamName; + const string expectedParamName = "assessmentSection"; + Assert.AreEqual(expectedParamName, paramName); + } + } + + [Test] + public void CalculateDesignWaterLevels_NullLocations_ThrowsArgumentNullException() + { + // Setup + var assessmentSectionMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + TestDelegate test = () => guiService.CalculateDesignWaterLevels(assessmentSectionMock, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + const string expectedParamName = "locations"; + Assert.AreEqual(expectedParamName, paramName); + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateDesignWaterLevels_HydraulicDatabaseDoesNotExist_LogsErrorAndDoesNotNotifyObservers() + { + // Setup + var assessmentSectionMock = mockRepository.StrictMock(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = "Does not exist" + }; + assessmentSectionMock.Expect(asm => asm.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase).Repeat.Any(); + + var observerMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + hydraulicBoundaryDatabase.Attach(observerMock); + + var locations = Enumerable.Empty(); + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.CalculateDesignWaterLevels(assessmentSectionMock, locations); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(1, msgs.Length); + StringAssert.StartsWith("Berekeningen konden niet worden gestart. ", msgs.First()); + }); + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateDesignWaterLevels_ValidPathEmptyList_NotifyObserversButNoLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath + }; + var assessmentSectionMock = mockRepository.StrictMock(); + assessmentSectionMock.Expect(asm => asm.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase).Repeat.Any(); + + var observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + mockRepository.ReplayAll(); + + var locations = Enumerable.Empty(); + + hydraulicBoundaryDatabase.Attach(observerMock); + + DialogBoxHandler = (name, wnd) => + { + // Expect an activity dialog which is automatically closed + }; + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.CalculateDesignWaterLevels(assessmentSectionMock, locations); + + // Assert + TestHelper.AssertLogMessagesCount(call, 0); + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateDesignWaterLevels_ValidPathOneLocationInTheList_NotifyObserversAndLogsMessages() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath + }; + + var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), 1.0, 1); + + var assessmentSectionMock = mockRepository.StrictMock(); + assessmentSectionMock.Expect(asm => asm.Id).Return(null); + assessmentSectionMock.Expect(asm => asm.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase).Repeat.AtLeastOnce(); + assessmentSectionMock.Expect(asm => asm.FailureMechanismContribution).Return(failureMechanismContribution); + + var observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + mockRepository.ReplayAll(); + + const string hydraulicLocationName = "name"; + var locations = new List + { + new HydraulicBoundaryLocation(1, hydraulicLocationName, 2, 3) + }; + + hydraulicBoundaryDatabase.Attach(observerMock); + + DialogBoxHandler = (name, wnd) => + { + // Expect an activity dialog which is automatically closed + }; + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.CalculateDesignWaterLevels(assessmentSectionMock, locations); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(6, msgs.Length); + string expectedName = string.Format("Toetspeil voor locatie {0}", hydraulicLocationName); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", expectedName), msgs.First()); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", expectedName), msgs.Skip(1).First()); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", expectedName), msgs.Skip(2).First()); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", expectedName), msgs.Skip(3).First()); + StringAssert.AreNotEqualIgnoringCase(string.Format("Uitvoeren van '{0}' is mislukt.", expectedName), msgs.Last()); + }); + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateWaveHeights_NullIAssessmentSection_ThrowsArgumentNullException() + { + // Setup + var locations = Enumerable.Empty(); + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + TestDelegate test = () => guiService.CalculateWaveHeights(null, locations); + + // Assert + string paramName = Assert.Throws(test).ParamName; + const string expectedParamName = "assessmentSection"; + Assert.AreEqual(expectedParamName, paramName); + } + } + + [Test] + public void CalculateWaveHeights_NullLocations_ThrowsArgumentNullException() + { + // Setup + var assessmentSectionMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + TestDelegate test = () => guiService.CalculateWaveHeights(assessmentSectionMock, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + const string expectedParamName = "locations"; + Assert.AreEqual(expectedParamName, paramName); + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateWaveHeights_HydraulicDatabaseDoesNotExist_LogsErrorAndDoesNotNotifyObservers() + { + // Setup + var assessmentSectionMock = mockRepository.StrictMock(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = "Does not exist" + }; + assessmentSectionMock.Expect(asm => asm.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase).Repeat.Any(); + + var observerMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var locations = Enumerable.Empty(); + + hydraulicBoundaryDatabase.Attach(observerMock); + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.CalculateWaveHeights(assessmentSectionMock, locations); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(1, msgs.Length); + StringAssert.StartsWith("Berekeningen konden niet worden gestart. ", msgs.First()); + }); + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateWaveHeights_ValidPathEmptyList_NotifyObserversButNoLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath + }; + var assessmentSectionMock = mockRepository.StrictMock(); + assessmentSectionMock.Expect(asm => asm.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase).Repeat.Any(); + + var observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + mockRepository.ReplayAll(); + + hydraulicBoundaryDatabase.Attach(observerMock); + + DialogBoxHandler = (name, wnd) => + { + // Expect an activity dialog which is automatically closed + }; + + var locations = Enumerable.Empty(); + + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.CalculateWaveHeights(assessmentSectionMock, locations); + + // Assert + TestHelper.AssertLogMessagesCount(call, 0); + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateWaveHeights_ValidPathOneLocationInTheList_NotifyObserversAndLogsMessages() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath + }; + + var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), 1.0, 1); + + var assessmentSectionMock = mockRepository.StrictMock(); + assessmentSectionMock.Expect(asm => asm.Id).Return(null); + assessmentSectionMock.Expect(asm => asm.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase).Repeat.AtLeastOnce(); + assessmentSectionMock.Expect(asm => asm.FailureMechanismContribution).Return(failureMechanismContribution); + + var observerMock = mockRepository.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + mockRepository.ReplayAll(); + + const string hydraulicLocationName = "name"; + + hydraulicBoundaryDatabase.Attach(observerMock); + + DialogBoxHandler = (name, wnd) => + { + // Expect an activity dialog which is automatically closed + }; + + var locations = new List + { + new HydraulicBoundaryLocation(1, hydraulicLocationName, 2, 3) + }; + using (var viewParent = new Form()) + { + var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.CalculateWaveHeights(assessmentSectionMock, locations); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(6, msgs.Length); + string expectedName = string.Format("Golfhoogte voor locatie {0}", hydraulicLocationName); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", expectedName), msgs.First()); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", expectedName), msgs.Skip(1).First()); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", expectedName), msgs.Skip(2).First()); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", expectedName), msgs.Skip(3).First()); + StringAssert.AreNotEqualIgnoringCase(string.Format("Uitvoeren van '{0}' is mislukt.", expectedName), msgs.Last()); + }); + } + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -re05b8947a4f5a41c2cb8b3f5460daf20ab77b2c8 -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision e05b8947a4f5a41c2cb8b3f5460daf20ab77b2c8) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -66,7 +66,7 @@ - + Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs (.../DesignWaterLevelLocationsViewTest.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs (.../DesignWaterLevelLocationsViewTest.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -34,7 +34,7 @@ using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.Views; namespace Ringtoets.Integration.Forms.Test.Views @@ -209,14 +209,14 @@ rows[0].Cells[locationCalculateColumnIndex].Value = true; var mockRepository = new MockRepository(); - var commandHandlerMock = mockRepository.StrictMock(); + var guiServiceMock = mockRepository.StrictMock(); IEnumerable locations = null; - commandHandlerMock.Expect(ch => ch.CalculateDesignWaterLevels(assessmentSection, null)).IgnoreArguments().WhenCalled( + guiServiceMock.Expect(ch => ch.CalculateDesignWaterLevels(assessmentSection, null)).IgnoreArguments().WhenCalled( invocation => { locations = (IEnumerable) invocation.Arguments[1]; }); mockRepository.ReplayAll(); - view.CalculationCommandHandler = commandHandlerMock; + view.CalculationGuiService = guiServiceMock; var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call @@ -231,7 +231,7 @@ } [Test] - public void CalculateForSelectedButton_OneSelectedButCalculationCommandHandlerNotSet_DoesNotThrowException() + public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup ShowFullyConfiguredDesignWaterLevelLocationsView(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -35,7 +35,7 @@ using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.Views; @@ -341,11 +341,11 @@ { // Setup var mockRepository = new MockRepository(); - var commandHandlerMock = mockRepository.StrictMock(); + var guiServiceMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); TestHydraulicBoundaryLocationsView view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); - view.CalculationCommandHandler = commandHandlerMock; + view.CalculationGuiService = guiServiceMock; var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call @@ -368,10 +368,10 @@ rows[0].Cells[locationCalculateColumnIndex].Value = true; var mockRepository = new MockRepository(); - var commandHandlerMock = mockRepository.StrictMock(); + var guiServiceMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - view.CalculationCommandHandler = commandHandlerMock; + view.CalculationGuiService = guiServiceMock; var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call @@ -385,7 +385,7 @@ } [Test] - public void CalculateForSelectedButton_OneSelectedButCalculationCommandHandlerNotSet_DoesNotThrowException() + public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs (.../WaveHeightLocationsViewTest.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs (.../WaveHeightLocationsViewTest.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -34,7 +34,7 @@ using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.Views; namespace Ringtoets.Integration.Forms.Test.Views @@ -205,14 +205,14 @@ rows[0].Cells[locationCalculateColumnIndex].Value = true; var mockRepository = new MockRepository(); - var commandHandlerMock = mockRepository.StrictMock(); + var guiServiceMock = mockRepository.StrictMock(); IEnumerable locations = null; - commandHandlerMock.Expect(ch => ch.CalculateWaveHeights(assessmentSection, null)).IgnoreArguments().WhenCalled( + guiServiceMock.Expect(ch => ch.CalculateWaveHeights(assessmentSection, null)).IgnoreArguments().WhenCalled( invocation => { locations = (IEnumerable) invocation.Arguments[1]; }); mockRepository.ReplayAll(); - view.CalculationCommandHandler = commandHandlerMock; + view.CalculationGuiService = guiServiceMock; var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call @@ -227,7 +227,7 @@ } [Test] - public void CalculateForSelectedButton_OneSelectedButCalculationCommandHandlerNotSet_DoesNotThrowException() + public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup ShowFullyConfiguredWaveHeightLocationsView(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelLocationsViewInfoTest.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelLocationsViewInfoTest.cs (.../DesignWaterLevelLocationsViewInfoTest.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelLocationsViewInfoTest.cs (.../DesignWaterLevelLocationsViewInfoTest.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -32,6 +32,7 @@ using Ringtoets.Common.Forms.Properties; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.Views; @@ -154,7 +155,7 @@ info.AfterCreate(view, context); // Assert - Assert.IsInstanceOf(view.CalculationCommandHandler); + Assert.IsInstanceOf(view.CalculationGuiService); Assert.AreSame(view.ApplicationSelection, guiStub); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightLocationsViewInfoTest.cs =================================================================== diff -u -r6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightLocationsViewInfoTest.cs (.../WaveHeightLocationsViewInfoTest.cs) (revision 6ecd02f5f7c642d5624f1e52f528c51b1bf5ab3a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightLocationsViewInfoTest.cs (.../WaveHeightLocationsViewInfoTest.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -32,6 +32,7 @@ using Ringtoets.Common.Forms.Properties; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.Views; @@ -155,7 +156,7 @@ info.AfterCreate(view, context); // Assert - Assert.IsInstanceOf(view.CalculationCommandHandler); + Assert.IsInstanceOf(view.CalculationGuiService); Assert.AreSame(view.ApplicationSelection, guiStub); } mocks.VerifyAll(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/StochasticSoilModelPropertiesTest.cs =================================================================== diff -u -r63f8609a55959d62ba00e8b28871ed274f00a0ca -rcf6cf1e068381a14a9dfdbc65ef71be45e7c25e5 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/StochasticSoilModelPropertiesTest.cs (.../StochasticSoilModelPropertiesTest.cs) (revision 63f8609a55959d62ba00e8b28871ed274f00a0ca) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/StochasticSoilModelPropertiesTest.cs (.../StochasticSoilModelPropertiesTest.cs) (revision cf6cf1e068381a14a9dfdbc65ef71be45e7c25e5) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.ComponentModel; using Core.Common.Base.Geometry; @@ -100,8 +101,11 @@ // Assert var dynamicPropertyBag = new DynamicPropertyBag(properties); - PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(); - Assert.AreEqual(6, dynamicProperties.Count); + PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[] + { + BrowsableAttribute.Yes + }); + Assert.AreEqual(5, dynamicProperties.Count); PropertyDescriptor stochasticSoilModelIdProperty = dynamicProperties[stochasticSoilModelIdPropertyIndex]; Assert.IsNotNull(stochasticSoilModelIdProperty);