// Copyright (C) Stichting Deltares 2019. 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.IO; using System.Xml.Linq; using Deltares.Dam.Data; using Deltares.Dam.Data.Assemblers; using Deltares.Dam.TestHelper; using Deltares.Standard; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class CalculationParametersAssemblerTest { private const string testFileName = @"TestData\SampleCalculationParameters.xml"; private const double Precision = 1e-8; private XDocument testDoc; private CalculationParametersAssembler assembler; #region Setup/Teardown [SetUp] public void TestSetup() { this.assembler = new CalculationParametersAssembler(); } #endregion [TestFixtureSetUp] public void TestFixtureSetup() { this.testDoc = XDocument.Load(testFileName); } [Test] [TestCase("Stability")] [TestCase("PipingSellmeijerProbabilistic")] [TestCase("PipingIJkdijk")] [TestCase("Overtopping")] public void GivenParameterFileWithObsoleteCalculationModuleWhenParsingThenExceptionIsThrown(string obsoleteElement) { // Given ParameterFile with obsolete Calculation Module string inputString = File.ReadAllText(testFileName); inputString = XmlAdapter.ChangeKeyName(inputString, "StabilityOutside", obsoleteElement); XDocument inputDocument = XDocument.Parse(inputString); // When parsing, then exception is thrown Assert.That(() => this.assembler.CreateDomainObject(inputDocument), Throws.TypeOf(typeof(DtoAssemblerException)).With.Message.EqualTo(String.Format("The specified parameter '{0}' is obsolete", obsoleteElement))); } [Test] [TestCase("ShearStrength")] [TestCase("Probabilistic")] [TestCase("IsOverrulePLLineCreationMethod")] [TestCase("PLLineCreationMethod")] public void GivenParameterFileWithObsoleteMStabParametersWhenParsingThenExceptionIsThrown(string obsoleteElement) { // Given ParameterFile with obsolete MStab parameters string inputString = File.ReadAllText(testFileName); inputString = XmlAdapter.ChangeKeyName(inputString, "CalculationModel", obsoleteElement); XDocument inputDocument = XDocument.Parse(inputString); // When parsing, then exception is thrown Assert.That(() => this.assembler.CreateDomainObject(inputDocument), Throws.TypeOf(typeof(DtoAssemblerException)).With.Message.EqualTo(String.Format("The specified parameter '{0}' is obsolete", obsoleteElement))); } [Test] public void CreateEntityFromDto() { // First validate test XML against schema string message; if (!this.assembler.ValidateSchema(this.testDoc, out message)) { Assert.Fail("SCHEMA VALIDATION: " + message); } // Do the thing: create MStabParameters from XML element CalculationParameters calculationParameters = this.assembler.CreateDomainObject(this.testDoc); Assert.IsNotNull(calculationParameters); // Calculation modules Assert.IsNotNull(calculationParameters.CalculationModules); Assert.IsTrue(calculationParameters.CalculationModules.StabilityOutside, "CalculationModules.StabilityOutside"); Assert.IsTrue(calculationParameters.CalculationModules.StabilityInside, "CalculationModules.Stability"); Assert.IsTrue(calculationParameters.CalculationModules.PipingWti, "CalculationModules.PipingWti"); Assert.IsTrue(calculationParameters.CalculationModules.PipingBligh, "CalculationModules.PipingBligh"); Assert.IsTrue(calculationParameters.CalculationModules.PipingSellmeijer, "CalculationModules.PipingSellmeijer"); // MStab parameters Assert.IsNotNull(calculationParameters.MStabParameters); Assert.AreEqual(false, calculationParameters.MStabParameters.IsCalculateAllStabilityProjectsAtOnce, "MStabParameters.IsCalculateAllStabilityProjectsAtOnce"); Assert.AreEqual(MStabModelType.UpliftVan, calculationParameters.MStabParameters.Model, "MStabParameters.Model"); Assert.AreEqual(MStabSearchMethod.Grid, calculationParameters.MStabParameters.SearchMethod, "MStabParameters.SearchMethod"); Assert.IsTrue(calculationParameters.MStabParameters.CalculationOptions.ZonesType.Equals(MStabZonesType.ForbiddenZone), "MStabParameters.CalculationOptions.ZonesType"); } } }