Exemple #1
0
        public void Validate_ValidCalculationInvalidPreprocessorDirectory_LogsErrorAndReturnsFalse()
        {
            // Setup
            var mocks = new MockRepository();

            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(
                new TestCalculatableFailureMechanism(), mocks, validHydraulicBoundaryDatabaseFilePath);

            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.CanUsePreprocessor    = true;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.UsePreprocessor       = true;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.PreprocessorDirectory = "NonExistingPreprocessorDirectory";

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation();

            var isValid = true;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                Assert.AreEqual("De bestandsmap waar de preprocessor bestanden opslaat is ongeldig. De bestandsmap bestaat niet.", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
Exemple #2
0
        public void Validate_ValidCalculationValidHydraulicBoundaryDatabaseNoSettings_LogsErrorAndReturnsFalse()
        {
            // Setup
            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(new TestCalculatableFailureMechanism(),
                                                                                                           mocks,
                                                                                                           Path.Combine(testDataPath, "HRD nosettings.sqlite"));

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation();

            var isValid = false;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                StringAssert.StartsWith("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. " +
                                        "Fout bij het lezen van bestand", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
Exemple #3
0
        public void Calculate_ValidInputButIllustrationPointResultsOfIncorrectType_IllustrationPointsNotSetAndLogsWarning()
        {
            // Setup
            var mocks      = new MockRepository();
            var calculator = new TestStructuresCalculator <ExceedanceProbabilityCalculationInput>
            {
                OutputDirectory          = validHydraulicBoundaryDatabaseFilePath,
                IllustrationPointsResult = TestGeneralResult.CreateGeneralResultWithSubMechanismIllustrationPoints()
            };
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(null))
            .IgnoreArguments()
            .Return(calculator);

            const string performedCalculationMessage = "Calculation successful";
            var          messageProvider             = mocks.StrictMock <IStructuresCalculationMessageProvider>();

            messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validHydraulicBoundaryDatabaseFilePath)).Return(performedCalculationMessage);
            mocks.ReplayAll();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation            = hydraulicBoundaryLocation,
                    ShouldIllustrationPointsBeCalculated = true
                }
            };

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestStructuresCalculationService(messageProvider);

                // Call
                void Call() => service.Calculate(calculation, new GeneralTestInput(), CreateCalculationSettings());

                // Assert
                TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(Call, messages =>
                {
                    Tuple <string, Level, Exception>[] tupleArray = messages.ToArray();

                    string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray();
                    Assert.AreEqual(4, msgs.Length);

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);
                    Assert.AreEqual("Het uitlezen van illustratiepunten is mislukt.", msgs[1]);
                    Assert.AreEqual(performedCalculationMessage, msgs[2]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]);

                    Assert.IsInstanceOf <IllustrationPointConversionException>(tupleArray[1].Item3);
                });
                Assert.IsNotNull(calculation.Output);
                Assert.IsFalse(calculation.Output.HasGeneralResult);
            }

            mocks.VerifyAll();
        }
Exemple #4
0
        public void Calculate_CalculationRanErrorInSettingIllustrationPoints_IllustrationPointsNotSetAndLogsWarning()
        {
            // Setup
            var mocks      = new MockRepository();
            var calculator = new TestStructuresCalculator <ExceedanceProbabilityCalculationInput>
            {
                OutputDirectory          = validHydraulicBoundaryDatabaseFilePath,
                IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithDuplicateStochasts()
            };
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(null))
            .IgnoreArguments()
            .Return(calculator);

            const string performedCalculationMessage = "Calculation successful";
            var          messageProvider             = mocks.StrictMock <IStructuresCalculationMessageProvider>();

            messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validHydraulicBoundaryDatabaseFilePath)).Return(performedCalculationMessage);
            mocks.ReplayAll();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation            = hydraulicBoundaryLocation,
                    ShouldIllustrationPointsBeCalculated = true
                }
            };

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestStructuresCalculationService(messageProvider);

                // Call
                void Call() => service.Calculate(calculation, new GeneralTestInput(), CreateCalculationSettings());

                // Assert
                TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(Call, messages =>
                {
                    Tuple <string, Level, Exception>[] tupleArray = messages.ToArray();

                    string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray();
                    Assert.AreEqual(4, msgs.Length);

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);
                    Assert.AreEqual("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " +
                                    "Een of meerdere stochasten hebben dezelfde naam. Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]);
                    Assert.AreEqual(performedCalculationMessage, msgs[2]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]);
                });
                Assert.IsNotNull(calculation.Output);
                Assert.IsFalse(calculation.Output.HasGeneralResult);
            }

            mocks.VerifyAll();
        }
