// Copyright (C) Stichting Deltares 2024. 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.That(scenario, Is.InstanceOf()); Assert.That(scenario, Is.InstanceOf()); Assert.That(scenario.PolderLevel, Is.EqualTo(0)); Assert.That(scenario.HeadPl2, Is.Null); } [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.That(pairs.ContainsKey(variableName), Is.True); string pairValue = pairs[variableName]; var expectedValue = scenario.PolderLevel.ToString(new NumberFormatInfo { NumberDecimalSeparator = "." }); Assert.That(pairValue, Is.EqualTo(expectedValue)); } [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.That(scenario.PolderLevel, Is.EqualTo(numericValue)); } [Test] public void GivenScenarioWithHeadPl2NotNull_WhenGetParametersAsNameValuePairs_ThenDictionaryContainsPolderLevel() { // Given var random = new Random(21); var scenario = new Scenario { HeadPl2 = random.NextDouble() }; // Precondition Assert.That(scenario.HeadPl2, Is.Not.Null); // When Dictionary pairs = scenario.GetParametersAsNameValuePairs(); // Then const string variableName = "HeadPL2"; Assert.That(pairs.ContainsKey(variableName), Is.True); string pairValue = pairs[variableName]; var expectedValue = scenario.HeadPl2.Value.ToString(new NumberFormatInfo { NumberDecimalSeparator = "." }); Assert.That(pairValue, Is.EqualTo(expectedValue)); } [Test] public void GivenScenarioWithHeadPl2Null_WhenGetParametersAsNameValuePairs_ThenDictionaryDoesNotContainPolderLevel() { // Given var scenario = new Scenario(); // Precondition Assert.That(scenario.HeadPl2, Is.Null); // When Dictionary pairs = scenario.GetParametersAsNameValuePairs(); // Then Assert.That(pairs.ContainsKey("HeadPl2"), Is.False); } [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.That(scenario.HeadPl2, Is.Null); // Call scenario.SetParameterFromNameValuePair(headPL2Name, stringValue); // Assert Assert.That(scenario.HeadPl2, Is.EqualTo(numericValue)); } } }