Example #1
0
        public void Run_InvalidPreprocessorDirectory_PerformValidationAndLogStartAndEndAndError()
        {
            // Setup
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var settings = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath,
                                                                    validHlcdFilePath,
                                                                    false,
                                                                    "NonExistingPreprocessorDirectory");
            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(new TestDuneLocation(locationName)),
                                                               settings,
                                                               0.01,
                                                               calculationIdentifier);

            // Call
            void Call() => activity.Run();

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(4, msgs.Length);
                Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName}' ({calculationIdentifier}) is gestart.", msgs[0]);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                Assert.AreEqual("De bestandsmap waar de preprocessor bestanden opslaat is ongeldig. De bestandsmap bestaat niet.", msgs[2]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]);
            });
            Assert.AreEqual(ActivityState.Failed, activity.State);
        }
Example #2
0
        public void Run_InvalidHydraulicBoundaryDatabase_PerformValidationAndLogStartAndEndAndError()
        {
            // Setup
            string invalidFilePath = Path.Combine(testDataPath, "notexisting.sqlite");

            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var settings = new HydraulicBoundaryCalculationSettings(invalidFilePath,
                                                                    validHlcdFilePath,
                                                                    false,
                                                                    string.Empty);
            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(new TestDuneLocation(locationName)),
                                                               settings,
                                                               0.01,
                                                               calculationIdentifier);

            // Call
            void Call() => activity.Run();

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(4, msgs.Length);
                Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName}' ({calculationIdentifier}) is gestart.", msgs[0]);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                StringAssert.StartsWith("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. Fout bij het lezen van bestand", msgs[2]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]);
            });
            Assert.AreEqual(ActivityState.Failed, activity.State);
        }
Example #3
0
        public void Run_ErrorInCalculation_ActivityStateSetToFailed(bool endInFailure, string lastErrorFileContent)
        {
            // Setup
            const string locationName = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(new TestDuneLocation(locationName)),
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               "1/100");

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                activity.Run();

                // Assert
                Assert.AreEqual(ActivityState.Failed, activity.State);
            }

            mockRepository.VerifyAll();
        }
Example #4
0
        public void Run_ValidInput_PerformValidationAndCalculationAndLogStartAndEnd()
        {
            // Setup
            const double targetProbability     = 0.01;
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                Converged = true
            };

            HydraulicBoundaryCalculationSettings calculationSettings = CreateCalculationSettings();

            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            var duneLocation = new TestDuneLocation(locationName);

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(duneLocation),
                                                               calculationSettings,
                                                               targetProbability,
                                                               calculationIdentifier);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                void Call() => activity.Run();

                // Assert
                TestHelper.AssertLogMessages(Call, m =>
                {
                    string[] messages = m.ToArray();
                    Assert.AreEqual(6, messages.Length);
                    Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName}' ({calculationIdentifier}) is gestart.", messages[0]);
                    CalculationServiceTestHelper.AssertValidationStartMessage(messages[1]);
                    CalculationServiceTestHelper.AssertValidationEndMessage(messages[2]);
                    CalculationServiceTestHelper.AssertCalculationStartMessage(messages[3]);
                    StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", messages[4]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(messages[5]);
                });
            }

            Assert.AreEqual(ActivityState.Executed, activity.State);
            mockRepository.VerifyAll();
        }
Example #5
0
        public void Run_VariousValidInputs_PerformsCalculationWithCorrectInput(bool usePreprocessor)
        {
            // Setup
            const double targetProbability     = 0.01;
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                Converged = true
            };

            string preprocessorDirectory = usePreprocessor ? validPreprocessorDirectory : string.Empty;
            var    calculationSettings   = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath,
                                                                                    validHlcdFilePath,
                                                                                    false,
                                                                                    preprocessorDirectory);

            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

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

            var duneLocation = new TestDuneLocation(locationName);

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(duneLocation),
                                                               calculationSettings,
                                                               targetProbability,
                                                               calculationIdentifier);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                activity.Run();

                // Assert
                DunesBoundaryConditionsCalculationInput calculationInput = calculator.ReceivedInputs.Single();
                Assert.AreEqual(duneLocation.Id, calculationInput.HydraulicBoundaryLocationId);
                Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(targetProbability), calculationInput.Beta);
            }

            mockRepository.VerifyAll();
        }