Exemple #5
0
        public void ShouldCalculate_Always_ReturnsExpectedValue(TestStructuresCalculation calculation,
                                                                bool expectedShouldCalculate)
        {
            // Call
            bool shouldCalculate = calculation.ShouldCalculate;

            // Assert
            Assert.AreEqual(expectedShouldCalculate, shouldCalculate);
        }
Exemple #6
0
        public void Calculate_ValidInputButIllustrationPointsNull_IllustrationPointsNotSetAndLogs()
        {
            // Setup
            const string parserMessage = "Parser error";
            var          mocks         = new MockRepository();
            var          calculator    = new TestStructuresCalculator <ExceedanceProbabilityCalculationInput>
            {
                OutputDirectory = validHydraulicBoundaryDatabaseFilePath,
                IllustrationPointsParserErrorMessage = parserMessage
            };
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(null))
            .IgnoreArguments()
            .Return(calculator);

            const string performedCalculationMessage = "Calculation successful";
            var          messageProvider             = mocks.StrictMock <IStructuresCalculationMessageProvider>();

            messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validHydraulicBoundaryDatabaseFilePath)).Return(performedCalculationMessage);
            mocks.ReplayAll();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation            = hydraulicBoundaryLocation,
                    ShouldIllustrationPointsBeCalculated = true
                }
            };

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestStructuresCalculationService(messageProvider);

                // Call
                void Call() => service.Calculate(calculation, new GeneralTestInput(), CreateCalculationSettings());

                // Assert
                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(4, msgs.Length);

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);
                    Assert.AreEqual(parserMessage, msgs[1]);
                    Assert.AreEqual(performedCalculationMessage, msgs[2]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]);
                });
                Assert.IsNotNull(calculation.Output);
                Assert.IsFalse(calculation.Output.HasGeneralResult);
            }

            mocks.VerifyAll();
        }
Exemple #7
0
        public void Property_Comments_ReturnsExpectedValues(string comments)
        {
            // Setup
            var calculation = new TestStructuresCalculation();

            // Call
            calculation.Comments.Body = comments;

            // Assert
            Assert.AreEqual(comments, calculation.Comments.Body);
        }
Exemple #8
0
        public void ClearIllustrationPoints_CalculationWithoutOutput_DoesNotThrow()
        {
            // Setup
            var calculation = new TestStructuresCalculation();

            // Call
            TestDelegate call = () => calculation.ClearIllustrationPoints();

            // Assert
            Assert.DoesNotThrow(call);
        }
Exemple #9
0
        public void Clone_NotAllPropertiesSet_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            TestStructuresCalculation original = CreateRandomCalculationWithoutOutput();

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

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones <TestStructuresInput, TestStructure>);
        }
        public void ClearIllustrationPoints_Always_ReturnsAffectedCalculations()
        {
            // Setup
            var calculationWithIllustrationPoints = new TestStructuresCalculation
            {
                Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint())
            };

            var calculationWithOutput = new TestStructuresCalculation
            {
                Output = new TestStructuresOutput()
            };

            TestStructuresCalculation[] calculations =
            {
                new TestStructuresCalculation(),
                calculationWithOutput,
                calculationWithIllustrationPoints
            };

            var mocks         = new MockRepository();
            var inquiryHelper = mocks.StrictMock <IInquiryHelper>();

            var calculationWithIllustrationPointsObserver = mocks.StrictMock <IObserver>();

            calculationWithIllustrationPoints.Attach(calculationWithIllustrationPointsObserver);

            var calculationWithoutIllustrationPointsObserver = mocks.StrictMock <IObserver>();

            calculationWithOutput.Attach(calculationWithoutIllustrationPointsObserver);
            mocks.ReplayAll();

            var handler = new ClearIllustrationPointsOfStructureCalculationCollectionChangeHandler(inquiryHelper, calculations);

            // Call
            IEnumerable <IObservable> affectedObjects = handler.ClearIllustrationPoints();

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                calculationWithIllustrationPoints
            }, affectedObjects);

            TestStructuresCalculation[] calculationsWithOutput =
            {
                calculationWithOutput,
                calculationWithIllustrationPoints
            };
            Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput));
            Assert.IsTrue(calculationsWithOutput.All(calc => !calc.Output.HasGeneralResult));

            mocks.VerifyAll();
        }
