// 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.ComponentModel;
using Core.Common.Base;
using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.Gui.PropertyBag;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Forms.PropertyClasses;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses;
using Ringtoets.HydraRing.Data;
namespace Ringtoets.GrassCoverErosionInwards.Forms.Test.PropertyClasses
{
[TestFixture]
public class GrassCoverErosionInwardsInputContextPropertiesTest
{
private const int dikeProfilePropertyIndex = 0;
private const int worldReferencePointPropertyIndex = 1;
private const int orientationPropertyIndex = 2;
private const int breakWaterPropertyIndex = 3;
private const int foreshorePropertyIndex = 4;
private const int dikeGeometryPropertyIndex = 5;
private const int dikeHeightPropertyIndex = 6;
private const int criticalFlowRatePropertyIndex = 7;
private const int hydraulicBoundaryLocationPropertyIndex = 8;
private const int calculateDikeHeightPropertyIndex = 9;
private MockRepository mockRepository;
[SetUp]
public void SetUp()
{
mockRepository = new MockRepository();
}
[Test]
public void Constructor_ExpectedValues()
{
// Call
var properties = new GrassCoverErosionInwardsInputContextProperties();
// Assert
Assert.IsInstanceOf>(properties);
Assert.IsNull(properties.Data);
}
[Test]
public void Data_SetNewInputContextInstance_ReturnCorrectPropertyValues()
{
// Setup
var assessmentSectionMock = mockRepository.StrictMock();
var failureMechanismMock = mockRepository.StrictMock();
var calculationMock = mockRepository.StrictMock();
mockRepository.ReplayAll();
var input = new GrassCoverErosionInwardsInput
{
HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "", 0, 0)
};
var inputContext = new GrassCoverErosionInwardsInputContext(input, calculationMock, failureMechanismMock, assessmentSectionMock);
// Call
var properties = new GrassCoverErosionInwardsInputContextProperties
{
Data = inputContext
};
// Assert
Assert.AreEqual(2, properties.Orientation.NumberOfDecimalPlaces);
Assert.IsNull(properties.DikeProfile);
Assert.AreEqual(0.0, properties.Orientation.Value);
Assert.IsInstanceOf(properties.BreakWater);
Assert.IsInstanceOf(properties.Foreshore);
Assert.AreSame(inputContext, properties.DikeGeometry.Data);
Assert.AreEqual(2, properties.DikeHeight.NumberOfDecimalPlaces);
Assert.AreEqual(0.0, properties.DikeHeight.Value);
Assert.AreEqual(input.CriticalFlowRate.Mean, properties.CriticalFlowRate.Mean);
Assert.AreEqual(input.CriticalFlowRate.StandardDeviation, properties.CriticalFlowRate.StandardDeviation);
Assert.AreSame(input.HydraulicBoundaryLocation, properties.HydraulicBoundaryLocation);
Assert.AreEqual(input.CalculateDikeHeight, properties.CalculateDikeHeight);
Assert.IsNull(properties.WorldReferencePoint);
mockRepository.VerifyAll();
}
[Test]
public void Data_SetNewInputContextInstanceWithDikeProfile_ReturnCorrectPropertyValues()
{
// Setup
var assessmentSectionMock = mockRepository.StrictMock();
var failureMechanismMock = mockRepository.StrictMock();
var calculationMock = mockRepository.StrictMock();
mockRepository.ReplayAll();
var input = new GrassCoverErosionInwardsInput
{
DikeProfile = new DikeProfile(new Point2D(12.34, 56.78), new RoughnessPoint[0], new Point2D[0],
null, new DikeProfile.ConstructionProperties()),
HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "", 0, 0)
};
var inputContext = new GrassCoverErosionInwardsInputContext(input, calculationMock, failureMechanismMock, assessmentSectionMock);
// Call
var properties = new GrassCoverErosionInwardsInputContextProperties
{
Data = inputContext
};
// Assert
Assert.AreEqual(2, properties.Orientation.NumberOfDecimalPlaces);
Assert.AreSame(input.DikeProfile, properties.DikeProfile);
Assert.AreEqual(0.0, properties.Orientation.Value);
Assert.IsInstanceOf(properties.BreakWater);
Assert.IsInstanceOf(properties.Foreshore);
Assert.AreSame(inputContext, properties.DikeGeometry.Data);
Assert.AreEqual(2, properties.DikeHeight.NumberOfDecimalPlaces);
Assert.AreEqual(0.0, properties.DikeHeight.Value);
Assert.AreEqual(input.CriticalFlowRate.Mean, properties.CriticalFlowRate.Mean);
Assert.AreEqual(input.CriticalFlowRate.StandardDeviation, properties.CriticalFlowRate.StandardDeviation);
Assert.AreSame(input.HydraulicBoundaryLocation, properties.HydraulicBoundaryLocation);
Assert.AreEqual(input.CalculateDikeHeight, properties.CalculateDikeHeight);
Assert.AreEqual(new Point2D(12, 57), properties.WorldReferencePoint);
mockRepository.VerifyAll();
}
[Test]
public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers()
{
// Setup
var observerMock = mockRepository.StrictMock();
const int numberProperties = 5;
observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(numberProperties);
var assessmentSectionMock = mockRepository.StrictMock();
var failureMechanismMock = mockRepository.StrictMock();
var calculationMock = mockRepository.StrictMock();
mockRepository.ReplayAll();
var input = new GrassCoverErosionInwardsInput();
input.Attach(observerMock);
var properties = new GrassCoverErosionInwardsInputContextProperties
{
Data = new GrassCoverErosionInwardsInputContext(input, calculationMock, failureMechanismMock, assessmentSectionMock)
};
var newDikeProfile = new DikeProfile(new Point2D(0, 0), new RoughnessPoint[0], new Point2D[0],
null, new DikeProfile.ConstructionProperties());
var newDikeHeight = new RoundedDouble(2, 9);
var newOrientation = new RoundedDouble(2, 5);
var newHydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "name", 0.0, 1.1);
// Call
properties.DikeProfile = newDikeProfile;
properties.Orientation = newOrientation;
properties.DikeHeight = newDikeHeight;
properties.HydraulicBoundaryLocation = newHydraulicBoundaryLocation;
properties.CalculateDikeHeight = true;
// Assert
Assert.AreSame(newDikeProfile, input.DikeProfile);
Assert.AreEqual(newOrientation, input.Orientation);
Assert.AreEqual(newDikeHeight, input.DikeHeight);
Assert.AreSame(newHydraulicBoundaryLocation, input.HydraulicBoundaryLocation);
Assert.IsTrue(input.CalculateDikeHeight);
mockRepository.VerifyAll();
}
[TestCase(true)]
[TestCase(false)]
public void PropertyAttributes_ReturnExpectedValues(bool withDikeProfile)
{
// Setup
var assessmentSectionMock = mockRepository.StrictMock();
mockRepository.ReplayAll();
var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
var calculation = new GrassCoverErosionInwardsCalculation();
var input = new GrassCoverErosionInwardsInput();
if (withDikeProfile)
{
input.DikeProfile = new DikeProfile(new Point2D(0, 0), new RoughnessPoint[0], new Point2D[0],
null, new DikeProfile.ConstructionProperties());
}
// Call
var properties = new GrassCoverErosionInwardsInputContextProperties
{
Data = new GrassCoverErosionInwardsInputContext(input, calculation, failureMechanism, assessmentSectionMock)
};
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(10, dynamicProperties.Count);
PropertyDescriptor dikeProfileProperty = dynamicProperties[dikeProfilePropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dikeProfileProperty,
"Schematisatie",
"Dijkprofiel",
"De schematisatie van het dijkprofiel.");
PropertyDescriptor worldReferencePointProperty = dynamicProperties[worldReferencePointPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(worldReferencePointProperty,
"Schematisatie",
"Locatie (RD) [m]",
"De coördinaten van de locatie van de dijk in het Rijksdriehoeksstelsel.",
true);
PropertyDescriptor orientationProperty = dynamicProperties[orientationPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(orientationProperty,
"Schematisatie",
"Oriëntatie [°]",
"Oriëntatie van de dijknormaal ten opzichte van het noorden.",
!withDikeProfile);
PropertyDescriptor breakWaterProperty = dynamicProperties[breakWaterPropertyIndex];
Assert.IsInstanceOf(breakWaterProperty.Converter);
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(breakWaterProperty,
"Schematisatie",
"Dam",
"Eigenschappen van de dam.",
true);
PropertyDescriptor foreshoreProperty = dynamicProperties[foreshorePropertyIndex];
Assert.IsInstanceOf(foreshoreProperty.Converter);
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(foreshoreProperty,
"Schematisatie",
"Voorlandgeometrie",
"Eigenschappen van de voorlandgeometrie.",
true);
PropertyDescriptor dikeGeometryProperty = dynamicProperties[dikeGeometryPropertyIndex];
Assert.IsInstanceOf(dikeGeometryProperty.Converter);
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dikeGeometryProperty,
"Schematisatie",
"Dijkgeometrie",
"Eigenschappen van de dijkgeometrie.",
true);
PropertyDescriptor dikeHeightProperty = dynamicProperties[dikeHeightPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dikeHeightProperty,
"Schematisatie",
"Dijkhoogte [m+NAP]",
"De hoogte van de dijk.",
!withDikeProfile);
PropertyDescriptor criticalFlowRateProperty = dynamicProperties[criticalFlowRatePropertyIndex];
Assert.IsInstanceOf(criticalFlowRateProperty.Converter);
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(criticalFlowRateProperty,
"Toetseisen",
"Kritisch overslagdebiet [m³/s/m]",
"Kritisch overslagdebiet per strekkende meter.",
true);
PropertyDescriptor hydraulicBoundaryLocationProperty = dynamicProperties[hydraulicBoundaryLocationPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(hydraulicBoundaryLocationProperty,
"Hydraulische gegevens",
"Locatie met hydraulische randvoorwaarden",
"De locatie met hydraulische randvoorwaarden.");
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[calculateDikeHeightPropertyIndex],
"Schematisatie",
"HBN berekenen",
"Geeft aan of ook het Hydraulisch Belasting Niveau (HBN) moet worden berekend.");
mockRepository.VerifyAll();
}
}
}