// 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.Gui.PropertyBag;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Data.Properties;
using Ringtoets.GrassCoverErosionOutwards.Forms.PropertyClasses;
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 te bepalen in een semi-probabilistische beoordeling.", lengthEffectProperty.Description);
}
private const int namePropertyIndex = 0;
private const int codePropertyIndex = 1;
private const int lengthEffectPropertyIndex = 2;
}
}