Index: Riskeer/Common/src/Riskeer.Common.Forms/Helpers/CalculationTypeHelper.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Forms/Helpers/CalculationTypeHelper.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Forms/Helpers/CalculationTypeHelper.cs (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -0,0 +1,66 @@ +// Copyright (C) Stichting Deltares 2019. 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.Common.Forms.Properties; +using Riskeer.Common.Forms.TreeNodeInfos; + +namespace Riskeer.Common.Forms.Helpers +{ + /// + /// Helper class to help when dealing with . + /// + public static class CalculationTypeHelper + { + /// + /// Gets an image based on the given . + /// + /// The to get the image for. + /// An image. + /// Thrown when + /// has an invalid value. + /// Thrown when + /// has a valid but not supported value. + public static Bitmap GetCalculationTypeImage(CalculationType calculationType) + { + if (!Enum.IsDefined(typeof(CalculationType), calculationType)) + { + throw new InvalidEnumArgumentException(nameof(calculationType), + (int) calculationType, + typeof(CalculationType)); + } + + switch (calculationType) + { + case CalculationType.SemiProbabilistic: + return Resources.SemiProbabilisticCalculationIcon; + case CalculationType.Probabilistic: + return Resources.ProbabilisticCalculationIcon; + case CalculationType.Hydraulic: + return Resources.HydraulicCalculationIcon; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Index: Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerTreeNodeInfoFactory.cs =================================================================== diff -u -rf4359dde195c85255ac1aa2373710dc709f65a56 -r87452d01a3f950c5ac75374dd3e75aa72b4a4844 --- Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerTreeNodeInfoFactory.cs (.../RiskeerTreeNodeInfoFactory.cs) (revision f4359dde195c85255ac1aa2373710dc709f65a56) +++ Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerTreeNodeInfoFactory.cs (.../RiskeerTreeNodeInfoFactory.cs) (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -27,6 +27,7 @@ using Core.Common.Controls.TreeView; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Forms.Helpers; using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.Properties; @@ -82,23 +83,17 @@ /// The action to perform on removing a node. /// The type of the calculation. /// A object. - /// Thrown when - /// has an invalid value. - /// Thrown when - /// has a valid but not supported value. public static TreeNodeInfo CreateCalculationContextTreeNodeInfo( Func childNodeObjects, Func contextMenuStrip, Action onNodeRemoved, CalculationType calculationType) where TCalculationContext : ICalculationContext { - Bitmap image = GetCalculationContextTreeNodeImage(calculationType); - return new TreeNodeInfo { Text = context => context.WrappedData.Name, - Image = context => image, + Image = context => CalculationTypeHelper.GetCalculationTypeImage(calculationType), EnsureVisibleOnCreate = (context, parent) => true, ChildNodeObjects = childNodeObjects, ContextMenuStrip = contextMenuStrip, @@ -148,37 +143,6 @@ #region Helper methods for CreateCalculationContextTreeNodeInfo - /// - /// Gets the calculation context tree node image based on the given . - /// - /// The to get the image for. - /// A calculation context tree node image. - /// Thrown when - /// has an invalid value. - /// Thrown when - /// has a valid but not supported value. - private static Bitmap GetCalculationContextTreeNodeImage(CalculationType calculationType) - { - if (!Enum.IsDefined(typeof(CalculationType), calculationType)) - { - throw new InvalidEnumArgumentException(nameof(calculationType), - (int) calculationType, - typeof(CalculationType)); - } - - switch (calculationType) - { - case CalculationType.SemiProbabilistic: - return Resources.SemiProbabilisticCalculationIcon; - case CalculationType.Probabilistic: - return Resources.ProbabilisticCalculationIcon; - case CalculationType.Hydraulic: - return Resources.HydraulicCalculationIcon; - default: - throw new NotSupportedException(); - } - } - private static bool CalculationContextCanRemove(ICalculationContext calculationContext, object parentNodeData) { var calculationGroupContext = parentNodeData as ICalculationContext; Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/CalculationTypeHelperTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/CalculationTypeHelperTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/CalculationTypeHelperTest.cs (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -0,0 +1,60 @@ +// Copyright (C) Stichting Deltares 2019. 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.Common.Forms.Helpers; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.TreeNodeInfos; + +namespace Riskeer.Common.Forms.Test.Helpers +{ + [TestFixture] + public class CalculationTypeHelperTest + { + [Test] + public void GetCalculationTypeImage_InvalidCalculationType_ThrowsInvalidEnumArgumentException() + { + // Setup + const CalculationType calculationType = (CalculationType) 99; + + // Call + void Call() => CalculationTypeHelper.GetCalculationTypeImage(calculationType); + + // Assert + var expectedMessage = $"The value of argument 'calculationType' ({calculationType}) is invalid for Enum type '{nameof(CalculationType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + } + + [Test] + [TestCaseSource(typeof(CalculationTypeTestHelper), nameof(CalculationTypeTestHelper.CalculationTypeWithImageCases))] + public void GetCalculationTypeImage_ValidCalculationType_ReturnsImage(CalculationType calculationType, Bitmap expectedImage) + { + // Call + Bitmap image = CalculationTypeHelper.GetCalculationTypeImage(calculationType); + + // Assert + TestHelper.AssertImagesAreEqual(expectedImage, image); + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerTreeNodeInfoFactoryTest.cs =================================================================== diff -u -rf4359dde195c85255ac1aa2373710dc709f65a56 -r87452d01a3f950c5ac75374dd3e75aa72b4a4844 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerTreeNodeInfoFactoryTest.cs (.../RiskeerTreeNodeInfoFactoryTest.cs) (revision f4359dde195c85255ac1aa2373710dc709f65a56) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerTreeNodeInfoFactoryTest.cs (.../RiskeerTreeNodeInfoFactoryTest.cs) (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -35,6 +35,7 @@ using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.TestUtil; using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.Common.Forms.TestUtil; using Riskeer.Common.Forms.TreeNodeInfos; using RiskeerFormsResources = Riskeer.Common.Forms.Properties.Resources; @@ -604,32 +605,15 @@ #region CreateCalculationContextTreeNodeInfo [Test] - public void CreateCalculationContextTreeNodeInfo_InvalidCalculationType_ThrowsInvalidEnumArgumentException() + [TestCaseSource(typeof(CalculationTypeTestHelper), nameof(CalculationTypeTestHelper.CalculationTypeWithImageCases))] + public void CreateCalculationContextTreeNodeInfo_Always_ExpectedPropertiesSet(CalculationType calculationType, Bitmap expectedIcon) { // Setup Func childNodeObjects = context => new object[0]; Func contextMenuStrip = (context, parent, treeViewControl) => new ContextMenuStrip(); Action onNodeRemoved = (context, parent) => {}; - const CalculationType calculationType = (CalculationType) 99; // Call - void Call() => RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(childNodeObjects, contextMenuStrip, onNodeRemoved, calculationType); - - // Assert - var expectedMessage = $"The value of argument 'calculationType' ({calculationType}) is invalid for Enum type '{nameof(CalculationType)}'."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); - } - - [Test] - [TestCaseSource(nameof(GetCalculationTypes))] - public void CreateCalculationContextTreeNodeInfo_ValidData_ExpectedPropertiesSet(CalculationType calculationType, Bitmap expectedIcon) - { - // Setup - Func childNodeObjects = context => new object[0]; - Func contextMenuStrip = (context, parent, treeViewControl) => new ContextMenuStrip(); - Action onNodeRemoved = (context, parent) => {}; - - // Call TreeNodeInfo treeNodeInfo = RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(childNodeObjects, contextMenuStrip, onNodeRemoved, calculationType); // Assert @@ -645,7 +629,7 @@ } [Test] - public void TextOfCalculationContextTreeNodeInfo_ValidData_ReturnsWrappedDataName() + public void TextOfCalculationContextTreeNodeInfo_Always_ReturnsWrappedDataName() { // Setup var mocks = new MockRepository(); @@ -672,7 +656,7 @@ } [Test] - public void EnsureVisibleOnCreateOfCalculationContextTreeNodeInfo_ValidData_ReturnsTrue() + public void EnsureVisibleOnCreateOfCalculationContextTreeNodeInfo_Always_ReturnsTrue() { // Setup var calculationType = new Random(21).NextEnumValue(); @@ -686,7 +670,7 @@ } [Test] - public void CanRenameCalculationContextTreeNodeInfo_ValidData_ReturnTrue() + public void CanRenameCalculationContextTreeNodeInfo_Always_ReturnTrue() { // Setup var calculationType = new Random(21).NextEnumValue(); @@ -700,7 +684,7 @@ } [Test] - public void OnNodeRenamedOfCalculationContextTreeNodeInfo_ValidData_SetNewNameToCalculationItemAndNotifyObserver() + public void OnNodeRenamedOfCalculationContextTreeNodeInfo_Always_SetNewNameToCalculationItemAndNotifyObserver() { // Setup var mocks = new MockRepository(); @@ -819,16 +803,6 @@ Assert.IsTrue(canDrag); } - private static IEnumerable GetCalculationTypes() - { - return new[] - { - new TestCaseData(CalculationType.Hydraulic, RiskeerFormsResources.HydraulicCalculationIcon), - new TestCaseData(CalculationType.Probabilistic, RiskeerFormsResources.ProbabilisticCalculationIcon), - new TestCaseData(CalculationType.SemiProbabilistic, RiskeerFormsResources.SemiProbabilisticCalculationIcon), - }; - } - #endregion #region CreateFailureMechanismContextTreeNodeInfo Index: Riskeer/Common/test/Riskeer.Common.Forms.TestUtil.Test/CalculationTypeTestHelperTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Forms.TestUtil.Test/CalculationTypeTestHelperTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Forms.TestUtil.Test/CalculationTypeTestHelperTest.cs (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -0,0 +1,57 @@ +// Copyright (C) Stichting Deltares 2019. 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 System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Common.Forms.TreeNodeInfos; +using RiskeerFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.Common.Forms.TestUtil.Test +{ + [TestFixture] + public class CalculationTypeTestHelperTest + { + [Test] + public void CalculationTypeWithImageCases_Always_ReturnsExpectedCases() + { + // Call + IEnumerable testCases = CalculationTypeTestHelper.CalculationTypeWithImageCases.ToArray(); + + // Assert + var expectedCases = new[] + { + new TestCaseData(CalculationType.Hydraulic, RiskeerFormsResources.HydraulicCalculationIcon), + new TestCaseData(CalculationType.Probabilistic, RiskeerFormsResources.ProbabilisticCalculationIcon), + new TestCaseData(CalculationType.SemiProbabilistic, RiskeerFormsResources.SemiProbabilisticCalculationIcon) + }; + + Assert.AreEqual(expectedCases.Length, testCases.Count()); + for (var i = 0; i < testCases.Count(); i++) + { + Assert.AreEqual(expectedCases[i].Arguments[0], testCases.ElementAt(i).Arguments[0]); + TestHelper.AssertImagesAreEqual((Image) expectedCases[i].Arguments[1], (Image) testCases.ElementAt(i).Arguments[1]); + } + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Forms.TestUtil.Test/Riskeer.Common.Forms.TestUtil.Test.csproj =================================================================== diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r87452d01a3f950c5ac75374dd3e75aa72b4a4844 --- Riskeer/Common/test/Riskeer.Common.Forms.TestUtil.Test/Riskeer.Common.Forms.TestUtil.Test.csproj (.../Riskeer.Common.Forms.TestUtil.Test.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4) +++ Riskeer/Common/test/Riskeer.Common.Forms.TestUtil.Test/Riskeer.Common.Forms.TestUtil.Test.csproj (.../Riskeer.Common.Forms.TestUtil.Test.csproj) (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -12,18 +12,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + Index: Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/CalculationTypeTestHelper.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/CalculationTypeTestHelper.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/CalculationTypeTestHelper.cs (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -0,0 +1,51 @@ +// Copyright (C) Stichting Deltares 2019. 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 NUnit.Framework; +using Riskeer.Common.Forms.TreeNodeInfos; +using RiskeerFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.Common.Forms.TestUtil +{ + /// + /// Helper class to get test cases when dealing with . + /// + public static class CalculationTypeTestHelper + { + /// + /// Gets a collection of test cases to test the images belonging to various + /// values. + /// + public static IEnumerable CalculationTypeWithImageCases + { + get + { + return new[] + { + new TestCaseData(CalculationType.Hydraulic, RiskeerFormsResources.HydraulicCalculationIcon), + new TestCaseData(CalculationType.Probabilistic, RiskeerFormsResources.ProbabilisticCalculationIcon), + new TestCaseData(CalculationType.SemiProbabilistic, RiskeerFormsResources.SemiProbabilisticCalculationIcon), + }; + } + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/Riskeer.Common.Forms.TestUtil.csproj =================================================================== diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r87452d01a3f950c5ac75374dd3e75aa72b4a4844 --- Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/Riskeer.Common.Forms.TestUtil.csproj (.../Riskeer.Common.Forms.TestUtil.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4) +++ Riskeer/Common/test/Riskeer.Common.Forms.TestUtil/Riskeer.Common.Forms.TestUtil.csproj (.../Riskeer.Common.Forms.TestUtil.csproj) (revision 87452d01a3f950c5ac75374dd3e75aa72b4a4844) @@ -15,20 +15,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + +