Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssessmentSectionAssemblyInputCreator.cs =================================================================== diff -u -rfd617a479211d0370b325fa4de269906e3e70348 -rb83e33013182f266cc099119d9ecda0551bad6c8 --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssessmentSectionAssemblyInputCreator.cs (.../AssessmentSectionAssemblyInputCreator.cs) (revision fd617a479211d0370b325fa4de269906e3e70348) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssessmentSectionAssemblyInputCreator.cs (.../AssessmentSectionAssemblyInputCreator.cs) (revision b83e33013182f266cc099119d9ecda0551bad6c8) @@ -71,6 +71,73 @@ return new FailureMechanismAssemblyResult(ConvertFailureMechanismAssemblyCategoryGroup(input)); } + /// + /// Creates based on the given parameters. + /// + /// The assembly to create a from. + /// The created . + /// Thrown when is null. + /// Thrown when contains + /// an invalid . + /// Thrown when contains + /// a valid but unsupported . + public static AssessmentSectionAssemblyResult CreateAssessementSectionAssemblyResult(AssessmentSectionAssembly input) + { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + return new AssessmentSectionAssemblyResult(ConvertAssessmentSectionAssemblyCategoryGroup(input.Group), + input.Probability); + } + + /// + /// Creates based on the given parameters. + /// + /// The assembly to create a from. + /// The created . + /// Thrown when contains + /// an invalid . + /// Thrown when contains + /// a valid but unsupported . + public static AssessmentSectionAssemblyResult CreateAssessementSectionAssemblyResult(AssessmentSectionAssemblyCategoryGroup input) + { + return new AssessmentSectionAssemblyResult(ConvertAssessmentSectionAssemblyCategoryGroup(input)); + } + + private static EAssessmentGrade ConvertAssessmentSectionAssemblyCategoryGroup(AssessmentSectionAssemblyCategoryGroup input) + { + if (!Enum.IsDefined(typeof(AssessmentSectionAssemblyCategoryGroup), input)) + { + throw new InvalidEnumArgumentException(nameof(input), + (int) input, + typeof(AssessmentSectionAssemblyCategoryGroup)); + } + + switch (input) + { + case AssessmentSectionAssemblyCategoryGroup.None: + return EAssessmentGrade.Gr; + case AssessmentSectionAssemblyCategoryGroup.NotApplicable: + return EAssessmentGrade.Nvt; + case AssessmentSectionAssemblyCategoryGroup.NotAssessed: + return EAssessmentGrade.Ngo; + case AssessmentSectionAssemblyCategoryGroup.APlus: + return EAssessmentGrade.APlus; + case AssessmentSectionAssemblyCategoryGroup.A: + return EAssessmentGrade.A; + case AssessmentSectionAssemblyCategoryGroup.B: + return EAssessmentGrade.B; + case AssessmentSectionAssemblyCategoryGroup.C: + return EAssessmentGrade.C; + case AssessmentSectionAssemblyCategoryGroup.D: + return EAssessmentGrade.D; + default: + throw new NotSupportedException(); + } + } + private static EFailureMechanismCategory ConvertFailureMechanismAssemblyCategoryGroup(FailureMechanismAssemblyCategoryGroup input) { if (!Enum.IsDefined(typeof(FailureMechanismAssemblyCategoryGroup), input)) Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyInputCreatorTest.cs =================================================================== diff -u -rfd617a479211d0370b325fa4de269906e3e70348 -rb83e33013182f266cc099119d9ecda0551bad6c8 --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyInputCreatorTest.cs (.../AssessmentSectionAssemblyInputCreatorTest.cs) (revision fd617a479211d0370b325fa4de269906e3e70348) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyInputCreatorTest.cs (.../AssessmentSectionAssemblyInputCreatorTest.cs) (revision b83e33013182f266cc099119d9ecda0551bad6c8) @@ -49,6 +49,21 @@ } } + private static IEnumerable GetAssessmentSectionAssemblyCategoryGroupConversions + { + get + { + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.None, EAssessmentGrade.Gr); + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.NotAssessed, EAssessmentGrade.Ngo); + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.NotApplicable, EAssessmentGrade.Nvt); + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.APlus, EAssessmentGrade.APlus); + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.A, EAssessmentGrade.A); + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.B, EAssessmentGrade.B); + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.C, EAssessmentGrade.C); + yield return new TestCaseData(AssessmentSectionAssemblyCategoryGroup.D, EAssessmentGrade.D); + } + } + [Test] public void CreateFailureMechanismAssemblyResult_FailureMechanismAssemblyNull_ThrowsArgumentNullException() { @@ -118,5 +133,74 @@ Assert.AreEqual(expectedGroup, result.Category); Assert.IsNull(result.FailureProbability); } + + [Test] + public void CreateAssessementSectionAssemblyResult_WithAssessmentSectionAssemblyAndInvalidEnumInput_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssessmentSectionAssemblyInputCreator.CreateAssessementSectionAssemblyResult(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("input", exception.ParamName); + } + + [Test] + public void CreateAssessementSectionAssemblyResult_WithAssessmentSectionAssemblyAndInvalidEnumInput_ThrowsInvalidEnumArgumentException() + { + // Setup + var random = new Random(21); + var input = new AssessmentSectionAssembly(random.NextDouble(), (AssessmentSectionAssemblyCategoryGroup) 99); + + // Call + TestDelegate test = () => AssessmentSectionAssemblyInputCreator.CreateAssessementSectionAssemblyResult(input); + + // Assert + const string expectedMessage = "The value of argument 'input' (99) is invalid for Enum type 'AssessmentSectionAssemblyCategoryGroup'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(GetAssessmentSectionAssemblyCategoryGroupConversions))] + public void CreateAssessementSectionAssemblyResult_WithValidAssessmentSectionAssembly_ThrowsInvalidEnumArgumentException( + AssessmentSectionAssemblyCategoryGroup originalGroup, + EAssessmentGrade expectedGroup) + { + // Setup + var random = new Random(21); + var input = new AssessmentSectionAssembly(random.NextDouble(), originalGroup); + + // Call + AssessmentSectionAssemblyResult result = AssessmentSectionAssemblyInputCreator.CreateAssessementSectionAssemblyResult(input); + + // Assert + Assert.AreEqual(expectedGroup, result.Category); + Assert.AreEqual(input.Probability, result.FailureProbability); + } + + [Test] + public void CreateAssessementSectionAssemblyResult_WithInvalidEnumInput_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => AssessmentSectionAssemblyInputCreator.CreateAssessementSectionAssemblyResult((AssessmentSectionAssemblyCategoryGroup) 99); + + // Assert + const string expectedMessage = "The value of argument 'input' (99) is invalid for Enum type 'AssessmentSectionAssemblyCategoryGroup'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(GetAssessmentSectionAssemblyCategoryGroupConversions))] + public void CreateAssessementSectionAssemblyResult_WithValidEnumInput_ThrowsInvalidEnumArgumentException( + AssessmentSectionAssemblyCategoryGroup originalGroup, + EAssessmentGrade expectedGroup) + { + // Call + AssessmentSectionAssemblyResult result = AssessmentSectionAssemblyInputCreator.CreateAssessementSectionAssemblyResult(originalGroup); + + // Assert + Assert.AreEqual(expectedGroup, result.Category); + Assert.IsNull(result.FailureProbability); + } } } \ No newline at end of file