Exemple #11
0
        public void Validate_AssessmentSectionNull_ThrowArgumentNullException()
        {
            // Setup
            var calculation = new TestStructuresCalculation();

            // Call
            void Call() => TestStructuresCalculationService.Validate(calculation, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("assessmentSection", exception.ParamName);
        }
Exemple #12
0
        public void Clone_AllPropertiesSet_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            TestStructuresCalculation original = CreateRandomCalculationWithoutOutput();

            original.Output = CommonTestDataGenerator.GetRandomStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint());

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

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones <TestStructuresInput, TestStructure>);
        }
Exemple #13
0
        public void HasOutput_OutputSet_ReturnsTrue()
        {
            // Setup
            var calculation = new TestStructuresCalculation
            {
                Output = new TestStructuresOutput()
            };

            // Call
            bool calculationHasOutput = calculation.HasOutput;

            // Assert
            Assert.IsTrue(calculationHasOutput);
        }
Exemple #14
0
        public void HasOutput_OutputNull_ReturnsFalse()
        {
            // Setup
            var calculation = new TestStructuresCalculation
            {
                Output = null
            };

            // Call
            bool calculationHasOutput = calculation.HasOutput;

            // Assert
            Assert.IsFalse(calculationHasOutput);
        }
Exemple #15
0
        public void ClearOutput_Always_SetsOutputToNull()
        {
            // Setup
            var calculation = new TestStructuresCalculation
            {
                Output = new TestStructuresOutput()
            };

            // Call
            calculation.ClearOutput();

            // Assert
            Assert.IsNull(calculation.Output);
        }
Exemple #16
0
        public void Constructor_Default_ExpectedValues()
        {
            // Call
            var calculation = new TestStructuresCalculation();

            // Assert
            Assert.IsInstanceOf <CloneableObservable>(calculation);
            Assert.IsInstanceOf <IStructuresCalculation>(calculation);
            Assert.IsInstanceOf <ICalculation <TestStructuresInput> >(calculation);
            Assert.AreEqual("Nieuwe berekening", calculation.Name);
            Assert.IsNotNull(calculation.InputParameters);
            Assert.IsNull(calculation.Comments.Body);
            Assert.IsNull(calculation.Output);
        }
Exemple #17
0
        public void ToString_Always_ReturnName()
        {
            // Setup
            const string expectedName = "someTestName";
            var          calculation  = new TestStructuresCalculation
            {
                Name = expectedName
            };

            // Call
            string result = calculation.ToString();

            // Assert
            Assert.AreEqual(expectedName, result);
        }
Exemple #18
0
        private static TestStructuresCalculation CreateRandomCalculationWithoutOutput()
        {
            var calculation = new TestStructuresCalculation
            {
                Comments =
                {
                    Body = "Random body"
                },
                Name = "Random name"
            };

            CommonTestDataGenerator.SetRandomDataToStructuresInput(calculation.InputParameters);

            return(calculation);
        }
        public void Constructor_WithArguments_ExpectedValues()
        {
            // Setup
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation();

            // Call
            var handler = new ClearIllustrationPointsOfStructuresCalculationHandler(inquiryHelper, calculation);

            // Assert
            Assert.IsInstanceOf <ClearIllustrationPointsOfCalculationChangeHandlerBase <IStructuresCalculation> >(handler);
            mocks.VerifyAll();
        }
Exemple #20
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);
        }
