// Copyright (C) Stichting Deltares 2017. 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 Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.AssemblyTool.IO.Model; using Ringtoets.AssemblyTool.IO.Model.DataTypes; using Ringtoets.AssemblyTool.IO.TestUtil; namespace Ringtoets.AssemblyTool.IO.Test.Model { [TestFixture] public class SerializableCombinedFailureMechanismSectionAssemblyTest { [Test] public void DefaultConstructor_ReturnsDefaultValues() { // Call var combinedSectionAssembly = new SerializableCombinedFailureMechanismSectionAssembly(); // Assert Assert.IsInstanceOf(combinedSectionAssembly); Assert.IsNull(combinedSectionAssembly.Id); Assert.IsNull(combinedSectionAssembly.TotalAssemblyResultId); Assert.IsNull(combinedSectionAssembly.FailureMechanismSectionId); Assert.IsNull(combinedSectionAssembly.CombinedSectionResult); Assert.IsNull(combinedSectionAssembly.FailureMechanismResults); SerializableAttributeTestHelper.AssertXmlAttributeAttribute( nameof(SerializableCombinedFailureMechanismSectionAssembly.Id), "GecombineerdToetsoordeelID"); SerializableAttributeTestHelper.AssertXmlAttributeAttribute( nameof(SerializableCombinedFailureMechanismSectionAssembly.TotalAssemblyResultId), "VeiligheidsoordeelIDRef"); SerializableAttributeTestHelper.AssertXmlAttributeAttribute( nameof(SerializableCombinedFailureMechanismSectionAssembly.FailureMechanismSectionId), "WaterkeringsectieIDRef"); SerializableAttributeTestHelper.AssertXmlElementAttribute( nameof(SerializableCombinedFailureMechanismSectionAssembly.CombinedSectionResult), "toetsoordeelGecombineerd"); SerializableAttributeTestHelper.AssertXmlElementAttribute( nameof(SerializableCombinedFailureMechanismSectionAssembly.FailureMechanismResults), "eindtoetsoordeelToetsspoor"); } [Test] public void Constructor_IdNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => new SerializableCombinedFailureMechanismSectionAssembly(null, new SerializableTotalAssemblyResult(), new SerializableFailureMechanismSection(), new SerializableCombinedFailureMechanismSectionAssemblyResult[0], new SerializableFailureMechanismSectionAssemblyResult()); // Assert var exception = Assert.Throws(call); Assert.AreEqual("id", exception.ParamName); } [Test] public void Constructor_TotalAssemblyResultNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => new SerializableCombinedFailureMechanismSectionAssembly("id", null, new SerializableFailureMechanismSection(), new SerializableCombinedFailureMechanismSectionAssemblyResult[0], new SerializableFailureMechanismSectionAssemblyResult()); // Assert var exception = Assert.Throws(call); Assert.AreEqual("totalAssemblyResult", exception.ParamName); } [Test] public void Constructor_SectionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => new SerializableCombinedFailureMechanismSectionAssembly("id", new SerializableTotalAssemblyResult(), null, new SerializableCombinedFailureMechanismSectionAssemblyResult[0], new SerializableFailureMechanismSectionAssemblyResult()); // Assert var exception = Assert.Throws(call); Assert.AreEqual("section", exception.ParamName); } [Test] public void Constructor_FailureMechanismResultsNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => new SerializableCombinedFailureMechanismSectionAssembly("id", new SerializableTotalAssemblyResult(), new SerializableFailureMechanismSection(), null, new SerializableFailureMechanismSectionAssemblyResult()); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanismResults", exception.ParamName); } [Test] public void Constructor_CombinedSectionResultNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => new SerializableCombinedFailureMechanismSectionAssembly("id", new SerializableTotalAssemblyResult(), new SerializableFailureMechanismSection(), new SerializableCombinedFailureMechanismSectionAssemblyResult[0], null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("combinedSectionResult", exception.ParamName); } [Test] public void Constructor_WithValidData_ReturnsExpectedValues() { // Setup const string id = "id"; var random = new Random(39); var totalAssembly = new SerializableTotalAssemblyResult("total assembly ID", new SerializableAssessmentProcess(), new SerializableFailureMechanismAssemblyResult(), new SerializableFailureMechanismAssemblyResult(), new SerializableAssessmentSectionAssemblyResult()); var section = new SerializableFailureMechanismSection("section ID", new SerializableFailureMechanismSectionCollection(), random.NextDouble(), random.NextDouble(), new[] { new Point2D(random.NextDouble(), random.NextDouble()) }); var sectionResults = new SerializableCombinedFailureMechanismSectionAssemblyResult[0]; var combinedSectionResult = new SerializableFailureMechanismSectionAssemblyResult(); // Call var combinedSectionAssembly = new SerializableCombinedFailureMechanismSectionAssembly(id, totalAssembly, section, sectionResults, combinedSectionResult); // Assert Assert.AreEqual(id, combinedSectionAssembly.Id); Assert.AreEqual(totalAssembly.Id, combinedSectionAssembly.TotalAssemblyResultId); Assert.AreEqual(section.Id, combinedSectionAssembly.FailureMechanismSectionId); Assert.AreSame(sectionResults, combinedSectionAssembly.FailureMechanismResults); Assert.AreSame(combinedSectionResult, combinedSectionAssembly.CombinedSectionResult); } } }