Index: Riskeer/Common/src/Riskeer.Common.Forms/Helpers/AssemblyGroupColorHelper.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Forms/Helpers/AssemblyGroupColorHelper.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Forms/Helpers/AssemblyGroupColorHelper.cs (revision 1228f310314708afee087d4e83260e80d83f18e5) @@ -0,0 +1,81 @@ +// Copyright (C) Stichting Deltares 2021. 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 System.Drawing; +using Riskeer.AssemblyTool.Data; + +namespace Riskeer.Common.Forms.Helpers +{ + /// + /// Helper class for determining the colors belonging to various assembly groups. + /// + public class AssemblyGroupColorHelper + { + /// + /// Gets the color for a failure mechanism section assembly group. + /// + /// The assembly group to get the color for. + /// The corresponding to the given assembly group. + /// Thrown when + /// has an invalid value for . + /// Thrown when + /// is not supported. + public static Color GetFailureMechanismSectionAssemblyCategoryGroupColor(FailureMechanismSectionAssemblyGroup assemblyGroup) + { + if (!Enum.IsDefined(typeof(FailureMechanismSectionAssemblyGroup), assemblyGroup)) + { + throw new InvalidEnumArgumentException(nameof(assemblyGroup), + (int) assemblyGroup, + typeof(FailureMechanismSectionAssemblyGroup)); + } + + switch (assemblyGroup) + { + case FailureMechanismSectionAssemblyGroup.ND: + return Color.FromArgb(192, 192, 192); + case FailureMechanismSectionAssemblyGroup.III: + return Color.FromArgb(34, 139, 34); + case FailureMechanismSectionAssemblyGroup.II: + return Color.FromArgb(146, 208, 80); + case FailureMechanismSectionAssemblyGroup.I: + return Color.FromArgb(198, 224, 180); + case FailureMechanismSectionAssemblyGroup.ZeroPlus: + return Color.FromArgb(255, 255, 0); + case FailureMechanismSectionAssemblyGroup.Zero: + return Color.FromArgb(255, 165, 0); + case FailureMechanismSectionAssemblyGroup.IMin: + return Color.FromArgb(255, 0, 0); + case FailureMechanismSectionAssemblyGroup.IIMin: + return Color.FromArgb(178, 34, 34); + case FailureMechanismSectionAssemblyGroup.IIIMin: + return Color.FromArgb(128, 0, 0); + case FailureMechanismSectionAssemblyGroup.D: + return Color.FromArgb(255, 90, 172); + case FailureMechanismSectionAssemblyGroup.Gr: + return Color.FromArgb(255, 255, 255); + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/AssemblyGroupColorHelperTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/AssemblyGroupColorHelperTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/AssemblyGroupColorHelperTest.cs (revision 1228f310314708afee087d4e83260e80d83f18e5) @@ -0,0 +1,61 @@ +// Copyright (C) Stichting Deltares 2021. 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 System.Drawing; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.Common.Forms.Helpers; +using Riskeer.Common.Forms.TestUtil; + +namespace Riskeer.Common.Forms.Test.Helpers +{ + [TestFixture] + public class AssemblyGroupColorHelperTest + { + [Test] + public void GetFailureMechanismSectionAssemblyCategoryGroupColor_InvalidFailureMechanismSectionAssemblyGroup_ThrowsInvalidEnumArgumentException() + { + // Setup + const FailureMechanismSectionAssemblyGroup assemblyGroup = (FailureMechanismSectionAssemblyGroup) 99; + + // Call + void Call() => AssemblyGroupColorHelper.GetFailureMechanismSectionAssemblyCategoryGroupColor(assemblyGroup); + + // Assert + var expectedMessage = $"The value of argument 'assemblyGroup' ({assemblyGroup}) is invalid for Enum type '{nameof(FailureMechanismSectionAssemblyGroup)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + } + + [Test] + [TestCaseSource(typeof(AssemblyGroupColorTestHelper), nameof(AssemblyGroupColorTestHelper.FailureMechanismSectionAssemblyGroupColorCases))] + public void GetFailureMechanismSectionAssemblyCategoryGroupColor_ValidFailureMechanismSectionAssemblyGroup_ReturnsExpectedColor( + FailureMechanismSectionAssemblyGroup assemblyGroup, Color expectedColor) + { + // Call + Color color = AssemblyGroupColorHelper.GetFailureMechanismSectionAssemblyCategoryGroupColor(assemblyGroup); + + // Assert + Assert.AreEqual(expectedColor, color); + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/AssemblyGroupColorTestHelper.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/AssemblyGroupColorTestHelper.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/AssemblyGroupColorTestHelper.cs (revision 1228f310314708afee087d4e83260e80d83f18e5) @@ -0,0 +1,56 @@ +// Copyright (C) Stichting Deltares 2021. 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.Collections.Generic; +using System.Drawing; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; + +namespace Riskeer.Common.Forms.TestUtil +{ + /// + /// Class that can be used to assert the color corresponding to assembly groups. + /// + public static class AssemblyGroupColorTestHelper + { + /// + /// Gets a collection of test cases to test the colors belonging to various + /// values. + /// + public static IEnumerable FailureMechanismSectionAssemblyGroupColorCases + { + get + { + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.ND, Color.FromArgb(192, 192, 192)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.III, Color.FromArgb(34, 139, 34)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.II, Color.FromArgb(146, 208, 80)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.I, Color.FromArgb(198, 224, 180)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.ZeroPlus, Color.FromArgb(255, 255, 0)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.Zero, Color.FromArgb(255, 165, 0)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.IMin, Color.FromArgb(255, 0, 0)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.IIMin, Color.FromArgb(178, 34, 34)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.IIIMin, Color.FromArgb(128, 0, 0)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.D, Color.FromArgb(255, 90, 172)); + yield return new TestCaseData(FailureMechanismSectionAssemblyGroup.Gr, Color.FromArgb(255, 255, 255)); + } + } + } +} \ No newline at end of file