Exemple #21
0
        public void Validate_ValidInputWithUseProcessorTrue_ReturnsTrue()
        {
            // Setup
            var mocks = new MockRepository();

            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(
                new TestCalculatableFailureMechanism(), mocks, validHydraulicBoundaryDatabaseFilePath);

            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.CanUsePreprocessor    = true;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.UsePreprocessor       = true;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.PreprocessorDirectory = TestHelper.GetScratchPadPath();

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    Structure                 = new TestStructure(),
                    HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                    IsValid                   = true
                }
            };

            var isValid = false;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(2, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]);
            });
            Assert.IsTrue(isValid);

            mocks.VerifyAll();
        }
Exemple #22
0
        public void Calculate_CancelCalculationWithValidInput_CancelsCalculatorAndHasNullOutput()
        {
            // Setup
            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = hydraulicBoundaryLocation
                }
            };

            var mocks             = new MockRepository();
            var calculator        = new TestStructuresCalculator <ExceedanceProbabilityCalculationInput>();
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(null))
            .IgnoreArguments()
            .Return(calculator);

            var messageProvider = mocks.Stub <IStructuresCalculationMessageProvider>();

            mocks.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestStructuresCalculationService(messageProvider);
                calculator.CalculationFinishedHandler += (s, e) => service.Cancel();

                // Call
                service.Calculate(calculation, new GeneralTestInput(), CreateCalculationSettings());

                // Assert
                Assert.IsNull(calculation.Output);
                Assert.IsTrue(calculator.IsCanceled);
            }

            mocks.VerifyAll();
        }
Exemple #23
0
        public void Validate_InputInvalidAccordingToValidationRule_LogErrorAndReturnFalse()
        {
            // Setup
            var failureMechanism = new TestCalculatableFailureMechanism();

            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(
                failureMechanism, mocks, validHydraulicBoundaryDatabaseFilePath);

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    Structure                 = new TestStructure(),
                    HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                    IsValid                   = false
                }
            };

            var isValid = false;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                Assert.AreEqual("Error message", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
        public void ClearIllustrationPoints_WithVariousCalculationConfigurations_ClearsIllustrationPointsAndReturnsExpectedResult(
            TestStructuresCalculation calculation, bool expectedResult)
        {
            // Setup
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.StrictMock <IInquiryHelper>();

            mocks.ReplayAll();

            var handler = new ClearIllustrationPointsOfStructuresCalculationHandler(inquiryHelper, calculation);

            bool hasOutput = calculation.HasOutput;

            // Call
            bool isCalculationAffected = handler.ClearIllustrationPoints();

            // Assert
            Assert.AreEqual(expectedResult, isCalculationAffected);
            Assert.AreEqual(hasOutput, calculation.HasOutput);

            Assert.IsNull(calculation.Output?.GeneralResult);
            mocks.VerifyAll();
        }
        private static IEnumerable <TestCaseData> GetStructureCalculationCollections()
        {
            var calculationWithIllustrationPoints = new TestStructuresCalculation
            {
                Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint())
            };

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

            yield return(new TestCaseData(new[]
            {
                calculationWithOutput1,
                calculationWithIllustrationPoints,
                calculationWithOutput2
            }, true));

            yield return(new TestCaseData(new[]
            {
                calculationWithOutput1,
                calculationWithOutput2
            }, false));

            yield return(new TestCaseData(new[]
            {
                new TestStructuresCalculation()
            }, false));

            yield return(new TestCaseData(Enumerable.Empty <TestStructuresCalculation>(), false));
        }
