public void Constructor_NoGeneralResult_PropertiesHaveExpectedAttributesValues()
        {
            // Setup
            var structuresOutput = new StructuresOutput(0, null);

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

            // Assert
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            Assert.AreEqual(2, dynamicProperties.Count);

            PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty,
                                                                            resultCategoryName,
                                                                            "Faalkans [1/jaar]",
                                                                            "De kans dat het faalmechanisme optreedt voor deze berekening.",
                                                                            true);

            PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty,
                                                                            resultCategoryName,
                                                                            "Betrouwbaarheidsindex faalkans [-]",
                                                                            "De betrouwbaarheidsindex van de faalkans voor deze berekening.",
                                                                            true);
        }
Beispiel #2
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);
            }
        }
 private static void SetGeneralResult(StructuresOutput structuresOutput, IHasGeneralResultFaultTreeIllustrationPointEntity outputEntity)
 {
     if (structuresOutput.HasGeneralResult)
     {
         outputEntity.GeneralResultFaultTreeIllustrationPointEntity =
             structuresOutput.GeneralResult
             .CreateGeneralResultFaultTreeIllustrationPointEntity();
     }
 }
Beispiel #4
0
        public void Clone_AllPropertiesSet_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            StructuresOutput original = CommonTestDataGenerator.GetRandomStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint());

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
Beispiel #5
0
        public void Clone_NotAllPropertiesSet_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            StructuresOutput original = CommonTestDataGenerator.GetRandomStructuresOutput(null);

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var structuresOutput = new StructuresOutput(0, null);

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

            // Assert
            Assert.IsInstanceOf <ObjectProperties <StructuresOutput> >(properties);
            Assert.AreSame(structuresOutput, properties.Data);
        }
        public void IllustrationPoints_WithoutGeneralResult_ReturnsEmptyTopLevelFaultTreeIllustrationPointPropertiesArray()
        {
            // Setup
            var structuresOutput = new StructuresOutput(0, null);
            var properties       = new StructuresOutputProperties(structuresOutput);

            // Call
            TopLevelFaultTreeIllustrationPointProperties[] illustrationPoints = properties.IllustrationPoints;

            // Assert
            Assert.IsEmpty(illustrationPoints);
        }
Beispiel #8
0
        public void Create_CalculationWithNaNOutput_ReturnEntityWithNullOutput()
        {
            // Setup
            var output = new StructuresOutput(
                double.NaN, null);

            // Call
            var entity = output.Create <TestStructureOutputEntity>();

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNull(entity.Reliability);
            Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity);
        }
Beispiel #9
0
        public void Create_CalculationWithOutputAndGeneralResult_ReturnEntityWithOutputAndGeneralResult()
        {
            // Setup
            var random = new Random(567);
            var output = new StructuresOutput(random.NextDouble(),
                                              new TestGeneralResultFaultTreeIllustrationPoint());

            // Call
            var entity = output.Create <TestStructureOutputEntity>();

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(output.Reliability, entity.Reliability);
            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, entity.GeneralResultFaultTreeIllustrationPointEntity);
        }
        private static void ReadOutput(StructuresCalculation <HeightStructuresInput> calculation,
                                       HeightStructuresCalculationEntity entity)
        {
            HeightStructuresOutputEntity outputEntity = entity.HeightStructuresOutputEntities.SingleOrDefault();

            if (outputEntity == null)
            {
                return;
            }

            var output = new StructuresOutput(outputEntity.Reliability.ToNullAsNaN(),
                                              outputEntity.GeneralResultFaultTreeIllustrationPointEntity?.Read());

            calculation.Output = output;
        }
Beispiel #11
0
        public void ClearIllustrationPoints_OutputWithoutGeneralResult_OtherOutputIsNotAffected()
        {
            // Setup
            var    random      = new Random(39);
            double reliability = random.NextDouble();

            var structuresOutput = new StructuresOutput(reliability, null);

            // Call
            structuresOutput.ClearIllustrationPoints();

            // Assert
            Assert.AreEqual(reliability, structuresOutput.Reliability);
            Assert.IsFalse(structuresOutput.HasGeneralResult);
            Assert.IsNull(structuresOutput.GeneralResult);
        }
Beispiel #12
0
        public void ClearIllustrationPoints_OutputWithGeneralResult_ClearsGeneralResultAndOtherOutputIsNotAffected()
        {
            // Setup
            var    random      = new Random(39);
            double reliability = random.NextDouble();
            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = new TestGeneralResultFaultTreeIllustrationPoint();

            var structuresOutput = new StructuresOutput(reliability, generalResult);

            // Call
            structuresOutput.ClearIllustrationPoints();

            // Assert
            Assert.AreEqual(reliability, structuresOutput.Reliability);
            Assert.IsFalse(structuresOutput.HasGeneralResult);
            Assert.IsNull(structuresOutput.GeneralResult);
        }
