/// <summary> /// Creates an instance of <see cref="AggregatedSerializableFailureMechanism"/> based on its input parameters. /// </summary> /// <param name="idGenerator">The generator to generate ids for the serializable components.</param> /// <param name="serializableTotalAssemblyResult">The <see cref="SerializableTotalAssemblyResult"/> /// the serializable components belong to.</param> /// <param name="failureMechanism">The <see cref="ExportableFailureMechanism"/> /// to create an <see cref="AggregatedSerializableFailureMechanism"/> for.</param> /// <returns>An <see cref="AggregatedSerializableFailureMechanism"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <exception cref="AssemblyCreatorException">Thrown when <paramref name="failureMechanism"/> /// is invalid to create a serializable counterpart for.</exception> /// <exception cref="NotSupportedException">Thrown when the <see cref="ExportableFailureMechanism"/> /// contains unsupported items in the failure mechanism section assembly results.</exception> public static AggregatedSerializableFailureMechanism Create(IdentifierGenerator idGenerator, SerializableTotalAssemblyResult serializableTotalAssemblyResult, ExportableFailureMechanism failureMechanism) { if (idGenerator == null) { throw new ArgumentNullException(nameof(idGenerator)); } if (serializableTotalAssemblyResult == null) { throw new ArgumentNullException(nameof(serializableTotalAssemblyResult)); } if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } SerializableFailureMechanism serializableFailureMechanism = SerializableFailureMechanismCreator.Create(idGenerator, serializableTotalAssemblyResult, failureMechanism); var serializableCollection = new SerializableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.SerializableFailureMechanismSectionCollection_IdPrefix)); AggregatedSerializableFailureMechanismSectionAssembly[] serializableFailureMechanismSectionAssemblyResults = failureMechanism.SectionAssemblyResults .Select(sectionAssemblyResult => CreateFailureMechanismSectionAssembly( idGenerator, serializableFailureMechanism, serializableCollection, sectionAssemblyResult)) .ToArray(); return(new AggregatedSerializableFailureMechanism(serializableFailureMechanism, serializableCollection, serializableFailureMechanismSectionAssemblyResults.Select(fmr => fmr.FailureMechanismSection), serializableFailureMechanismSectionAssemblyResults.Select(fmr => fmr.FailureMechanismSectionAssembly))); }
public void Create_WithValidArguments_ReturnsAggregatedSerializableFailureMechanism() { // Setup var random = new Random(21); var failureMechanism = new ExportableFailureMechanism( ExportableFailureMechanismAssemblyResultTestFactory.CreateResult(), new[] { ExportableFailureMechanismSectionAssemblyResultTestFactory.CreateWithProbability( ExportableFailureMechanismSectionTestFactory.CreateExportableFailureMechanismSection(random.Next()), random.Next()), ExportableFailureMechanismSectionAssemblyResultTestFactory.CreateWithProbability( ExportableFailureMechanismSectionTestFactory.CreateExportableFailureMechanismSection(random.Next()), random.Next()) }, random.NextEnumValue <ExportableFailureMechanismType>(), "code", "name"); var idGenerator = new IdentifierGenerator(); const string totalAssemblyId = "totalAssemblyId"; var serializableTotalAssembly = new SerializableTotalAssemblyResult(totalAssemblyId, new SerializableAssessmentProcess(), random.NextEnumValue <SerializableAssemblyMethod>(), random.NextEnumValue <SerializableAssemblyMethod>(), random.NextEnumValue <SerializableAssessmentSectionAssemblyGroup>(), random.NextDouble()); // Call AggregatedSerializableFailureMechanism aggregatedFailureMechanism = AggregatedSerializableFailureMechanismCreator.Create(idGenerator, serializableTotalAssembly, failureMechanism); // Assert SerializableFailureMechanism serializableFailureMechanism = aggregatedFailureMechanism.FailureMechanism; Assert.AreEqual("Fm.0", serializableFailureMechanism.Id); Assert.AreEqual(serializableTotalAssembly.Id, serializableFailureMechanism.TotalAssemblyResultId); Assert.AreEqual(SerializableFailureMechanismTypeCreator.Create(failureMechanism.FailureMechanismType), serializableFailureMechanism.FailureMechanismType); Assert.AreEqual(failureMechanism.Code, serializableFailureMechanism.GenericFailureMechanismCode); SerializableFailureMechanismAssemblyResultTestHelper.AssertSerializableFailureMechanismAssemblyResult(failureMechanism.FailureMechanismAssembly, serializableFailureMechanism.FailureMechanismAssemblyResult); SerializableFailureMechanismSectionCollection serializableFailureMechanismSectionCollection = aggregatedFailureMechanism.FailureMechanismSectionCollection; Assert.AreEqual("Vi.0", serializableFailureMechanismSectionCollection.Id); AssertFailureMechanismSectionAssemblies(failureMechanism, serializableFailureMechanismSectionCollection, serializableFailureMechanism, aggregatedFailureMechanism.FailureMechanismSections, aggregatedFailureMechanism.FailureMechanismSectionAssemblyResults); }
private static void AssertExportableFailureMechanism(IFailureMechanism <FailureMechanismSectionResult> failureMechanism, ExportableFailureMechanismType expectedFailureMechanismType, ExportableFailureMechanism actualExportableFailureMechanism) { Assert.AreEqual(expectedFailureMechanismType, actualExportableFailureMechanism.FailureMechanismType); Assert.AreEqual(failureMechanism.Code, actualExportableFailureMechanism.Code); ExportableFailureMechanismAssemblyResult exportableFailureMechanismAssemblyResult = actualExportableFailureMechanism.FailureMechanismAssembly; Assert.AreEqual(0.1, exportableFailureMechanismAssemblyResult.Probability); Assert.AreEqual(ExportableAssemblyMethod.BOI1A1, exportableFailureMechanismAssemblyResult.AssemblyMethod); Assert.AreEqual(failureMechanism.SectionResults.Count(), actualExportableFailureMechanism.SectionAssemblyResults.Count()); }
private static void AssertFailureMechanismSectionAssemblies( ExportableFailureMechanism expectedFailureMechanism, SerializableFailureMechanismSectionCollection expectedSerializableFailureMechanismSectionCollection, SerializableFailureMechanism expectedSerializableFailureMechanism, IEnumerable <SerializableFailureMechanismSection> serializableFailureMechanismSections, IEnumerable <SerializableFailureMechanismSectionAssembly> serializableFailureMechanismSectionAssemblies) { IEnumerable <ExportableFailureMechanismSection> expectedSections = expectedFailureMechanism.SectionAssemblyResults.Select(sar => sar.FailureMechanismSection); int expectedNrOfSections = expectedSections.Count(); Assert.AreEqual(expectedNrOfSections, serializableFailureMechanismSections.Count()); IEnumerable <ExportableFailureMechanismSectionAssemblyWithProbabilityResult> expectedSectionAssemblyResults = expectedFailureMechanism.SectionAssemblyResults; Assert.AreEqual(expectedSectionAssemblyResults.Count(), serializableFailureMechanismSectionAssemblies.Count()); var sectionId = 0; var sectionAssemblyId = 0; for (var i = 0; i < expectedNrOfSections; i++) { ExportableFailureMechanismSection expectedSection = expectedSections.ElementAt(i); SerializableFailureMechanismSection actualSection = serializableFailureMechanismSections.ElementAt(i); SerializableFailureMechanismSectionTestHelper.AssertFailureMechanismSection(expectedSection, expectedSerializableFailureMechanismSectionCollection, actualSection, sectionId++); ExportableFailureMechanismSectionAssemblyWithProbabilityResult expectedSectionAssemblyResult = expectedSectionAssemblyResults.ElementAt(i); SerializableFailureMechanismSectionAssembly actualSectionAssemblyResult = serializableFailureMechanismSectionAssemblies.ElementAt(i); Assert.AreEqual($"Fa.{sectionAssemblyId++}", actualSectionAssemblyResult.Id); Assert.AreEqual(expectedSerializableFailureMechanism.Id, actualSectionAssemblyResult.FailureMechanismId); Assert.AreEqual(actualSection.Id, actualSectionAssemblyResult.FailureMechanismSectionId); Assert.AreEqual(SerializableFailureMechanismSectionAssemblyGroupCreator.Create( expectedSectionAssemblyResult.AssemblyGroup), actualSectionAssemblyResult.SectionResult.AssemblyGroup); Assert.AreEqual(expectedSectionAssemblyResult.Probability, actualSectionAssemblyResult.SectionResult.Probability); } }
public void CreateExportableFailureMechanism_WithValidData_ReturnsExportableFailureMechanism() { // Setup var random = new Random(21); var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(2, 10)); var assessmentSection = new AssessmentSectionStub(); double probability = random.NextDouble(); var assemblyMethod = random.NextEnumValue <AssemblyMethod>(); FailureMechanismSectionAssemblyResultWrapper expectedSectionOutput = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create(); var failureMechanismType = random.NextEnumValue <ExportableFailureMechanismType>(); // Call ExportableFailureMechanism exportableFailureMechanism = ExportableFailureMechanismFactory.CreateExportableFailureMechanism <TestFailureMechanism, TestFailureMechanismSectionResult>( failureMechanism, assessmentSection, (fm, section) => new FailureMechanismAssemblyResultWrapper(probability, assemblyMethod), (sr, fm, section) => expectedSectionOutput, failureMechanismType); // Assert Assert.AreEqual(failureMechanismType, exportableFailureMechanism.FailureMechanismType); Assert.AreEqual(failureMechanism.Code, exportableFailureMechanism.Code); ExportableFailureMechanismAssemblyResult exportableFailureMechanismAssembly = exportableFailureMechanism.FailureMechanismAssembly; Assert.AreEqual(probability, exportableFailureMechanismAssembly.Probability); Assert.AreEqual(ExportableAssemblyMethodFactory.Create(assemblyMethod), exportableFailureMechanismAssembly.AssemblyMethod); IEnumerable <ExportableFailureMechanismSection> exportableFailureMechanismSections = exportableFailureMechanism.SectionAssemblyResults .Select(sar => sar.FailureMechanismSection); ExportableFailureMechanismSectionTestHelper.AssertExportableFailureMechanismSections(failureMechanism.Sections, exportableFailureMechanismSections); ExportableFailureMechanismSectionAssemblyResultTestHelper.AssertExportableFailureMechanismSectionResults( expectedSectionOutput, exportableFailureMechanismSections, exportableFailureMechanism.SectionAssemblyResults); }
public void Create_WithFailureMechanismAssemblyResult_ReturnsSerializableFailureMechanism() { // Setup var idGenerator = new IdentifierGenerator(); ExportableFailureMechanism failureMechanism = CreateExportableFailureMechanism(); const string totalAssemblyId = "totalAssemblyId"; SerializableTotalAssemblyResult serializableTotalAssembly = CreateSerializableTotalAssembly(totalAssemblyId); // Call SerializableFailureMechanism serializableFailureMechanism = SerializableFailureMechanismCreator.Create(idGenerator, serializableTotalAssembly, failureMechanism); // Assert Assert.AreEqual("Fm.0", serializableFailureMechanism.Id); Assert.AreEqual(serializableTotalAssembly.Id, serializableFailureMechanism.TotalAssemblyResultId); Assert.AreEqual(SerializableFailureMechanismTypeCreator.Create(failureMechanism.FailureMechanismType), serializableFailureMechanism.FailureMechanismType); Assert.AreEqual(failureMechanism.Code, serializableFailureMechanism.GenericFailureMechanismCode); SerializableFailureMechanismAssemblyResultTestHelper.AssertSerializableFailureMechanismAssemblyResult(failureMechanism.FailureMechanismAssembly, serializableFailureMechanism.FailureMechanismAssemblyResult); }
public void Constructor_ExpectedValues() { // Setup var random = new Random(21); ExportableFailureMechanismAssemblyResult failureMechanismAssembly = ExportableFailureMechanismAssemblyResultTestFactory.CreateResult(); IEnumerable <ExportableFailureMechanismSectionAssemblyWithProbabilityResult> sectionAssemblyResults = Enumerable.Empty <ExportableFailureMechanismSectionAssemblyWithProbabilityResult>(); var failureMechanismType = random.NextEnumValue <ExportableFailureMechanismType>(); const string code = "code"; const string name = "name"; // Call var failureMechanism = new ExportableFailureMechanism( failureMechanismAssembly, sectionAssemblyResults, failureMechanismType, code, name); // Assert Assert.AreSame(failureMechanismAssembly, failureMechanism.FailureMechanismAssembly); Assert.AreSame(sectionAssemblyResults, failureMechanism.SectionAssemblyResults); Assert.AreEqual(failureMechanismType, failureMechanism.FailureMechanismType); Assert.AreEqual(code, failureMechanism.Code); Assert.AreEqual(name, failureMechanism.Name); }
/// <summary> /// Creates an instance of <see cref="SerializableFailureMechanism"/> based on its input parameters. /// </summary> /// <param name="idGenerator">The generator to generate an id for the <see cref="SerializableFailureMechanism"/>.</param> /// <param name="serializableTotalAssembly">The <see cref="SerializableTotalAssemblyResult"/> /// the <see cref="SerializableFailureMechanism"/> belongs to.</param> /// <param name="failureMechanism">The <see cref="ExportableFailureMechanism"/> /// to create a <see cref="SerializableFailureMechanism"/> for.</param> /// <returns>A <see cref="SerializableFailureMechanism"/></returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <exception cref="AssemblyCreatorException">Thrown when <paramref name="failureMechanism"/> is invalid to /// create a serializable counterpart for.</exception> public static SerializableFailureMechanism Create(IdentifierGenerator idGenerator, SerializableTotalAssemblyResult serializableTotalAssembly, ExportableFailureMechanism failureMechanism) { if (idGenerator == null) { throw new ArgumentNullException(nameof(idGenerator)); } if (serializableTotalAssembly == null) { throw new ArgumentNullException(nameof(serializableTotalAssembly)); } if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } return(new SerializableFailureMechanism(idGenerator.GetNewId(Resources.SerializableFailureMechanismCreator_IdPrefix), SerializableFailureMechanismTypeCreator.Create(failureMechanism.FailureMechanismType), failureMechanism.Code, failureMechanism.Name, serializableTotalAssembly, SerializableFailureMechanismResultCreator.Create(failureMechanism.FailureMechanismAssembly))); }