Exemple #26
0
        public void Validate_CalculationInputWithoutHydraulicBoundaryLocationValidHydraulicBoundaryDatabase_LogsErrorAndReturnsFalse()
        {
            // Setup
            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(new TestCalculatableFailureMechanism(),
                                                                                                           mocks,
                                                                                                           validHydraulicBoundaryDatabaseFilePath);

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    Structure = new TestStructure()
                }
            };

            var isValid = false;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                Assert.AreEqual("Er is geen hydraulische belastingenlocatie geselecteerd.", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
Exemple #27
0
        public void Calculate_CalculationFailed_ThrowsHydraRingCalculationExceptionAndLogError(bool endInFailure,
                                                                                               string lastErrorFileContent,
                                                                                               string detailedReport)
        {
            // Setup
            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = hydraulicBoundaryLocation
                }
            };

            var mocks      = new MockRepository();
            var calculator = new TestStructuresCalculator <ExceedanceProbabilityCalculationInput>
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(null))
            .IgnoreArguments()
            .Return(calculator);

            const string calculationFailedMessage    = "Calculation failed";
            const string calculationPerformedMessage = "Calculation performed";
            var          messageProvider             = mocks.StrictMock <IStructuresCalculationMessageProvider>();

            if (endInFailure && string.IsNullOrEmpty(lastErrorFileContent))
            {
                messageProvider.Expect(mp => mp.GetCalculationFailedMessage(calculation.Name)).Return(calculationFailedMessage);
            }
            else
            {
                messageProvider.Expect(mp => mp.GetCalculationFailedWithErrorReportMessage(calculation.Name,
                                                                                           endInFailure && string.IsNullOrEmpty(lastErrorFileContent)
                                                                                               ? calculator.HydraRingCalculationException.Message
                                                                                               : lastErrorFileContent
                                                                                           )).Return(calculationFailedMessage);
            }

            messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(calculator.OutputDirectory)).Return(calculationPerformedMessage);
            mocks.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var exceptionThrown = false;
                var structuresCalculationService = new TestStructuresCalculationService(messageProvider);

                // Call
                void Call()
                {
                    try
                    {
                        structuresCalculationService.Calculate(calculation, new GeneralTestInput(), CreateCalculationSettings());
                    }
                    catch (HydraRingCalculationException)
                    {
                        exceptionThrown = true;
                    }
                }

                // Assert
                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(4, msgs.Length);
                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);
                    Assert.AreEqual(calculationFailedMessage, msgs[1]);
                    Assert.AreEqual(calculationPerformedMessage, msgs[2]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]);
                });
                Assert.IsTrue(exceptionThrown);
                Assert.IsNull(calculation.Output);
            }

            mocks.VerifyAll();
        }
        public void HasIllustrationPoints_WithStructuresCalculation_ReturnsExpectedResult(TestStructuresCalculation calculation,
                                                                                          bool expectedHasIllustrationPoints)
        {
            // Call
            bool hasIllustrationPoints = IllustrationPointsHelper.HasIllustrationPoints(calculation);

            // Assert
            Assert.AreEqual(expectedHasIllustrationPoints, hasIllustrationPoints);
        }
Exemple #29
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);
        }
Exemple #30
0
        public void Calculate_ValidInput_InputPropertiesCorrectlySentToCalculator(bool usePreprocessor)
        {
            // Setup
            string preprocessorDirectory = usePreprocessor
                                               ? validPreprocessorDirectory
                                               : string.Empty;

            var calculationSettings = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath,
                                                                               validHlcdFilePath,
                                                                               false,
                                                                               preprocessorDirectory);

            var mocks      = new MockRepository();
            var calculator = new TestStructuresCalculator <ExceedanceProbabilityCalculationInput>
            {
                OutputDirectory = validHydraulicBoundaryDatabaseFilePath
            };
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(
                                         Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    calculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(calculator);

            const string performedCalculationMessage = "Calculation successful";
            var          messageProvider             = mocks.StrictMock <IStructuresCalculationMessageProvider>();

            messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validHydraulicBoundaryDatabaseFilePath)).Return(performedCalculationMessage);
            mocks.ReplayAll();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new TestStructuresCalculation
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = hydraulicBoundaryLocation
                }
            };

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestStructuresCalculationService(messageProvider);

                // Call
                service.Calculate(calculation, new GeneralTestInput(), calculationSettings);

                // Assert
                ExceedanceProbabilityCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray();
                Assert.AreEqual(1, calculationInputs.Length);

                var expectedInput = new TestExceedanceProbabilityCalculationInput(hydraulicBoundaryLocation.Id);
                ExceedanceProbabilityCalculationInput actualInput = calculationInputs[0];
                HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput);
                Assert.IsFalse(calculator.IsCanceled);
            }

            mocks.VerifyAll();
        }