Example #6
0
        public void Run_ValidCalculationAndRun_SetsOutput()
        {
            // Setup
            var    random                   = new Random(123);
            double expectedWaterLevel       = random.NextDouble();
            double expectedWaveHeight       = random.NextDouble();
            double expectedWavePeriod       = random.NextDouble();
            double expectedReliabilityIndex = random.NextDouble();

            var duneLocationCalculation = new DuneLocationCalculation(new TestDuneLocation());
            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                WaterLevel       = expectedWaterLevel,
                WaveHeight       = expectedWaveHeight,
                WavePeriod       = expectedWavePeriod,
                ReliabilityIndex = expectedReliabilityIndex,
                Converged        = true
            };

            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            var activity = new DuneLocationCalculationActivity(duneLocationCalculation,
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               "1/100");

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                activity.Run();
            }

            // Assert
            DuneLocationCalculationOutput actualCalculationOutput = duneLocationCalculation.Output;

            Assert.IsNotNull(actualCalculationOutput);
            Assert.AreEqual(expectedWaterLevel, actualCalculationOutput.WaterLevel, actualCalculationOutput.WaterLevel.GetAccuracy());
            Assert.AreEqual(expectedWaveHeight, actualCalculationOutput.WaveHeight, actualCalculationOutput.WaveHeight.GetAccuracy());
            Assert.AreEqual(expectedWavePeriod, actualCalculationOutput.WavePeriod, actualCalculationOutput.WavePeriod.GetAccuracy());
            Assert.AreEqual(expectedReliabilityIndex, actualCalculationOutput.CalculatedReliability, actualCalculationOutput.CalculatedReliability.GetAccuracy());
            Assert.AreEqual(CalculationConvergence.CalculatedConverged, actualCalculationOutput.CalculationConvergence);
            mockRepository.VerifyAll();
        }
Example #7
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            // Call
            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(new TestDuneLocation(locationName)),
                                                               CreateCalculationSettings(),
                                                               0.001,
                                                               calculationIdentifier);

            // Assert
            Assert.IsInstanceOf <CalculatableActivity>(activity);
            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName}' ({calculationIdentifier})", activity.Description);
            Assert.IsNull(activity.ProgressText);
            Assert.AreEqual(ActivityState.None, activity.State);
        }
Example #8
0
        public void Run_CalculationResultingInNoConvergence_LogWarningNoConvergence()
        {
            // Setup
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                Converged = false
            };

            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            var duneLocationCalculation = new DuneLocationCalculation(new TestDuneLocation(locationName));

            var activity = new DuneLocationCalculationActivity(duneLocationCalculation,
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               calculationIdentifier);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                void Call() => activity.Run();

                // Assert
                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(7, msgs.Length);
                    Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{locationName}' ({calculationIdentifier}) is niet geconvergeerd.", msgs[4]);
                });
                Assert.AreEqual(CalculationConvergence.CalculatedNotConverged, duneLocationCalculation.Output.CalculationConvergence);
            }

            mockRepository.VerifyAll();
        }
Example #9
0
        public void Run_InvalidCalculation_LogsError(bool endInFailure, string lastErrorFileContent)
        {
            // Setup
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(new TestDuneLocation(locationName)),
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               calculationIdentifier);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                void Call() => activity.Run();

                // Assert
                string expectedFailureMessage = string.IsNullOrEmpty(lastErrorFileContent)
                                                    ? $"Er is een fout opgetreden tijdens de hydraulische belastingenberekening '{locationName}' ({calculationIdentifier}). Er is geen foutrapport beschikbaar."
                                                    : $"Er is een fout opgetreden tijdens de hydraulische belastingenberekening '{locationName}' ({calculationIdentifier}). Bekijk het foutrapport door op details te klikken.{Environment.NewLine}{lastErrorFileContent}";

                TestHelper.AssertLogMessageIsGenerated(Call, expectedFailureMessage, 7);
            }

            mockRepository.VerifyAll();
        }