public void GivenMapLayerWithFailureMechanismSectionAssemblyResults_WhenChangingFailureMechanismDataAndObserversNotified_ThenMapDataUpdated()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var random           = new Random(21);
            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            using (var mapLayer = new NonCalculatableFailureMechanismSectionResultsMapLayer <TestFailureMechanismSectionResult>(
                       failureMechanism, result => assemblyResult))
            {
                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);

                // When
                failureMechanism.SetSections(new[]
                {
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                    {
                        new Point2D(0, 0),
                        new Point2D(1, 1)
                    }),
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                    {
                        new Point2D(1, 1),
                        new Point2D(2, 2)
                    })
                }, string.Empty);
                failureMechanism.NotifyObservers();

                // Then
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }
Exemplo n.º 2
0
        public void UpdateSectionsWithImportedData_WithEmptyData_ClearsSectionsAndUpdatesPathAndReturnsAffectedObjects()
        {
            // Setup
            const string oldSourcePath = "old/path";
            string       sourcePath    = TestHelper.GetScratchPadPath();

            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, oldSourcePath);

            var failureMechanismSectionReplaceStrategy = new FailureMechanismSectionReplaceStrategy(failureMechanism);

            // Precondition
            IEnumerable <FailureMechanismSection> failureMechanismSections = failureMechanism.Sections;

            Assert.AreEqual(1, failureMechanismSections.Count());
            Assert.AreEqual(oldSourcePath, failureMechanism.FailureMechanismSectionSourcePath);

            // Call
            IEnumerable <IObservable> affectedObjects = failureMechanismSectionReplaceStrategy.UpdateSectionsWithImportedData(Enumerable.Empty <FailureMechanismSection>(), sourcePath);

            // Assert
            Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath);
            Assert.IsEmpty(failureMechanismSections);
            CollectionAssert.AreEqual(new IObservable[]
            {
                failureMechanism,
                failureMechanism.SectionResults
            }, affectedObjects);
        }
Exemplo n.º 3
0
        public void AssembleFailureMechanism_WithInput_SetsInputOnCalculator()
        {
            // Setup
            var failureMechanism = new TestFailureMechanism
            {
                AssemblyResult =
                {
                    ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic
                }
            };

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, "APath");

            var assessmentSection = new AssessmentSectionStub();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;

                // Call
                FailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);

                // Assert
                Assert.AreEqual(failureMechanism.GeneralInput.N, failureMechanismAssemblyCalculator.FailureMechanismN);
                Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput.AssemblyResult, failureMechanismAssemblyCalculator.SectionAssemblyResultsInput.Single());
                Assert.AreEqual(failureMechanism.GeneralInput.ApplyLengthEffectInSection, failureMechanismAssemblyCalculator.ApplyLengthEffect);
            }
        }
