Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelLocationsViewInfoTest.cs =================================================================== diff -u -r425a50160d826226ef47b6c4de8b56811c1984a7 -rfc3b0b96c11a1e048daa4984cb080486abea89ad --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelLocationsViewInfoTest.cs (.../DesignWaterLevelLocationsViewInfoTest.cs) (revision 425a50160d826226ef47b6c4de8b56811c1984a7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelLocationsViewInfoTest.cs (.../DesignWaterLevelLocationsViewInfoTest.cs) (revision fc3b0b96c11a1e048daa4984cb080486abea89ad) @@ -58,7 +58,7 @@ public void SetUp() { plugin = new RingtoetsPlugin(); - info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(DesignWaterLevelLocationsView)); + info = GetViewInfo(plugin); } [TearDown] @@ -146,16 +146,11 @@ hbl => new HydraulicBoundaryLocationCalculation(), "Category"); - using (var ringtoetsPlugin = new RingtoetsPlugin()) - { - info = ringtoetsPlugin.GetViewInfos().First(tni => tni.ViewType == typeof(DesignWaterLevelLocationsView)); + // Call + var view = (DesignWaterLevelLocationsView) info.CreateInstance(context); - // Call - var view = (DesignWaterLevelLocationsView) info.CreateInstance(context); - - // Assert - Assert.AreSame(assessmentSection, view.AssessmentSection); - } + // Assert + Assert.AreSame(assessmentSection, view.AssessmentSection); } [Test] @@ -190,25 +185,20 @@ hbl => hydraulicBoundaryLocationsLookup[hbl], "Category"); - using (var ringtoetsPlugin = new RingtoetsPlugin()) + // Call + var view = (DesignWaterLevelLocationsView) info.CreateInstance(context); + + // Assert + using (var testForm = new Form()) { - info = ringtoetsPlugin.GetViewInfos().First(tni => tni.ViewType == typeof(DesignWaterLevelLocationsView)); + testForm.Controls.Add(view); + testForm.Show(); - // Call - var view = (DesignWaterLevelLocationsView) info.CreateInstance(context); - - // Assert - using (var testForm = new Form()) - { - testForm.Controls.Add(view); - testForm.Show(); - - DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); - DataGridViewRowCollection rows = locationsDataGridView.Rows; - Assert.AreEqual(2, rows.Count); - Assert.AreEqual(hydraulicBoundaryLocationsLookup.Values.ElementAt(0).Output.Result.ToString(), rows[0].Cells[locationDesignWaterLevelColumnIndex].FormattedValue); - Assert.AreEqual(hydraulicBoundaryLocationsLookup.Values.ElementAt(1).Output.Result.ToString(), rows[1].Cells[locationDesignWaterLevelColumnIndex].FormattedValue); - } + DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); + DataGridViewRowCollection rows = locationsDataGridView.Rows; + Assert.AreEqual(2, rows.Count); + Assert.AreEqual(hydraulicBoundaryLocationsLookup.Values.ElementAt(0).Output.Result.ToString(), rows[0].Cells[locationDesignWaterLevelColumnIndex].FormattedValue); + Assert.AreEqual(hydraulicBoundaryLocationsLookup.Values.ElementAt(1).Output.Result.ToString(), rows[1].Cells[locationDesignWaterLevelColumnIndex].FormattedValue); } } @@ -218,23 +208,12 @@ // Setup Func getNormFunc = () => 0.01; - var hydraulicBoundaryLocations = new ObservableList(); - var hydraulicBoundaryLocationsLookup = new Dictionary + var hydraulicBoundaryLocations = new ObservableList { - { - new TestHydraulicBoundaryLocation(), - new HydraulicBoundaryLocationCalculation() - }, - { - new TestHydraulicBoundaryLocation(), - new HydraulicBoundaryLocationCalculation() - } + new TestHydraulicBoundaryLocation() }; + Func getCalculationFunc = hbl => new HydraulicBoundaryLocationCalculation(); - hydraulicBoundaryLocations.AddRange(hydraulicBoundaryLocationsLookup.Keys); - - Func getCalculationFunc = hbl => hydraulicBoundaryLocationsLookup[hbl]; - var context = new DesignWaterLevelLocationsContext(hydraulicBoundaryLocations, new ObservableTestAssessmentSectionStub(), getNormFunc, @@ -255,32 +234,27 @@ mockRepository.ReplayAll(); - using (var ringtoetsPlugin = new RingtoetsPlugin()) + // Call + var view = (DesignWaterLevelLocationsView) info.CreateInstance(context); + + // Assert + using (var testForm = new Form()) { - info = ringtoetsPlugin.GetViewInfos().First(tni => tni.ViewType == typeof(DesignWaterLevelLocationsView)); + view.CalculationGuiService = guiService; + testForm.Controls.Add(view); + testForm.Show(); - // Call - var view = (DesignWaterLevelLocationsView) info.CreateInstance(context); + DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); + DataGridViewRowCollection rows = locationsDataGridView.Rows; + rows[0].Cells[locationCalculateColumnIndex].Value = true; - // Assert - using (var testForm = new Form()) - { - view.CalculationGuiService = guiService; - testForm.Controls.Add(view); - testForm.Show(); + view.CalculationGuiService = guiService; + var button = new ButtonTester("CalculateForSelectedButton", testForm); - DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); - DataGridViewRowCollection rows = locationsDataGridView.Rows; - rows[0].Cells[locationCalculateColumnIndex].Value = true; + button.Click(); - view.CalculationGuiService = guiService; - var button = new ButtonTester("CalculateForSelectedButton", testForm); - - button.Click(); - - Assert.AreEqual(getNormFunc(), actualNormValue); - Assert.AreSame(getCalculationFunc, actualGetCalculationFuncValue); - } + Assert.AreEqual(getNormFunc(), actualNormValue); + Assert.AreSame(getCalculationFunc, actualGetCalculationFuncValue); } mockRepository.VerifyAll(); @@ -320,12 +294,12 @@ using (var ringtoetsPlugin = new RingtoetsPlugin()) { - info = ringtoetsPlugin.GetViewInfos().First(tni => tni.ViewType == typeof(DesignWaterLevelLocationsView)); + ViewInfo viewInfo = GetViewInfo(ringtoetsPlugin); ringtoetsPlugin.Gui = gui; ringtoetsPlugin.Activate(); // Call - info.AfterCreate(view, context); + viewInfo.AfterCreate(view, context); // Assert Assert.IsInstanceOf(view.CalculationGuiService); @@ -394,5 +368,10 @@ Assert.IsFalse(closeForData); } } + + private static ViewInfo GetViewInfo(RingtoetsPlugin plugin) + { + return plugin.GetViewInfos().First(tni => tni.ViewType == typeof(DesignWaterLevelLocationsView)); + } } } \ No newline at end of file