// Copyright (C) Stichting Deltares 2017. 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.Collections.Generic; using System.Drawing; using System.Linq; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; using Core.Components.Charting.Data; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; using Ringtoets.Integration.Data; using Ringtoets.Revetment.Data; using Ringtoets.Revetment.Forms.PresentationObjects; using Ringtoets.Revetment.Forms.TestUtil; using Ringtoets.Revetment.Forms.Views; using Ringtoets.Revetment.TestUtil; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.StabilityStoneCover.Forms.PresentationObjects; using Ringtoets.WaveImpactAsphaltCover.Data; using Ringtoets.WaveImpactAsphaltCover.Forms.PresentationObjects; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Plugin.Test.ViewInfos { [TestFixture] public class WaveConditionsInputViewInfoTest { private RingtoetsPlugin plugin; private ViewInfo info; [SetUp] public void SetUp() { plugin = new RingtoetsPlugin(); info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(WaveConditionsInputView)); } [TearDown] public void TearDown() { plugin.Dispose(); } [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Assert Assert.AreEqual(typeof(WaveConditionsInputContext), info.DataType); Assert.AreEqual(typeof(ICalculation), info.ViewDataType); TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, info.Image); } [Test] public void GetViewName_Always_ReturnsInputResourceName() { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle())) { var calculation = new TestWaveConditionsCalculation(); // Call string viewName = info.GetViewName(view, calculation); // Assert Assert.AreEqual("Invoer", viewName); } } [Test] public void GetViewData_Always_ReturnsWrappedCalculation() { // Setup var input = new WaveConditionsInput(); var calculation = new TestWaveConditionsCalculation(); var context = new TestWaveConditionsInputContext(input, calculation, new ForeshoreProfile[0], new HydraulicBoundaryLocation[0]); // Call object viewData = info.GetViewData(context); // Assert Assert.AreEqual(calculation, viewData); } [Test] [TestCaseSource(nameof(GetCalculationContextDatas), new object[] { "CloseForData_CorrespondingToCalculationContext_ReturnTrue({0})" })] public void CloseForData_ViewCorrespondingToRemovedCalculationContext_ReturnsTrue( ICalculationContext, IFailureMechanism> context, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, context); // Assert Assert.IsTrue(closeForData); } } [Test] [TestCaseSource(nameof(GetCalculationContextDatas), new object[] { "CloseForData_NotCorrespondingToCalculationContext_ReturnFalse({0})" })] public void CloseForData_ViewNotCorrespondingToRemovedCalculationContext_ReturnsFalse( ICalculationContext, IFailureMechanism> context, ICalculation calculation) { // Setup var calculationToRemove = new TestWaveConditionsCalculation(); using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculationToRemove }) { // Call bool closeForData = info.CloseForData(view, context); // Assert Assert.IsFalse(closeForData); } } [Test] [TestCaseSource(nameof(GetCalculationGroupDatas), new object[] { "CloseForData_CorrespondingWithCalculationGroupContext_ReturnTrue({0})" })] public void CloseForData_ViewCorrespondingWithRemovedCalculationGroupContext_ReturnsTrue( ICalculationContext context, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, context); // Assert Assert.IsTrue(closeForData); } } [Test] [TestCaseSource(nameof(GetCalculationGroupDatas), new object[] { "CloseForData_NotCorrespondingWithCalculationGroupContext_ReturnFalse({0})" })] public void CloseForData_ViewNotCorrespondingWithRemovedCalculationGroupContext_ReturnsFalse( ICalculationContext context, ICalculation calculation) { // Setup var contextToRemove = new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext(new CalculationGroup(), new GrassCoverErosionOutwardsFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)); using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, contextToRemove); // Assert Assert.IsFalse(closeForData); } } [Test] [TestCaseSource(nameof(GetFailureMechanismContextDatas), new object[] { "CloseForData_CorrespondingWithFailureMechanismContext_ReturnTrue({0})" })] public void CloseForData_ViewCorrespondingWithRemovedFailureMechanismContext_ReturnsTrue( IFailureMechanismContext context, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, context); // Assert Assert.IsTrue(closeForData); } } [Test] [TestCaseSource(nameof(GetFailureMechanismContextDatas), new object[] { "CloseForData_NotCorrespondingWithFailureMechanismContext_ReturnFalse({0})" })] public void CloseForData_ViewNotCorrespondingWithRemovedFailureMechanismContext_ReturnsFalse( IFailureMechanismContext context, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, new FailureMechanismContext( new TestFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike))); // Assert Assert.IsFalse(closeForData); } } [Test] [TestCaseSource(nameof(GetFailureMechanismDatas), new object[] { "CloseForData_CorrespondingWithFailureMechanism_ReturnTrue({0})" })] public void CloseForData_ViewCorrespondingWithRemovedFailureMechanism_ReturnsTrue( IFailureMechanism failureMechanism, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, failureMechanism); // Assert Assert.IsTrue(closeForData); } } [Test] [TestCaseSource(nameof(GetFailureMechanismDatas), new object[] { "CloseForData_NotCorrespondingWithFailureMechanism_ReturnFalse({0})" })] public void CloseForData_ViewNotCorrespondingWithRemovedFailureMechanism_ReturnsFalse( IFailureMechanism failureMechanism, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, new TestFailureMechanism()); // Assert Assert.IsFalse(closeForData); } } [Test] [TestCaseSource(nameof(GetAssessmentSectionDatas), new object[] { "CloseForData_CorrespondingWithAssessmentSection_ReturnTrue({0})" })] public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue(AssessmentSection assessmentSection, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, assessmentSection); // Assert Assert.IsTrue(closeForData); } } [Test] [TestCaseSource(nameof(GetAssessmentSectionDatas), new object[] { "CloseForData_NotCorrespondingWithAssessmentSection_ReturnFalse({0})" })] public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse(AssessmentSection assessmentSection, ICalculation calculation) { // Setup using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = new TestWaveConditionsCalculation() }) { // Call bool closeForData = info.CloseForData(view, assessmentSection); // Assert Assert.IsFalse(closeForData); } } [Test] [TestCaseSource(nameof(GetCalculationGroupDatas), new object[] { "CloseForData_NestedCorrespondingWithCalculationGroupContext_ReturnTrue({0})" })] public void CloseForData_NestedViewCorrespondingWithRemovedCalculationGroupContext_ReturnsTrue( ICalculationContext context, ICalculation calculation) { // Setup context.WrappedData.Children.RemoveAt(0); context.WrappedData.Children.Add(new CalculationGroup { Children = { calculation } }); using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, context); // Assert Assert.IsTrue(closeForData); } } [Test] [TestCaseSource(nameof(GetCalculationGroupDatas), new object[] { "CloseForData_NestedNotCorrespondingWithCalculationGroupContext_ReturnFalse({0})" })] public void CloseForData_NestedViewNotCorrespondingWithRemovedCalculationGroupContext_ReturnsFalse( ICalculationContext context, ICalculation calculation) { // Setup context.WrappedData.Children.RemoveAt(0); context.WrappedData.Children.Add(new CalculationGroup { Children = { calculation } }); var contextToRemove = new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext(new CalculationGroup(), new GrassCoverErosionOutwardsFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)); using (var view = new WaveConditionsInputView(new TestWaveConditionsInputViewStyle()) { Data = calculation }) { // Call bool closeForData = info.CloseForData(view, contextToRemove); // Assert Assert.IsFalse(closeForData); } } [Test] [TestCaseSource(nameof(GetInputContextDatas))] public void CreateInstance_WaveConditionsInputContext_ReturnViewWithStylingApplied(WaveConditionsInputContext context, Color revetmentLineColor, string designWaterLevelName) { // Call var view = (WaveConditionsInputView) info.CreateInstance(context); view.Data = context.Calculation; // Assert ChartDataCollection chartData = view.Chart.Data; var revetmentChartData = (ChartLineData) chartData.Collection.ElementAt(revetmentChartDataIndex); var revetmentBaseChartData = (ChartLineData) chartData.Collection.ElementAt(revetmentBaseChartDataIndex); var lowerBoundaryRevetmentChartData = (ChartLineData) chartData.Collection.ElementAt(lowerBoundaryRevetmentChartDataIndex); var upperBoundaryRevetmentChartData = (ChartLineData) chartData.Collection.ElementAt(upperBoundaryRevetmentChartDataIndex); var designWaterLevelChartData = (ChartLineData) chartData.Collection.ElementAt(designWaterLevelChartDataIndex); Assert.AreEqual(revetmentLineColor, revetmentChartData.Style.Color); Assert.AreEqual(Color.FromArgb(120, revetmentLineColor), revetmentBaseChartData.Style.Color); Assert.AreEqual(revetmentLineColor, lowerBoundaryRevetmentChartData.Style.Color); Assert.AreEqual(revetmentLineColor, upperBoundaryRevetmentChartData.Style.Color); Assert.AreEqual(designWaterLevelName, designWaterLevelChartData.Name); } #region TestCaseData private const int lowerBoundaryRevetmentChartDataIndex = 1; private const int upperBoundaryRevetmentChartDataIndex = 2; private const int designWaterLevelChartDataIndex = 5; private const int revetmentBaseChartDataIndex = 7; private const int revetmentChartDataIndex = 8; private static IEnumerable GetInputContextDatas() { yield return new TestCaseData( new GrassCoverErosionOutwardsWaveConditionsInputContext( new WaveConditionsInput(), new GrassCoverErosionOutwardsWaveConditionsCalculation(), new GrassCoverErosionOutwardsFailureMechanism()), Color.Green, "Waterstand bij doorsnede-eis") .SetName("Grass outwards input context"); yield return new TestCaseData( new StabilityStoneCoverWaveConditionsInputContext( new WaveConditionsInput(), new StabilityStoneCoverWaveConditionsCalculation(), new ForeshoreProfile[0], new AssessmentSection(AssessmentSectionComposition.Dike)), Color.Gray, "Toetspeil") .SetName("Stability stone cover input context"); yield return new TestCaseData( new WaveImpactAsphaltCoverWaveConditionsInputContext( new WaveConditionsInput(), new WaveImpactAsphaltCoverWaveConditionsCalculation(), new ForeshoreProfile[0], new AssessmentSection(AssessmentSectionComposition.Dike)), Color.Gray, "Toetspeil") .SetName("Wave impact asphalt cover input context"); } private static IEnumerable GetCalculationContextDatas(string testNameFormat) { var grassCoverErosionOutwardsWaveConditionsCalculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); yield return new TestCaseData( new GrassCoverErosionOutwardsWaveConditionsCalculationContext( grassCoverErosionOutwardsWaveConditionsCalculation, new GrassCoverErosionOutwardsFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)), grassCoverErosionOutwardsWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(GrassCoverErosionOutwardsWaveConditionsCalculation))); var stabilityStoneCoverWaveConditionsCalculation = new StabilityStoneCoverWaveConditionsCalculation(); yield return new TestCaseData( new StabilityStoneCoverWaveConditionsCalculationContext( stabilityStoneCoverWaveConditionsCalculation, new StabilityStoneCoverFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)), stabilityStoneCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(StabilityStoneCoverWaveConditionsCalculation))); var waveImpactAsphaltCoverWaveConditionsCalculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); yield return new TestCaseData( new WaveImpactAsphaltCoverWaveConditionsCalculationContext( waveImpactAsphaltCoverWaveConditionsCalculation, new WaveImpactAsphaltCoverFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)), waveImpactAsphaltCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(WaveImpactAsphaltCoverWaveConditionsCalculation))); } private static IEnumerable GetFailureMechanismDatas(string testNameFormat) { var grassCoverErosionOutwardsWaveConditionsCalculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); yield return new TestCaseData( GetFailureMechanism(grassCoverErosionOutwardsWaveConditionsCalculation), grassCoverErosionOutwardsWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(GrassCoverErosionOutwardsFailureMechanism))); var stabilityStoneCoverWaveConditionsCalculation = new StabilityStoneCoverWaveConditionsCalculation(); yield return new TestCaseData( GetFailureMechanism(stabilityStoneCoverWaveConditionsCalculation), stabilityStoneCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(StabilityStoneCoverFailureMechanism))); var waveImpactAsphaltCoverWaveConditionsCalculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); yield return new TestCaseData( GetFailureMechanism(waveImpactAsphaltCoverWaveConditionsCalculation), waveImpactAsphaltCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(WaveImpactAsphaltCoverFailureMechanism))); } private static IEnumerable GetFailureMechanismContextDatas(string testNameFormat) { var grassCoverErosionOutwardsWaveConditionsCalculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); yield return new TestCaseData( new GrassCoverErosionOutwardsFailureMechanismContext( GetFailureMechanism(grassCoverErosionOutwardsWaveConditionsCalculation), new AssessmentSection(AssessmentSectionComposition.Dike)), grassCoverErosionOutwardsWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(GrassCoverErosionOutwardsFailureMechanismContext))); var stabilityStoneCoverWaveConditionsCalculation = new StabilityStoneCoverWaveConditionsCalculation(); yield return new TestCaseData( new StabilityStoneCoverFailureMechanismContext( GetFailureMechanism(stabilityStoneCoverWaveConditionsCalculation), new AssessmentSection(AssessmentSectionComposition.Dike)), stabilityStoneCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(StabilityStoneCoverFailureMechanismContext))); var waveImpactAsphaltCoverWaveConditionsCalculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); yield return new TestCaseData( new WaveImpactAsphaltCoverFailureMechanismContext( GetFailureMechanism(waveImpactAsphaltCoverWaveConditionsCalculation), new AssessmentSection(AssessmentSectionComposition.Dike)), waveImpactAsphaltCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(WaveImpactAsphaltCoverFailureMechanismContext))); } private static IEnumerable GetCalculationGroupDatas(string testNameFormat) { var grassCoverErosionOutwardsWaveConditionsCalculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); yield return new TestCaseData( new GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext( new CalculationGroup { Children = { grassCoverErosionOutwardsWaveConditionsCalculation } }, new GrassCoverErosionOutwardsFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)), grassCoverErosionOutwardsWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(GrassCoverErosionOutwardsWaveConditionsCalculationGroupContext))); var stabilityStoneCoverWaveConditionsCalculation = new StabilityStoneCoverWaveConditionsCalculation(); yield return new TestCaseData( new StabilityStoneCoverWaveConditionsCalculationGroupContext( new CalculationGroup { Children = { stabilityStoneCoverWaveConditionsCalculation } }, new StabilityStoneCoverFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)), stabilityStoneCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(StabilityStoneCoverWaveConditionsCalculationGroupContext))); var waveImpactAsphaltCoverWaveConditionsCalculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); yield return new TestCaseData( new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext( new CalculationGroup { Children = { waveImpactAsphaltCoverWaveConditionsCalculation } }, new WaveImpactAsphaltCoverFailureMechanism(), new AssessmentSection(AssessmentSectionComposition.Dike)), waveImpactAsphaltCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, nameof(WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext))); } private static IEnumerable GetAssessmentSectionDatas(string testNameFormat) { var grassCoverErosionOutwardsWaveConditionsCalculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); yield return new TestCaseData( new AssessmentSection(AssessmentSectionComposition.Dike) { GrassCoverErosionOutwards = { WaveConditionsCalculationGroup = { Children = { grassCoverErosionOutwardsWaveConditionsCalculation } } } }, grassCoverErosionOutwardsWaveConditionsCalculation) .SetName(string.Format(testNameFormat, "assessmentSectionGrassCoverErosionOutwards")); var stabilityStoneCoverWaveConditionsCalculation = new StabilityStoneCoverWaveConditionsCalculation(); yield return new TestCaseData( new AssessmentSection(AssessmentSectionComposition.Dike) { StabilityStoneCover = { WaveConditionsCalculationGroup = { Children = { stabilityStoneCoverWaveConditionsCalculation } } } }, stabilityStoneCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, "assessmentSectionStabilityStoneCover")); var waveImpactAsphaltCoverWaveConditionsCalculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); yield return new TestCaseData( new AssessmentSection(AssessmentSectionComposition.Dike) { WaveImpactAsphaltCover = { WaveConditionsCalculationGroup = { Children = { waveImpactAsphaltCoverWaveConditionsCalculation } } } }, waveImpactAsphaltCoverWaveConditionsCalculation) .SetName(string.Format(testNameFormat, "assessmentSectionWaveImpactAsphaltCover")); } private static GrassCoverErosionOutwardsFailureMechanism GetFailureMechanism(GrassCoverErosionOutwardsWaveConditionsCalculation calculation) { return new GrassCoverErosionOutwardsFailureMechanism { WaveConditionsCalculationGroup = { Children = { calculation } } }; } private static StabilityStoneCoverFailureMechanism GetFailureMechanism(StabilityStoneCoverWaveConditionsCalculation calculation) { return new StabilityStoneCoverFailureMechanism { WaveConditionsCalculationGroup = { Children = { calculation } } }; } private static WaveImpactAsphaltCoverFailureMechanism GetFailureMechanism(WaveImpactAsphaltCoverWaveConditionsCalculation calculation) { return new WaveImpactAsphaltCoverFailureMechanism { WaveConditionsCalculationGroup = { Children = { calculation } } }; } #endregion } }