public void CalculateForSelectedButton_OneCalculationSelected_CalculateForSelectedCalculationAndKeepOriginalSelection()
        {
            // Setup
            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = hydraulicBoundaryDatabaseFilePath
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase);

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.Id).Return("1");
            assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase);
            assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
            assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();

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

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(new TestDunesBoundaryConditionsCalculator());
            mocks.ReplayAll();

            IObservableEnumerable <DuneLocationCalculation> calculations = GenerateDuneLocationCalculations();
            var failureMechanism = new DuneErosionFailureMechanism();

            using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations,
                                                                                        failureMechanism,
                                                                                        assessmentSection))
            {
                var    dataGridView            = (DataGridView)view.Controls.Find("dataGridView", true)[0];
                object originalDataSource      = dataGridView.DataSource;
                DataGridViewRowCollection rows = dataGridView.Rows;
                rows[0].Cells[calculateColumnIndex].Value = true;

                calculations.Attach(calculationsObserver);

                var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);

                using (var viewParent = new TestViewParentForm())
                    using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                    {
                        view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);

                        // Call
                        buttonTester.Click();

                        // Assert
                        Assert.AreSame(originalDataSource, dataGridView.DataSource);

                        Assert.IsTrue((bool)rows[0].Cells[calculateColumnIndex].Value);
                        Assert.IsFalse((bool)rows[1].Cells[calculateColumnIndex].Value);
                    }
            }
        }
        public void CalculateForSelectedButton_OneCalculationSelected_CalculateForSelectedCalculationAndLogsMessages()
        {
            // Setup
            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = hydraulicBoundaryDatabaseFilePath
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase);

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.Id).Return("1");
            assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase);
            assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
            assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();

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

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(new TestDunesBoundaryConditionsCalculator());
            mocks.ReplayAll();

            IObservableEnumerable <DuneLocationCalculation> calculations = GenerateDuneLocationCalculations();
            var failureMechanism = new DuneErosionFailureMechanism();

            using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations,
                                                                                        failureMechanism,
                                                                                        assessmentSection))
            {
                var dataGridView = (DataGridView)view.Controls.Find("dataGridView", true)[0];
                DataGridViewRowCollection rows = dataGridView.Rows;
                rows[0].Cells[calculateColumnIndex].Value = true;

                calculations.Attach(calculationsObserver);

                var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);

                using (var viewParent = new TestViewParentForm())
                    using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                    {
                        view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);

                        // Call
                        void Call() => buttonTester.Click();

                        // Assert
                        string expectedDuneLocationName = calculations.ElementAt(0).DuneLocation.Name;

                        TestHelper.AssertLogMessages(Call,
                                                     messages =>
                        {
                            List <string> messageList = messages.ToList();

                            // Assert
                            Assert.AreEqual(8, messageList.Count);
                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gestart.", messageList[0]);
                            CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]);
                            CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]);
                            Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{expectedDuneLocationName}' (1/100) is niet geconvergeerd.", messageList[4]);
                            StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", messageList[5]);
                            CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[6]);
                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gelukt.", messageList[7]);
                        });
                    }
            }
        }