public void Calculate_CancelCalculationWithValidInput_CancelsCalculator()
        {
            // Setup
            var          waterLevel        = (RoundedDouble)4.2;
            var          a                 = (RoundedDouble)1.0;
            var          b                 = (RoundedDouble)0.8;
            var          c                 = (RoundedDouble)0.4;
            const double targetProbability = 0.2;
            var          input             = new WaveConditionsInput
            {
                HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                ForeshoreProfile          = new TestForeshoreProfile(),
                UpperBoundaryRevetment    = waterLevel,
                LowerBoundaryRevetment    = (RoundedDouble)3
            };
            var calculator        = new TestWaveConditionsCosineCalculator();
            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.Stub <IHydraRingCalculatorFactory>();

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

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

                // Call
                service.PublicCalculate(a,
                                        b,
                                        c,
                                        targetProbability,
                                        input,
                                        waterLevel,
                                        GetValidHydraulicBoundaryDatabase());

                // Assert
                Assert.IsTrue(calculator.IsCanceled);
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_OneOutOfThreeCalculationsFails_ReturnsOutputsAndLogError(bool endInFailure,
                                                                                       string lastErrorFileContent,
                                                                                       string detailedReport)
        {
            // Setup
            var calculatorThatFails = new TestWaveConditionsCosineCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };
            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculatorThatFails);
            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(new TestWaveConditionsCosineCalculator())
            .Repeat
            .Twice();
            mockRepository.ReplayAll();

            var          waterLevelUpperBoundary = new RoundedDouble(2, 4.00);
            var          waterLevelLowerBoundary = new RoundedDouble(2, 3.00);
            var          waterLevel        = (RoundedDouble)4.2;
            var          a                 = (RoundedDouble)1.0;
            var          b                 = (RoundedDouble)0.8;
            var          c                 = (RoundedDouble)0.4;
            const double targetProbability = 0.2;
            var          input             = new WaveConditionsInput
            {
                HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                ForeshoreProfile          = new TestForeshoreProfile(),
                UpperBoundaryRevetment    = waterLevelUpperBoundary,
                LowerBoundaryRevetment    = waterLevelLowerBoundary
            };

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestWaveConditionsCalculationService();

                // Call
                void Call() => service.PublicCalculate(a, b, c, targetProbability, input, waterLevel, GetValidHydraulicBoundaryDatabase());

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

                    var waterLevelMiddle = new RoundedDouble(2, 3.50);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundary}' is gestart.", msgs[0]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelUpperBoundary}'. {detailedReport}", msgs[1]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[2]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundary}' is beëindigd.", msgs[3]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddle}' is gestart.", msgs[4]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[5]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddle}' is beëindigd.", msgs[6]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundary}' is gestart.", msgs[7]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[8]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundary}' is beëindigd.", msgs[9]);
                });

                WaveConditionsOutput[] waveConditionsOutputs = service.Outputs.ToArray();
                Assert.AreEqual(3, waveConditionsOutputs.Length);

                WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevelUpperBoundary,
                                                                  targetProbability,
                                                                  waveConditionsOutputs[0]);
            }

            mockRepository.VerifyAll();
        }