// 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 Core.Common.Base; using Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.Common.Data; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; namespace Ringtoets.Common.Service.Test { [TestFixture] public class RingtoetsCommonDataSynchronizationServiceTest { [Test] public void ClearHydraulicBoundaryLocationOutput_LocationsNull_ThrowsArgumentNullException() { // Call TestDelegate test = () => RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(null); // Assert var exception = Assert.Throws(test); Assert.AreEqual("locations", exception.ParamName); } [Test] public void ClearHydraulicBoundaryLocationOutput_LocationWithData_ClearsDataAndReturnsAffectedObjects( [Values(3.4, double.NaN)] double designWaterLevel, [Values(5.3, double.NaN)] double waveHeight) { // Setup HydraulicBoundaryLocation location = new TestHydraulicBoundaryLocation { DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput(designWaterLevel), WaveHeightOutput = new TestHydraulicBoundaryLocationOutput(waveHeight) }; var locations = new ObservableList { location }; // Call IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(locations); // Assert Assert.IsNull(location.DesignWaterLevelOutput); Assert.IsNull(location.WaveHeightOutput); Assert.IsNaN(location.DesignWaterLevel); Assert.IsNaN(location.WaveHeight); Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); CollectionAssert.AreEqual(new[] { location }, affectedObjects); } [Test] public void ClearHydraulicBoundaryLocationOutput_HydraulicBoundaryDatabaseWithoutLocations_ReturnsNoAffectedObjects() { // Setup IEnumerable locations = new ObservableList(); // Call IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(locations); // Assert CollectionAssert.IsEmpty(affectedObjects); } [Test] public void ClearHydraulicBoundaryLocationOutput_LocationWithoutWaveHeightAndDesignWaterLevel_ReturnsNoAffectedObjects() { // Setup var locations = new ObservableList { new TestHydraulicBoundaryLocation() }; // Call IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(locations); // Assert CollectionAssert.IsEmpty(affectedObjects); } [Test] public void ClearCalculationOutput_CalculationNull_ThrowsArgumentNullException() { // Setup StructuresCalculation calculation = null; // Call TestDelegate test = () => RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); // Assert var exception = Assert.Throws(test); Assert.AreEqual("calculation", exception.ParamName); } [Test] public void ClearCalculationOutput_WithCalculation_ClearsOutput() { // Setup var calculation = new StructuresCalculation { Output = new ProbabilityAssessmentOutput(1, 1, 1, 1, 1) }; // Call IEnumerable changedObjects = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); // Assert // Note: To make sure the clear is performed regardless of what is done with // the return result, no ToArray() should be called before these assertions: Assert.IsNull(calculation.Output); CollectionAssert.AreEqual(new[] { calculation }, changedObjects); } [Test] public void ClearCalculationOutput_CalculationWithoutOutput_DoNothing() { // Setup var calculation = new StructuresCalculation { Output = null }; // Call IEnumerable changedObjects = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); // Assert CollectionAssert.IsEmpty(changedObjects); } [Test] public void ClearForeshoreProfile_CalculationsWithForeshoreProfile_ClearForeshoreProfileAndReturnAffectedInputs() { // Setup var foreshoreProfileToBeRemoved = new TestForeshoreProfile(new Point2D(0, 0)); var foreshoreProfile = new TestForeshoreProfile(new Point2D(1, 1)); var calculation1 = new StructuresCalculation { InputParameters = { ForeshoreProfile = foreshoreProfile } }; var calculation2 = new StructuresCalculation { InputParameters = { ForeshoreProfile = foreshoreProfileToBeRemoved } }; var calculations = new[] { calculation1, calculation2 }; // Call IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearForeshoreProfile( calculations, foreshoreProfileToBeRemoved); // Assert Assert.IsNull(calculation2.InputParameters.ForeshoreProfile); Assert.IsNotNull(calculation1.InputParameters.ForeshoreProfile); CollectionAssert.AreEqual(new[] { calculation2.InputParameters }, affectedObjects); } private class TestInput : ICalculationInput { public void Attach(IObserver observer) { throw new NotImplementedException(); } public void Detach(IObserver observer) { throw new NotImplementedException(); } public void NotifyObservers() { throw new NotImplementedException(); } } private class SimpleStructuresInput : StructuresInputBase { protected override void UpdateStructureParameters() {} } } }