// Copyright (C) Stichting Deltares 2023. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI 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 System.Globalization;
using Deltares.Dam.Data;
using Deltares.Standard;
using Deltares.Standard.Validation;
using NUnit.Framework;
namespace Deltares.Dam.Tests
{
[TestFixture]
public class ScenarioTest
{
[Test]
public void Constructor_ExpectedValues()
{
// Call
var scenario = new Scenario();
// Assert
Assert.IsInstanceOf(scenario);
Assert.IsInstanceOf(scenario);
Assert.AreEqual(0, scenario.PolderLevel);
Assert.IsNull(scenario.HeadPl2);
}
[Test]
public void GivenScenarioWithPolderLevelNotNull_WhenGetParametersAsNameValuePairs_ThenDictionaryContainsPolderLevel()
{
// Given
var random = new Random(21);
var scenario = new Scenario
{
PolderLevel = random.NextDouble()
};
// When
Dictionary pairs = scenario.GetParametersAsNameValuePairs();
// Then
const string variableName = "PolderLevel";
Assert.IsTrue(pairs.ContainsKey(variableName));
string pairValue = pairs[variableName];
var expectedValue = scenario.PolderLevel.ToString(new NumberFormatInfo
{
NumberDecimalSeparator = "."
});
Assert.AreEqual(expectedValue, pairValue);
}
[Test]
public void SetParameterFromNameValuePair_WithValuesForPolderLevel_SetsValues()
{
// Setup
var random = new Random(21);
double numericValue = random.NextDouble();
var stringValue = numericValue.ToString(new NumberFormatInfo
{
NumberDecimalSeparator = "."
});
const string polderLevelName = "PolderLevel";
var scenario = new Scenario();
// Call
scenario.SetParameterFromNameValuePair(polderLevelName, stringValue);
// Assert
Assert.AreEqual(numericValue, scenario.PolderLevel);
}
[Test]
public void GivenScenarioWithHeadPl2NotNull_WhenGetParametersAsNameValuePairs_ThenDictionaryContainsPolderLevel()
{
// Given
var random = new Random(21);
var scenario = new Scenario
{
HeadPl2 = random.NextDouble()
};
// Precondition
Assert.IsNotNull(scenario.HeadPl2);
// When
Dictionary pairs = scenario.GetParametersAsNameValuePairs();
// Then
const string variableName = "HeadPL2";
Assert.IsTrue(pairs.ContainsKey(variableName));
string pairValue = pairs[variableName];
var expectedValue = scenario.HeadPl2.Value.ToString(new NumberFormatInfo
{
NumberDecimalSeparator = "."
});
Assert.AreEqual(expectedValue, pairValue);
}
[Test]
public void GivenScenarioWithHeadPl2Null_WhenGetParametersAsNameValuePairs_ThenDictionaryDoesNotContainPolderLevel()
{
// Given
var scenario = new Scenario();
// Precondition
Assert.IsNull(scenario.HeadPl2);
// When
Dictionary pairs = scenario.GetParametersAsNameValuePairs();
// Then
Assert.IsFalse(pairs.ContainsKey("HeadPl2"));
}
[Test]
public void SetParameterFromNameValuePair_WithValuesForheadPl2_SetsValues()
{
// Setup
var random = new Random(21);
double numericValue = random.NextDouble();
var stringValue = numericValue.ToString(new NumberFormatInfo
{
NumberDecimalSeparator = "."
});
const string headPL2Name = "HeadPL2";
var scenario = new Scenario();
// Precondition
Assert.IsNull(scenario.HeadPl2);
// Call
scenario.SetParameterFromNameValuePair(headPL2Name, stringValue);
// Assert
Assert.AreEqual(numericValue, scenario.HeadPl2);
}
}
}