示例#1
0
        private static void AssertPropertyChangeWithOrWithoutCalculationOutput(
            Action <HeightStructuresCalculationRow> setProperty,
            Action <StructuresCalculationScenario <HeightStructuresInput> > assertions,
            bool hasOutput,
            bool expectUpdates)
        {
            // Setup
            var mockRepository = new MockRepository();
            var inputObserver  = mockRepository.StrictMock <IObserver>();

            if (expectUpdates)
            {
                inputObserver.Expect(o => o.UpdateObserver());
            }

            var calculationObserver = mockRepository.StrictMock <IObserver>();

            if (expectUpdates && hasOutput)
            {
                calculationObserver.Expect(o => o.UpdateObserver());
            }

            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            StructuresOutput assignedOutput = null;

            StructuresCalculationScenario <HeightStructuresInput> calculation = HeightStructuresCalculationScenarioTestFactory.CreateNotCalculatedHeightStructuresCalculationScenario(new FailureMechanismSection("Section 1", new List <Point2D>
            {
                new Point2D(0.0, 0.0)
            }));

            calculation.InputParameters.HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            if (hasOutput)
            {
                assignedOutput = new TestStructuresOutput();
            }

            calculation.Output = assignedOutput;

            var row = new HeightStructuresCalculationRow(calculation, handler);

            calculation.Attach(calculationObserver);
            calculation.InputParameters.Attach(inputObserver);

            // Call
            setProperty(row);

            // Assert
            assertions(calculation);
            if (expectUpdates)
            {
                Assert.IsNull(calculation.Output);
            }
            else
            {
                Assert.AreSame(assignedOutput, calculation.Output);
            }
        }
示例#2
0
        private static IEnumerable <TestCaseData> GetCalculations()
        {
            var outputWithoutGeneralResult = new TestStructuresOutput();
            var outputWithGeneralResult    = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint());

            yield return(new TestCaseData(new TestStructuresCalculation
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = true
                },
                Output = outputWithGeneralResult
            }, false)
                         .SetName("OutputSufficientScenario1"));

            yield return(new TestCaseData(new TestStructuresCalculation
            {
                Output = outputWithoutGeneralResult
            }, false)
                         .SetName("OutputSufficientScenario2"));

            yield return(new TestCaseData(new TestStructuresCalculation(), true)
                         .SetName("NoOutputScenario1"));

            yield return(new TestCaseData(new TestStructuresCalculation
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = true
                }
            }, true)
                         .SetName("NoOutputScenario2"));

            yield return(new TestCaseData(new TestStructuresCalculation
            {
                Output = outputWithGeneralResult
            }, true)
                         .SetName("OutputWithRedundantGeneralResult"));

            yield return(new TestCaseData(new TestStructuresCalculation
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = true
                },
                Output = outputWithoutGeneralResult
            }, true)
                         .SetName("OutputWithMissingGeneralResult"));
        }
示例#3
0
        public void ClearIllustrationPoints_CalculationWithOutput_ClearsIllustrationPointResult(bool hasIllustrationPoints)
        {
            // Setup
            var originalOutput = new TestStructuresOutput(hasIllustrationPoints
                                                              ? new TestGeneralResultFaultTreeIllustrationPoint()
                                                              : null);

            var calculation = new TestStructuresCalculation
            {
                Output = originalOutput
            };

            // Call
            calculation.ClearIllustrationPoints();

            // Assert
            Assert.AreSame(originalOutput, calculation.Output);
            Assert.IsNull(calculation.Output.GeneralResult);
        }
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            var generalResult    = new TestGeneralResultFaultTreeIllustrationPoint();
            var structuresOutput = new TestStructuresOutput(generalResult);

            // Call
            var properties = new StructuresOutputProperties(structuresOutput);

            // Assert
            Assert.AreEqual(generalResult.GoverningWindDirection.Name, properties.WindDirection);

            Assert.AreEqual(ProbabilityFormattingHelper.Format(0.5), properties.Probability);
            Assert.AreEqual(0, properties.Reliability, properties.Reliability.GetAccuracy());

            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.AlphaValues));
            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.Durations));

            int nrOfExpectedStochasts = generalResult.Stochasts.Count();

            Assert.AreEqual(nrOfExpectedStochasts, properties.AlphaValues.Length);
            Assert.AreEqual(nrOfExpectedStochasts, properties.Durations.Length);
            Stochast expectedStochast = generalResult.Stochasts.First();

            Assert.AreEqual(expectedStochast.Alpha, properties.AlphaValues[0].Alpha);
            Assert.AreEqual(expectedStochast.Duration, properties.Durations[0].Duration);

            TestHelper.AssertTypeConverter <StructuresOutputProperties, ExpandableArrayConverter>(
                nameof(StructuresOutputProperties.IllustrationPoints));

            int nrOfExpectedTopLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.Count();

            Assert.AreEqual(nrOfExpectedTopLevelIllustrationPoints, properties.IllustrationPoints.Length);

            CollectionAssert.AreEqual(generalResult.TopLevelIllustrationPoints, properties.IllustrationPoints.Select(i => i.Data));
        }
示例#5
0
        public void ClearStructuresCalculationIllustrationPoints_CalculationsWithAndWithoutIllustrationPoints_ClearsIllustrationPointAndReturnsAffectedCalculations()
        {
            // Setup
            var originalOutputWithIllustrationPoints1 = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint());
            var calculationWithIllustrationPoints1    = new TestStructuresCalculation
            {
                Output = originalOutputWithIllustrationPoints1
            };

            var originalOutputWithIllustrationPoints2 = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint());
            var calculationWithIllustrationPoints2    = new TestStructuresCalculation
            {
                Output = originalOutputWithIllustrationPoints2
            };

            var originalOutput1        = new TestStructuresOutput();
            var calculationWithOutput1 = new TestStructuresCalculation
            {
                Output = originalOutput1
            };

            var originalOutput2        = new TestStructuresOutput();
            var calculationWithOutput2 = new TestStructuresCalculation
            {
                Output = originalOutput2
            };

            TestStructuresCalculation[] calculations =
            {
                new TestStructuresCalculation(),
                calculationWithOutput1,
                calculationWithIllustrationPoints1,
                new TestStructuresCalculation(),
                calculationWithOutput2,
                calculationWithIllustrationPoints2,
                new TestStructuresCalculation()
            };

            // Call
            IEnumerable <IObservable> affectedObjects = RiskeerCommonDataSynchronizationService.ClearStructuresCalculationIllustrationPoints(calculations);

            // Assert
            CollectionAssert.AreEquivalent(new[]
            {
                calculationWithIllustrationPoints1,
                calculationWithIllustrationPoints2
            }, affectedObjects);

            TestStructuresCalculation[] calculationsWithOutput =
            {
                calculationWithOutput1,
                calculationWithIllustrationPoints1,
                calculationWithOutput2,
                calculationWithIllustrationPoints2
            };

            Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput));
            Assert.IsTrue(calculationsWithOutput.All(calc => !calc.Output.HasGeneralResult));

            AssertStructuresOutput(originalOutput1, calculationWithOutput1.Output);
            AssertStructuresOutput(originalOutput2, calculationWithOutput2.Output);

            AssertStructuresOutput(originalOutputWithIllustrationPoints1, calculationWithIllustrationPoints1.Output);
            AssertStructuresOutput(originalOutputWithIllustrationPoints2, calculationWithIllustrationPoints2.Output);
        }