// Copyright (C) Stichting Deltares 2017. 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.Linq; using Deltares.Dam.Data; using Deltares.Geotechnics; using Deltares.Geotechnics.Soils; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class DamProjectCalculatorCsvExportDataBuilderTest { private readonly Dike dike = new Dike(); private readonly Scenario scenario = new Scenario(); private readonly DamFailureMechanismeCalculationSpecification failureMechanismSystemType = new DamFailureMechanismeCalculationSpecification(); private const AnalysisType analysisType = AnalysisType.AdaptGeometry; private const ProbabilisticType probabilisticType = ProbabilisticType.Deterministic; private DamProjectCalculatorCsvExportDataBuilder builder; [SetUp] public void SetUp() { builder = new DamProjectCalculatorCsvExportDataBuilder(dike, scenario, failureMechanismSystemType, analysisType, probabilisticType); } [Test] public void Build_DefaultConstructor_ReturnsWithDefaultsForIdIndexAndKernelType() { // setup var testDikeName = "testDike"; dike.Name = testDikeName; // call var result = builder.Build(new SoilGeometryProbability()); // assert Assert.IsEmpty(result.ID); Assert.AreEqual(0, result.NwoResultIndex); Assert.AreEqual((StabilityKernelType)0, result.SelectedStabilityKernelType); Assert.AreEqual(testDikeName, result.DikeName); Assert.AreEqual(scenario, result.Scenario); Assert.AreEqual(failureMechanismSystemType, result.DamFailureMechanismeCalculation); Assert.AreEqual(analysisType, result.AnalysisType); Assert.AreEqual(probabilisticType, result.ProbabilisticType); } [Test] public void Build_UseCustomIndex_ReturnsWitSetIndexAndSoilGeometryProperties() { // setup const int testIndex = 3; const string testSoilGeometryName = "soilName"; var testSoilGeometry = new SoilGeometryProbability(); var testSoilProfile = new SoilProfile1D(); testSoilGeometry.SoilGeometry2DName = testSoilGeometryName; testSoilGeometry.SoilProfile = testSoilProfile; // call var result = builder.Build(testSoilGeometry, testIndex); // assert Assert.AreEqual(testIndex, result.NwoResultIndex); Assert.AreEqual(testSoilGeometryName, result.SoilGeometry2DName); Assert.AreEqual(testSoilProfile, result.SoilProfile); } [Test] public void Build_UseCustomStabilityKernel_ReturnsWitSetKernelType() { // setup const int typeIndex = 1; Assert.LessOrEqual(typeIndex, Enum.GetValues(typeof(StabilityKernelType)).Length); var testType = (StabilityKernelType)typeIndex; // call var result = builder.Build(new SoilGeometryProbability(), testType); // assert Assert.AreEqual(testType, result.SelectedStabilityKernelType); } [Test] public void Build_SetMessage_ReturnsWithSetId() { // setup const string testText = "text"; builder.Append(testText); // call var result = builder.Build(new SoilGeometryProbability()); // assert Assert.AreEqual(testText, result.ID); } [Test] public void Build_SetMessageBuildTwice_ReturnsWithEmptyId() { // setup builder.Append("text"); builder.Build(new SoilGeometryProbability()); // call var result = builder.Build(new SoilGeometryProbability()); // assert Assert.IsEmpty(result.ID); } [TestCase(3)] [TestCase(5)] public void Build_SetMessageMultipleTimes_ReturnsWithSetId(int count) { // setup const string testText = "text"; for (var i = 0; i < count; i++) { builder.Append(testText); } // call var result = builder.Build(new SoilGeometryProbability()); // assert Assert.AreEqual(String.Join("", Enumerable.Repeat(testText,count)), result.ID); } [TestCase(3)] [TestCase(5)] public void Build_SetMultipleMessageInOneTime_ReturnsWithSetId(int count) { // setup const string testText = "text"; var texts = new string[count]; for (var i = 0; i < count; i++) { texts[i] = testText; } builder.Append(texts); // call var result = builder.Build(new SoilGeometryProbability()); // assert Assert.AreEqual(String.Join("", texts), result.ID); } } }