/// <summary> /// Creates a collection of <see cref="ExportableFailureMechanismSectionAssemblyWithProbabilityResult"/> /// with assembly results based on <paramref name="failureMechanism"/>. /// </summary> /// <param name="failureMechanism">The failure mechanism to create a collection of /// <see cref="ExportableFailureMechanismSectionAssemblyWithProbabilityResult"/> for.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> to use in the assembly.</param> /// <param name="assembleFailureMechanismSectionFunc">The <see cref="Func{T1,T2,T3,TResult}"/> /// to perform the failure mechanism section assembly.</param> /// <typeparam name="TFailureMechanism">The type of the failure mechanism.</typeparam> /// <typeparam name="TSectionResult">The type of the section result.</typeparam> /// <returns>A collection of <see cref="ExportableFailureMechanismSectionAssemblyWithProbabilityResult"/>.</returns> /// <exception cref="AssemblyException">Thrown when assembly results cannot be created.</exception> private static IEnumerable <ExportableFailureMechanismSectionAssemblyWithProbabilityResult> CreateExportableFailureMechanismSectionResults <TFailureMechanism, TSectionResult>( TFailureMechanism failureMechanism, IAssessmentSection assessmentSection, Func <TSectionResult, TFailureMechanism, IAssessmentSection, FailureMechanismSectionAssemblyResultWrapper> assembleFailureMechanismSectionFunc) where TFailureMechanism : IFailureMechanism <TSectionResult> where TSectionResult : FailureMechanismSectionResult { IDictionary <TSectionResult, ExportableFailureMechanismSection> failureMechanismSectionsLookup = ExportableFailureMechanismSectionHelper.CreateFailureMechanismSectionResultLookup(failureMechanism.SectionResults); var exportableResults = new List <ExportableFailureMechanismSectionAssemblyWithProbabilityResult>(); foreach (KeyValuePair <TSectionResult, ExportableFailureMechanismSection> failureMechanismSectionPair in failureMechanismSectionsLookup) { FailureMechanismSectionAssemblyResultWrapper assemblyResultWrapper = assembleFailureMechanismSectionFunc( failureMechanismSectionPair.Key, failureMechanism, assessmentSection); FailureMechanismSectionAssemblyResult assemblyResult = assemblyResultWrapper.AssemblyResult; exportableResults.Add( new ExportableFailureMechanismSectionAssemblyWithProbabilityResult( failureMechanismSectionPair.Value, assemblyResult.FailureMechanismSectionAssemblyGroup, assemblyResult.SectionProbability, ExportableAssemblyMethodFactory.Create(assemblyResultWrapper.AssemblyGroupMethod), ExportableAssemblyMethodFactory.Create(assemblyResultWrapper.ProbabilityMethod))); } return(exportableResults); }
public void CreateFailureMechanismSectionResultLookup_FailureMechanismSectionResultsNull_ThrowsArgumentNullException() { // Call void Call() => ExportableFailureMechanismSectionHelper.CreateFailureMechanismSectionResultLookup <TestFailureMechanismSectionResult>(null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanismSectionResults", exception.ParamName); }
public void CreateFailureMechanismSectionResultLookup_WithFailureMechanismSectionResults_ReturnsExpectedDictionary() { // Setup var failureMechanismSectionResults = new[] { new TestFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(0, 0), new Point2D(0, 10) })), new TestFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(0, 10), new Point2D(0, 20) })), new TestFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(0, 20), new Point2D(0, 40) })) }; // Call IDictionary <TestFailureMechanismSectionResult, ExportableFailureMechanismSection> failureMechanismSectionResultsLookup = ExportableFailureMechanismSectionHelper.CreateFailureMechanismSectionResultLookup(failureMechanismSectionResults); // Assert CollectionAssert.AreEqual(failureMechanismSectionResults, failureMechanismSectionResultsLookup.Keys); TestFailureMechanismSectionResult firstSectionResult = failureMechanismSectionResults[0]; ExportableFailureMechanismSection firstExportableSection = failureMechanismSectionResultsLookup[firstSectionResult]; Assert.AreSame(firstSectionResult.Section.Points, firstExportableSection.Geometry); Assert.AreEqual(0, firstExportableSection.StartDistance); Assert.AreEqual(10, firstExportableSection.EndDistance); TestFailureMechanismSectionResult secondSectionResult = failureMechanismSectionResults[1]; ExportableFailureMechanismSection secondExportableSection = failureMechanismSectionResultsLookup[secondSectionResult]; Assert.AreSame(secondSectionResult.Section.Points, secondExportableSection.Geometry); Assert.AreEqual(10, secondExportableSection.StartDistance); Assert.AreEqual(20, secondExportableSection.EndDistance); TestFailureMechanismSectionResult thirdSectionResult = failureMechanismSectionResults[2]; ExportableFailureMechanismSection thirdExportableSection = failureMechanismSectionResultsLookup[thirdSectionResult]; Assert.AreSame(thirdSectionResult.Section.Points, thirdExportableSection.Geometry); Assert.AreEqual(20, thirdExportableSection.StartDistance); Assert.AreEqual(40, thirdExportableSection.EndDistance); }