public void CreateAssemblyGroupFeatures_ValidParameters_ReturnsExpectedFeatures() { // Setup var random = new Random(39); var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10)); var expectedAssemblyResult = new FailureMechanismSectionAssemblyResult( random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextEnumValue <FailureMechanismSectionAssemblyGroup>()); // Call IEnumerable <MapFeature> features = AssemblyMapDataFeaturesFactory.CreateAssemblyGroupFeatures <FailureMechanismSectionResult>( failureMechanism, sr => expectedAssemblyResult); // Assert Assert.AreEqual(failureMechanism.Sections.Count(), features.Count()); for (var i = 0; i < features.Count(); i++) { FailureMechanismSection section = failureMechanism.Sections.ElementAt(i); MapFeature mapFeature = features.ElementAt(i); AssertAssemblyGroupMapFeature(section, mapFeature, expectedAssemblyResult); } }
public void CreateAssemblyGroupFeatures_PerformAssemblyFuncThrowsAssemblyExceptionOnFirstSection_FirstSectionSkipped() { // Setup var random = new Random(39); var failureMechanism = new TestFailureMechanism(); FailureMechanismTestHelper.AddSections(failureMechanism, 2); var expectedAssemblyResult = new FailureMechanismSectionAssemblyResult( random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextEnumValue <FailureMechanismSectionAssemblyGroup>()); // Call var shouldThrowException = true; IEnumerable <MapFeature> features = AssemblyMapDataFeaturesFactory.CreateAssemblyGroupFeatures <FailureMechanismSectionResult>( failureMechanism, sr => { if (shouldThrowException) { shouldThrowException = false; throw new AssemblyException(); } return(expectedAssemblyResult); }); // Assert AssertAssemblyGroupMapFeature(failureMechanism.Sections.ElementAt(1), features.Single(), expectedAssemblyResult); }
private static AssessmentSection CreateConfiguredAssessmentSection() { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { Name = "assessmentSectionName", Id = "assessmentSectionId" }; assessmentSection.ReferenceLine.SetGeometry(new[] { new Point2D(0, 0), new Point2D(3, 4) }); assessmentSection.SpecificFailureMechanisms.AddRange(new[] { new SpecificFailureMechanism { Name = "Specific failure mechanism 1" }, new SpecificFailureMechanism { Name = "Specific failure mechanism 2" } }); FailureMechanismTestHelper.AddSections(assessmentSection.Piping, 2); FailureMechanismTestHelper.AddSections(assessmentSection.MacroStabilityInwards, 2); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverErosionInwards, 2); FailureMechanismTestHelper.AddSections(assessmentSection.HeightStructures, 2); FailureMechanismTestHelper.AddSections(assessmentSection.ClosingStructures, 2); FailureMechanismTestHelper.AddSections(assessmentSection.StabilityPointStructures, 2); FailureMechanismTestHelper.AddSections(assessmentSection.StabilityStoneCover, 2); FailureMechanismTestHelper.AddSections(assessmentSection.WaveImpactAsphaltCover, 2); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverErosionOutwards, 2); FailureMechanismTestHelper.AddSections(assessmentSection.DuneErosion, 2); FailureMechanismTestHelper.AddSections(assessmentSection.Microstability, 2); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverSlipOffOutwards, 2); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverSlipOffInwards, 2); FailureMechanismTestHelper.AddSections(assessmentSection.PipingStructure, 2); FailureMechanismTestHelper.AddSections(assessmentSection.WaterPressureAsphaltCover, 2); FailureMechanismTestHelper.AddSections(assessmentSection.SpecificFailureMechanisms.First(), 2); FailureMechanismTestHelper.AddSections(assessmentSection.SpecificFailureMechanisms.Last(), 2); return(assessmentSection); }
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 CreateExportableAssessmentSection_WithAssessmentSectionWithReferenceLine_ReturnsExpectedValues() { // Setup const string name = "assessmentSectionName"; const string id = "assessmentSectionId"; var random = new Random(21); var assessmentSection = new AssessmentSection(random.NextEnumValue <AssessmentSectionComposition>()) { Name = name, Id = id }; ReferenceLineTestFactory.SetReferenceLineGeometry(assessmentSection.ReferenceLine); assessmentSection.SpecificFailureMechanisms.Add(new SpecificFailureMechanism()); assessmentSection.SpecificFailureMechanisms.Add(new SpecificFailureMechanism()); FailureMechanismTestHelper.AddSections(assessmentSection.Piping, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.MacroStabilityInwards, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverErosionInwards, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.HeightStructures, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.ClosingStructures, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.StabilityPointStructures, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.StabilityStoneCover, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.WaveImpactAsphaltCover, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverErosionOutwards, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.DuneErosion, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.Microstability, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverSlipOffOutwards, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.GrassCoverSlipOffInwards, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.PipingStructure, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.WaterPressureAsphaltCover, random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.SpecificFailureMechanisms.First(), random.Next(1, 10)); FailureMechanismTestHelper.AddSections(assessmentSection.SpecificFailureMechanisms.Last(), random.Next(1, 10)); using (new AssemblyToolCalculatorFactoryConfig()) { // Call ExportableAssessmentSection exportableAssessmentSection = ExportableAssessmentSectionFactory.CreateExportableAssessmentSection(assessmentSection); // Assert Assert.AreEqual(name, exportableAssessmentSection.Name); Assert.AreEqual(id, exportableAssessmentSection.Id); CollectionAssert.AreEqual(assessmentSection.ReferenceLine.Points, exportableAssessmentSection.Geometry); ExportableAssessmentSectionAssemblyResult exportableAssessmentSectionAssemblyResult = exportableAssessmentSection.AssessmentSectionAssembly; Assert.AreEqual(ExportableAssemblyMethod.BOI2A1, exportableAssessmentSectionAssemblyResult.ProbabilityAssemblyMethod); Assert.AreEqual(ExportableAssemblyMethod.BOI2B1, exportableAssessmentSectionAssemblyResult.AssemblyGroupAssemblyMethod); Assert.AreEqual(AssessmentSectionAssemblyGroup.APlus, exportableAssessmentSectionAssemblyResult.AssemblyGroup); Assert.AreEqual(0.14, exportableAssessmentSectionAssemblyResult.Probability); AssertExportableFailureMechanisms(exportableAssessmentSection.FailureMechanisms, assessmentSection); Assert.AreEqual(1, exportableAssessmentSection.CombinedSectionAssemblies.Count()); ExportableCombinedSectionAssembly exportableCombinedSectionAssembly = exportableAssessmentSection.CombinedSectionAssemblies.ElementAt(0); Assert.AreEqual(FailureMechanismSectionAssemblyGroup.Zero, exportableCombinedSectionAssembly.CombinedSectionAssemblyResult.AssemblyGroup); Assert.AreEqual(ExportableAssemblyMethod.BOI3C1, exportableCombinedSectionAssembly.CombinedSectionAssemblyResult.AssemblyGroupAssemblyMethod); Assert.AreEqual(0.0, exportableCombinedSectionAssembly.CombinedSectionAssemblyResult.FailureMechanismSection.StartDistance); Assert.AreEqual(1.0, exportableCombinedSectionAssembly.CombinedSectionAssemblyResult.FailureMechanismSection.EndDistance); AssertExportableFailureMechanismCombinedSectionAssemblyResults(exportableCombinedSectionAssembly.FailureMechanismResults, assessmentSection); Assert.AreEqual(ExportableAssemblyMethod.BOI3A1, exportableCombinedSectionAssembly.Section.AssemblyMethod); Assert.AreEqual(0.0, exportableCombinedSectionAssembly.Section.StartDistance); Assert.AreEqual(1.0, exportableCombinedSectionAssembly.Section.EndDistance); } }