// 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.ComponentModel;
using Core.Common.Base;
using Core.Common.Base.Data;
using Core.Common.Gui.PropertyBag;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Data.Properties;
using Ringtoets.GrassCoverErosionOutwards.Forms.PropertyClasses;
using Ringtoets.HydraRing.Data;
namespace Ringtoets.GrassCoverErosionOutwards.Forms.Test.PropertyClasses
{
[TestFixture]
public class GrassCoverErosionOutwardsFailureMechanismPropertiesTest
{
[Test]
public void Constructor_ExpectedValues()
{
// Call
var properties = new GrassCoverErosionOutwardsFailureMechanismProperties();
// Assert
Assert.IsInstanceOf>(properties);
Assert.IsNull(properties.Data);
}
[Test]
public void Data_SetNewFailureMechanismContextInstance_ReturnCorrectPropertyValues()
{
// Setup
var properties = new GrassCoverErosionOutwardsFailureMechanismProperties();
// Call
properties.Data = new GrassCoverErosionOutwardsFailureMechanism();
// Assert
Assert.AreEqual(Resources.GrassCoverErosionOutwardsFailureMechanism_DisplayName, properties.Name);
Assert.AreEqual(Resources.GrassCoverErosionOutwardsFailureMechanism_Code, properties.Code);
Assert.AreEqual(2, properties.LengthEffect);
}
[Test]
public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers()
{
// Setup
var mockRepository = new MockRepository();
var observerMock = mockRepository.StrictMock();
int numberProperties = 1;
observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(numberProperties);
mockRepository.ReplayAll();
var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
failureMechanism.Attach(observerMock);
var properties = new GrassCoverErosionOutwardsFailureMechanismProperties
{
Data = failureMechanism
};
const int newLengthEffect = 10;
// Call
properties.LengthEffect = newLengthEffect;
// Assert
Assert.AreEqual(newLengthEffect, failureMechanism.GeneralInput.N);
mockRepository.VerifyAll();
}
[Test]
public void PropertyAttributes_ReturnExpectedValues()
{
// Call
var properties = new GrassCoverErosionOutwardsFailureMechanismProperties
{
Data = new GrassCoverErosionOutwardsFailureMechanism()
};
// Assert
var dynamicPropertyBag = new DynamicPropertyBag(properties);
PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[]
{
BrowsableAttribute.Yes
});
Assert.AreEqual(3, dynamicProperties.Count);
PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex];
Assert.IsNotNull(nameProperty);
Assert.IsTrue(nameProperty.IsReadOnly);
Assert.AreEqual("Algemeen", nameProperty.Category);
Assert.AreEqual("Naam", nameProperty.DisplayName);
Assert.AreEqual("De naam van het toetsspoor.", nameProperty.Description);
PropertyDescriptor codeProperty = dynamicProperties[codePropertyIndex];
Assert.IsNotNull(codeProperty);
Assert.IsTrue(codeProperty.IsReadOnly);
Assert.AreEqual("Algemeen", codeProperty.Category);
Assert.AreEqual("Label", codeProperty.DisplayName);
Assert.AreEqual("Het label van het toetsspoor.", codeProperty.Description);
PropertyDescriptor lengthEffectProperty = dynamicProperties[lengthEffectPropertyIndex];
Assert.IsNotNull(lengthEffectProperty);
Assert.IsFalse(lengthEffectProperty.IsReadOnly);
Assert.AreEqual("Lengte-effect parameters", lengthEffectProperty.Category);
Assert.AreEqual("N [-]", lengthEffectProperty.DisplayName);
Assert.AreEqual("De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in een semi-probabilistische beoordeling.", lengthEffectProperty.Description);
}
[Test]
[TestCase(1)]
[TestCase(10)]
[TestCase(20)]
public void LengthEffect_NewValueSet_HydraulicBoundaryLocationsClearedNotifyObserversAndLogged(int value)
{
// Setup
var mockRepository = new MockRepository();
var observerMock = mockRepository.StrictMock();
observerMock.Expect(o => o.UpdateObserver());
mockRepository.ReplayAll();
var hydraulicLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0);
var grassCoverErosionOutwardsHydraulicBoundaryLocation = new GrassCoverErosionOutwardsHydraulicBoundaryLocation(hydraulicLocation)
{
DesignWaterLevel = (RoundedDouble)3.8,
WaveHeight = (RoundedDouble)5.2
};
var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism
{
GrassCoverErosionOutwardsHydraulicBoundaryLocations =
{
grassCoverErosionOutwardsHydraulicBoundaryLocation
}
};
failureMechanism.GrassCoverErosionOutwardsHydraulicBoundaryLocations.Attach(observerMock);
var properties = new GrassCoverErosionOutwardsFailureMechanismProperties
{
Data = failureMechanism
};
// Call
Action action = () => properties.LengthEffect = value;
// Assert
const string expectedMessage = "De berekende waterstanden en golfhoogtes bij doorsnede-eis voor alle hydraulische randvoorwaarden locaties zijn verwijderd.";
TestHelper.AssertLogMessageIsGenerated(action, expectedMessage);
Assert.AreEqual(value, properties.LengthEffect);
Assert.AreEqual(value, failureMechanism.GeneralInput.N);
Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel);
Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight);
Assert.AreEqual(CalculationConvergence.NotCalculated, grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence);
Assert.AreEqual(CalculationConvergence.NotCalculated, grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeightCalculationConvergence);
mockRepository.VerifyAll();
}
private const int namePropertyIndex = 0;
private const int codePropertyIndex = 1;
private const int lengthEffectPropertyIndex = 2;
}
}