public void CalculateDesignWaterLevels_ValidPathEmptyCalculationList_NoLog()
        {
            // Setup
            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks);

            mocks.ReplayAll();

            assessmentSection.HydraulicBoundaryDatabase.FilePath = validFilePath;
            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            DialogBoxHandler = (name, wnd) =>
            {
                // Expect an activity dialog which is automatically closed
            };

            using (var viewParent = new TestViewParentForm())
            {
                var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent);

                // Call
                void Call() => guiService.CalculateDesignWaterLevels(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), assessmentSection, 0.01, "1/100");

                // Assert
                TestHelper.AssertLogMessagesCount(Call, 0);
            }

            mocks.VerifyAll();
        }
        public void CalculateDesignWaterLevels_ValidPathOneCalculation_LogsMessages()
        {
            // Setup
            const string hydraulicLocationName = "name";
            const string calculationIdentifier = "1/100";

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

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

            calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(new TestDesignWaterLevelCalculator());
            mocks.ReplayAll();

            assessmentSection.HydraulicBoundaryDatabase.FilePath = validFilePath;
            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            DialogBoxHandler = (name, wnd) =>
            {
                // Expect an activity dialog which is automatically closed
            };

            using (var viewParent = new TestViewParentForm())
                using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                {
                    var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent);

                    // Call
                    void Call() =>
                    guiService.CalculateDesignWaterLevels(new[]
                    {
                        new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation(hydraulicLocationName))
                    }, assessmentSection, 0.01, calculationIdentifier);

                    // Assert
                    TestHelper.AssertLogMessages(Call, messages =>
                    {
                        string[] msgs = messages.ToArray();
                        Assert.AreEqual(8, msgs.Length);
                        string activityDescription = GetDesignWaterLevelCalculationActivityDescription(hydraulicLocationName, calculationIdentifier);
                        Assert.AreEqual($"{activityDescription} is gestart.", msgs[0]);
                        CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                        CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
                        CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]);
                        Assert.AreEqual($"Waterstand berekening voor locatie 'name' ({calculationIdentifier}) is niet geconvergeerd.", msgs[4]);
                        StringAssert.StartsWith("Waterstand berekening is uitgevoerd op de tijdelijke locatie", msgs[5]);
                        CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[6]);
                        Assert.AreEqual($"{activityDescription} is gelukt.", msgs[7]);
                    });
                }

            mocks.VerifyAll();
        }
        public void CalculateDesignWaterLevels_HydraulicDatabaseDoesNotExist_LogsError()
        {
            // Setup
            var mocks      = new MockRepository();
            var viewParent = mocks.Stub <IViewParent>();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks);

            mocks.ReplayAll();

            assessmentSection.HydraulicBoundaryDatabase.FilePath = "Does not exist";
            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent);

            // Call
            void Call() => guiService.CalculateDesignWaterLevels(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), assessmentSection, 0.01, "1/100");

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(1, msgs.Length);
                StringAssert.StartsWith("Berekeningen konden niet worden gestart. ", msgs.First());
            });

            mocks.VerifyAll();
        }
        public void CalculateDesignWaterLevels_AssessmentSectionNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks      = new MockRepository();
            var viewParent = mocks.Stub <IViewParent>();

            mocks.ReplayAll();

            var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent);

            // Call
            void Call() => guiService.CalculateDesignWaterLevels(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), null, 0.01, "1/100");

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

            Assert.AreEqual("assessmentSection", exception.ParamName);
            mocks.VerifyAll();
        }