Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionAssemblyGroupConverter.cs =================================================================== diff -u --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionAssemblyGroupConverter.cs (revision 0) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionAssemblyGroupConverter.cs (revision 418979f806ef850adff202050d671426da79369c) @@ -0,0 +1,83 @@ +// Copyright (C) Stichting Deltares 2022. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.ComponentModel; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.IO.Model.Enums; + +namespace Riskeer.Integration.IO.Factories +{ + /// + /// Converter for converting into . + /// + public static class ExportableFailureMechanismSectionAssemblyGroupConverter + { + /// + /// Converts an into an . + /// + /// The + /// to convert into an . + /// An . + /// Thrown when + /// is an invalid value. + /// Thrown when + /// is a valid value, but unsupported. + public static ExportableFailureMechanismSectionAssemblyGroup ConvertTo( + FailureMechanismSectionAssemblyGroup failureMechanismSectionAssemblyGroup) + { + if (!Enum.IsDefined(typeof(FailureMechanismSectionAssemblyGroup), failureMechanismSectionAssemblyGroup)) + { + throw new InvalidEnumArgumentException(nameof(failureMechanismSectionAssemblyGroup), + (int) failureMechanismSectionAssemblyGroup, + typeof(FailureMechanismSectionAssemblyGroup)); + } + + switch (failureMechanismSectionAssemblyGroup) + { + case FailureMechanismSectionAssemblyGroup.NotDominant: + return ExportableFailureMechanismSectionAssemblyGroup.NotDominant; + case FailureMechanismSectionAssemblyGroup.III: + return ExportableFailureMechanismSectionAssemblyGroup.III; + case FailureMechanismSectionAssemblyGroup.II: + return ExportableFailureMechanismSectionAssemblyGroup.II; + case FailureMechanismSectionAssemblyGroup.I: + return ExportableFailureMechanismSectionAssemblyGroup.I; + case FailureMechanismSectionAssemblyGroup.Zero: + return ExportableFailureMechanismSectionAssemblyGroup.Zero; + case FailureMechanismSectionAssemblyGroup.IMin: + return ExportableFailureMechanismSectionAssemblyGroup.IMin; + case FailureMechanismSectionAssemblyGroup.IIMin: + return ExportableFailureMechanismSectionAssemblyGroup.IIMin; + case FailureMechanismSectionAssemblyGroup.IIIMin: + return ExportableFailureMechanismSectionAssemblyGroup.IIIMin; + case FailureMechanismSectionAssemblyGroup.Dominant: + return ExportableFailureMechanismSectionAssemblyGroup.Dominant; + case FailureMechanismSectionAssemblyGroup.NoResult: + return ExportableFailureMechanismSectionAssemblyGroup.NoResult; + case FailureMechanismSectionAssemblyGroup.NotRelevant: + return ExportableFailureMechanismSectionAssemblyGroup.NotRelevant; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionAssemblyGroupConverterTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionAssemblyGroupConverterTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionAssemblyGroupConverterTest.cs (revision 418979f806ef850adff202050d671426da79369c) @@ -0,0 +1,71 @@ +// Copyright (C) Stichting Deltares 2022. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.ComponentModel; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.IO.Model.Enums; +using Riskeer.Integration.IO.Factories; + +namespace Riskeer.Integration.IO.Test.Factories +{ + [TestFixture] + public class ExportableFailureMechanismSectionAssemblyGroupConverterTest + { + [Test] + public void ConvertTo_InvalidAssemblyGroup_ThrowInvalidEnumArgumentException() + { + // Setup + const FailureMechanismSectionAssemblyGroup failureMechanismSectionAssemblyGroup = (FailureMechanismSectionAssemblyGroup) 999; + + // ExportableAssemblyMethodFactory + void Call() => ExportableFailureMechanismSectionAssemblyGroupConverter.ConvertTo(failureMechanismSectionAssemblyGroup); + + // Assert + var message = $"The value of argument 'failureMechanismSectionAssemblyGroup' ({failureMechanismSectionAssemblyGroup}) is invalid for Enum type '{nameof(FailureMechanismSectionAssemblyGroup)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, message); + } + + [Test] + [TestCase(FailureMechanismSectionAssemblyGroup.NotDominant, ExportableFailureMechanismSectionAssemblyGroup.NotDominant)] + [TestCase(FailureMechanismSectionAssemblyGroup.III, ExportableFailureMechanismSectionAssemblyGroup.III)] + [TestCase(FailureMechanismSectionAssemblyGroup.II, ExportableFailureMechanismSectionAssemblyGroup.II)] + [TestCase(FailureMechanismSectionAssemblyGroup.I, ExportableFailureMechanismSectionAssemblyGroup.I)] + [TestCase(FailureMechanismSectionAssemblyGroup.Zero, ExportableFailureMechanismSectionAssemblyGroup.Zero)] + [TestCase(FailureMechanismSectionAssemblyGroup.IMin, ExportableFailureMechanismSectionAssemblyGroup.IMin)] + [TestCase(FailureMechanismSectionAssemblyGroup.IIMin, ExportableFailureMechanismSectionAssemblyGroup.IIMin)] + [TestCase(FailureMechanismSectionAssemblyGroup.IIIMin, ExportableFailureMechanismSectionAssemblyGroup.IIIMin)] + [TestCase(FailureMechanismSectionAssemblyGroup.Dominant, ExportableFailureMechanismSectionAssemblyGroup.Dominant)] + [TestCase(FailureMechanismSectionAssemblyGroup.NoResult, ExportableFailureMechanismSectionAssemblyGroup.NoResult)] + [TestCase(FailureMechanismSectionAssemblyGroup.NotRelevant, ExportableFailureMechanismSectionAssemblyGroup.NotRelevant)] + public void ConvertTo_WithAssemblyGroup_ReturnsExpectedValue(FailureMechanismSectionAssemblyGroup failureMechanismSectionAssemblyGroup, + ExportableFailureMechanismSectionAssemblyGroup expectedExportableSectionAssemblyGroup) + { + // Call + ExportableFailureMechanismSectionAssemblyGroup convertedAssemblyGroup = + ExportableFailureMechanismSectionAssemblyGroupConverter.ConvertTo(failureMechanismSectionAssemblyGroup); + + // Assert + Assert.AreEqual(expectedExportableSectionAssemblyGroup, convertedAssemblyGroup); + } + } +} \ No newline at end of file