Beispiel #13
0
        public void Constructor_ExpectedValues(bool withIllustrationPoints)
        {
            // Setup
            var    random      = new Random(39);
            double reliability = random.NextDouble();
            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = withIllustrationPoints
                                                                                  ? new TestGeneralResultFaultTreeIllustrationPoint()
                                                                                  : null;

            // Call
            var structuresOutput = new StructuresOutput(reliability, generalResult);

            // Assert
            Assert.IsInstanceOf <ICloneable>(structuresOutput);
            Assert.AreEqual(reliability, structuresOutput.Reliability);
            Assert.AreEqual(withIllustrationPoints, structuresOutput.HasGeneralResult);
            Assert.AreSame(generalResult, structuresOutput.GeneralResult);
        }
        /// <summary>
        /// Creates a <see cref="TOutputEntity"/> based on the information of the
        /// <paramref name="structuresOutput"/>.
        /// </summary>
        /// <param name="structuresOutput">The structures output to create a database entity for.</param>
        /// <returns>A new <see cref="TOutputEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="structuresOutput"/>
        /// is <c>null</c>.</exception>
        public static TOutputEntity Create <TOutputEntity>(this StructuresOutput structuresOutput)
            where TOutputEntity : IStructuresOutputEntity,
        IHasGeneralResultFaultTreeIllustrationPointEntity,
        new()
        {
            if (structuresOutput == null)
            {
                throw new ArgumentNullException(nameof(structuresOutput));
            }

            var outputEntity = new TOutputEntity
            {
                Reliability = structuresOutput.Reliability.ToNaNAsNull()
            };

            SetGeneralResult(structuresOutput, outputEntity);

            return(outputEntity);
        }
        public void Read_ValidEntityWithOutputEntity_ReturnCalculationWithOutput()
        {
            // Setup
            var entity = new StabilityPointStructuresCalculationEntity
            {
                StabilityPointStructuresOutputEntities =
                {
                    new StabilityPointStructuresOutputEntity()
                },
                ScenarioContribution = 0
            };

            var collector = new ReadConversionCollector();

            // Call
            StructuresCalculationScenario <StabilityPointStructuresInput> calculation = entity.Read(collector);

            // Assert
            StructuresOutput calculationOutput = calculation.Output;

            Assert.IsNaN(calculationOutput.Reliability);
            Assert.IsFalse(calculationOutput.HasGeneralResult);
        }
Beispiel #16
0
 private static void AssertStructuresOutput(StructuresOutput expectedOutput, StructuresOutput actualOutput)
 {
     Assert.AreEqual(expectedOutput.Reliability, actualOutput.Reliability);
 }
        public void Constructor_HasGeneralResult_PropertiesHaveExpectedAttributesValues()
        {
            // Setup
            var generalResult    = new TestGeneralResultFaultTreeIllustrationPoint();
            var structuresOutput = new StructuresOutput(0, generalResult);

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

            // Assert
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            Assert.AreEqual(6, dynamicProperties.Count);

            PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty,
                                                                            resultCategoryName,
                                                                            "Faalkans [1/jaar]",
                                                                            "De kans dat het faalmechanisme optreedt voor deze berekening.",
                                                                            true);

            PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty,
                                                                            resultCategoryName,
                                                                            "Betrouwbaarheidsindex faalkans [-]",
                                                                            "De betrouwbaarheidsindex van de faalkans voor deze berekening.",
                                                                            true);

            PropertyDescriptor windDirectionProperty = dynamicProperties[windDirectionPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(windDirectionProperty,
                                                                            illustrationPointsCategoryName,
                                                                            "Maatgevende windrichting",
                                                                            "De windrichting waarvoor de berekende betrouwbaarheidsindex het laagst is.",
                                                                            true);

            PropertyDescriptor alphaValuesProperty = dynamicProperties[alphaValuesPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(alphaValuesProperty,
                                                                            illustrationPointsCategoryName,
                                                                            "Invloedscoëfficiënten [-]",
                                                                            "Berekende invloedscoëfficiënten voor alle beschouwde stochasten.",
                                                                            true);

            PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(durationsProperty,
                                                                            illustrationPointsCategoryName,
                                                                            "Tijdsduren [uur]",
                                                                            "Tijdsduren waarop de stochasten betrekking hebben.",
                                                                            true);

            PropertyDescriptor illustrationPointProperty = dynamicProperties[illustrationPointsPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(illustrationPointProperty,
                                                                            illustrationPointsCategoryName,
                                                                            "Illustratiepunten",
                                                                            "De lijst van illustratiepunten voor de berekening.",
                                                                            true);
        }
Beispiel #18
0
 /// <summary>
 /// Method that asserts whether <paramref name="original"/> and <paramref name="clone"/>
 /// are clones.
 /// </summary>
 /// <param name="original">The original object.</param>
 /// <param name="clone">The cloned object.</param>
 /// <exception cref="AssertionException">Thrown when <paramref name="original"/> and
 /// <paramref name="clone"/> are not clones.</exception>
 public static void AreClones(StructuresOutput original, StructuresOutput clone)
 {
     Assert.AreEqual(original.Reliability, clone.Reliability);
     CoreCloneAssert.AreObjectClones(original.GeneralResult, clone.GeneralResult, AreClones);
 }