Exemplo n.º 4
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var    failureMechanism = new TestFailureMechanism();
            string sourcePath       = TestHelper.GetScratchPadPath();

            var random = new Random(39);
            var probabilityAssessmentInput = new TestProbabilityAssessmentInput(random.NextDouble(), random.NextDouble());

            IEnumerable <FailureMechanismSection> sections = new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            };

            failureMechanism.SetSections(sections, sourcePath);

            // Call
            using (var properties = new FailureMechanismSectionsProbabilityAssessmentProperties(
                       failureMechanism, probabilityAssessmentInput))
            {
                // Assert
                Assert.IsInstanceOf <ObjectProperties <IFailureMechanism> >(properties);
                Assert.IsInstanceOf <IDisposable>(properties);
                Assert.AreSame(failureMechanism, properties.Data);

                TestHelper.AssertTypeConverter <FailureMechanismSectionsProperties, ExpandableArrayConverter>(
                    nameof(FailureMechanismSectionsProperties.Sections));
                Assert.AreEqual(sections.Count(), properties.Sections.Length);

                double sectionStart = 0;
                for (var i = 0; i < sections.Count(); i++)
                {
                    FailureMechanismSection section = sections.ElementAt(i);
                    FailureMechanismSectionProbabilityAssessmentProperties property = properties.Sections[i];

                    Assert.AreSame(section, property.Data);
                    Assert.AreEqual(1 + probabilityAssessmentInput.A * section.Length / probabilityAssessmentInput.B,
                                    property.N,
                                    property.N.GetAccuracy());

                    double sectionEnd = sectionStart + section.Length;
                    Assert.AreEqual(sectionStart, property.SectionStart, property.SectionStart.GetAccuracy());
                    Assert.AreEqual(sectionEnd, property.SectionEnd, property.SectionEnd.GetAccuracy());
                    sectionStart = sectionEnd;
                }

                Assert.AreEqual(sourcePath, properties.SourcePath);
            }
        }
        public void CreateFailureMechanismSectionsUpdateInfo_WithSourcePath_ReturnsIsEnabledTrue()
        {
            // Setup
            var mocks = new MockRepository();
            var sectionResultUpdateStrategy = mocks.Stub <IFailureMechanismSectionResultUpdateStrategy <FailureMechanismSectionResult> >();
            var assessmentSection           = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine());
            mocks.ReplayAll();

            // Call
            UpdateInfo <FailureMechanismSectionsContext> updateInfo = RiskeerUpdateInfoFactory.CreateFailureMechanismSectionsUpdateInfo <
                FailureMechanismSectionsContext, TestFailureMechanism, FailureMechanismSectionResult>(sectionResultUpdateStrategy);

            // Assert
            var testFailureMechanism = new TestFailureMechanism();

            testFailureMechanism.SetSections(Enumerable.Empty <FailureMechanismSection>(), "path/to/sections");
            var failureMechanismSectionsContext = new FailureMechanismSectionsContext(testFailureMechanism, assessmentSection);

            Assert.IsTrue(updateInfo.IsEnabled(failureMechanismSectionsContext));
            mocks.VerifyAll();
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var random           = new Random(21);
            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            // Call
            using (var mapLayer = new NonCalculatableFailureMechanismSectionResultsMapLayer <TestFailureMechanismSectionResult>(
                       failureMechanism, result => assemblyResult))
            {
                // Assert
                Assert.IsInstanceOf <IDisposable>(mapLayer);
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);
            }
        }
Exemplo n.º 7
0
        public void UpdateSectionsWithImportedData_WithValidData_SetsSectionsToFailureMechanismAndCopiesPropertiesOfEqualSectionsAndReturnsAffectedObjects()
        {
            // Setup
            string sourcePath = TestHelper.GetScratchPadPath();

            var failureMechanism = new TestFailureMechanism();
            FailureMechanismSection failureMechanismSection1 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(5.0, 5.0)
            });
            FailureMechanismSection failureMechanismSection2 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(5.0, 5.0),
                new Point2D(10.0, 10.0)
            });

            failureMechanism.SetSections(new[]
            {
                failureMechanismSection1,
                failureMechanismSection2
            }, sourcePath);

            IObservableEnumerable <FailureMechanismSectionResult> failureMechanismSectionResults = failureMechanism.SectionResults;
            FailureMechanismSectionResult oldSectionResult = failureMechanismSectionResults.First();

            var sectionResultUpdateStrategy           = new TestUpdateFailureMechanismSectionResultUpdateStrategy();
            var failureMechanismSectionUpdateStrategy = new FailureMechanismSectionUpdateStrategy <FailureMechanismSectionResult>(failureMechanism, sectionResultUpdateStrategy);

            FailureMechanismSection[] sections =
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                {
                    new Point2D(0.0, 0.0),
                    new Point2D(5.0, 5.0)
                }),
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                {
                    new Point2D(5.0, 5.0),
                    new Point2D(15.0, 15.0)
                })
            };

            // Call
            IEnumerable <IObservable> affectedObjects = failureMechanismSectionUpdateStrategy.UpdateSectionsWithImportedData(sections, sourcePath);

            // Assert
            Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath);

            IEnumerable <FailureMechanismSection> failureMechanismSections = failureMechanism.Sections;

            Assert.AreEqual(2, failureMechanismSections.Count());
            CollectionAssert.AreEqual(sections, failureMechanismSections);
            Assert.AreSame(oldSectionResult, sectionResultUpdateStrategy.Origin);
            Assert.AreSame(failureMechanismSectionResults.First(), sectionResultUpdateStrategy.Target);
            CollectionAssert.AreEqual(new IObservable[]
            {
                failureMechanism,
                failureMechanism.SectionResults
            }, affectedObjects);
        }