Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/BackgroundDataTreeNodeInfoTest.cs =================================================================== diff -u -r7dcf169799c42e16f0badadb62624806c4f7fb00 -r6288ea6ea5dbbbd7a98b40449eb3c7794379ce11 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/BackgroundDataTreeNodeInfoTest.cs (.../BackgroundDataTreeNodeInfoTest.cs) (revision 7dcf169799c42e16f0badadb62624806c4f7fb00) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/BackgroundDataTreeNodeInfoTest.cs (.../BackgroundDataTreeNodeInfoTest.cs) (revision 6288ea6ea5dbbbd7a98b40449eb3c7794379ce11) @@ -243,7 +243,7 @@ } [Test] - public void GivenNoMapDataSet_WhenSelectingValidWMTSMapDataFromContextMenu_ThenMapDataSetAndNotifiesObserver() + public void GivenNoMapDataSet_WhenSelectingValidWMTSMapDataFromContextMenu_ThenBackgroundDataSetAndNotifiesObserver() { // Given var mockRepository = new MockRepository(); @@ -304,7 +304,7 @@ contextMenuStrip.Items[selectContextMenuIndex].PerformClick(); // Then - AssertBackgroundMapDataProperties(newMapData, assessmentSection.BackgroundData, true); + AssertBackgroundMapDataProperties(newMapData, assessmentSection.BackgroundData); } } mockRepository.VerifyAll(); @@ -366,7 +366,7 @@ } [Test] - public void GivenMapDataSet_WhenSelectingValidWmtsMapDataFromContextMenu_ThenMapDataSetAndNotifiesObserver() + public void GivenMapDataSet_WhenSelectingValidWmtsMapDataFromContextMenu_ThenBackgroundDataSetAndNotifiesObserver() { // Given var mockRepository = new MockRepository(); @@ -425,24 +425,30 @@ contextMenuStrip.Items[selectContextMenuIndex].PerformClick(); // Then - AssertBackgroundMapDataProperties(newMapData, assessmentSection.BackgroundData, true); + AssertBackgroundMapDataProperties(newMapData, assessmentSection.BackgroundData); } } mockRepository.VerifyAll(); } [Test] - public void GivenMapDataSet_WhenSelectingValidWellKnownMapDataFromContextMenu_ThenMapDataNotSetAndNoNotifiesObserver() + public void GivenMapDataSet_WhenSelectingValidWellKnownMapDataFromContextMenu_ThenBackgroundDataSetAndNotifiesObserver() { // Given var mockRepository = new MockRepository(); var assessmentSectionObserver = mockRepository.StrictMock(); + assessmentSectionObserver.Expect(o => o.UpdateObserver()); + var backgroundMapDataObserver = mockRepository.StrictMock(); + backgroundMapDataObserver.Expect(o => o.UpdateObserver()); WmtsMapData mapData = WmtsMapData.CreateUnconnectedMapData(); var assessmentSection = new ObservableTestAssessmentSectionStub(); + var newMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); + var newBackgroundData = BackgroundDataTestDataGenerator.GetWellKnownBackgroundMapData(); + using (var treeViewControl = new TreeViewControl()) using (var plugin = new RingtoetsPlugin()) { @@ -454,7 +460,7 @@ gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); gui.Stub(g => g.ViewCommands).Return(viewCommands); - gui.Stub(cmp => cmp.Get(assessmentSection.BackgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.Get(newBackgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mockRepository.ReplayAll(); assessmentSection.Attach(assessmentSectionObserver); @@ -474,8 +480,8 @@ var comboBox = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; comboBox.SelectedItem = ((IBackgroundMapDataSelectionControl[]) comboBox.DataSource).OfType().First(); - var wmtsDataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject; - wmtsDataGridViewControl.SetCurrentCell(wmtsDataGridViewControl.GetCell(1, 0)); + var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject; + dataGridViewControl.SetCurrentCell(dataGridViewControl.GetCell(0, 0)); var button = new ButtonTester("selectButton", dialog); button.Click(); @@ -485,13 +491,13 @@ TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; - using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(assessmentSection.BackgroundData, assessmentSection, treeViewControl)) + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(newBackgroundData, assessmentSection, treeViewControl)) { // When contextMenuStrip.Items[selectContextMenuIndex].PerformClick(); // Then - AssertBackgroundMapDataProperties(mapData, assessmentSection.BackgroundData, false); + AssertBackgroundMapDataProperties(newMapData, assessmentSection.BackgroundData); } } mockRepository.VerifyAll(); @@ -555,17 +561,35 @@ mockRepository.VerifyAll(); } - private static void AssertBackgroundMapDataProperties(WmtsMapData mapData, BackgroundData backgroundData, bool shouldBeVisible) + private static void AssertBackgroundMapDataProperties(WmtsMapData mapData, BackgroundData backgroundData) { Assert.AreEqual(mapData.Name, backgroundData.Name); - Assert.AreEqual(shouldBeVisible, backgroundData.IsVisible); + Assert.IsTrue(backgroundData.IsVisible); Assert.AreEqual(mapData.IsConfigured, backgroundData.IsConfigured); Assert.AreEqual(mapData.Transparency, backgroundData.Transparency); - Assert.AreEqual(mapData.SourceCapabilitiesUrl, backgroundData.Parameters[BackgroundDataIdentifiers.SourceCapabilitiesUrl]); - Assert.AreEqual(mapData.SelectedCapabilityIdentifier, backgroundData.Parameters[BackgroundDataIdentifiers.SelectedCapabilityIdentifier]); - Assert.AreEqual(mapData.PreferredFormat, backgroundData.Parameters[BackgroundDataIdentifiers.PreferredFormat]); + + if (mapData.IsConfigured) + { + Assert.AreEqual(mapData.SourceCapabilitiesUrl, backgroundData.Parameters[BackgroundDataIdentifiers.SourceCapabilitiesUrl]); + Assert.AreEqual(mapData.SelectedCapabilityIdentifier, backgroundData.Parameters[BackgroundDataIdentifiers.SelectedCapabilityIdentifier]); + Assert.AreEqual(mapData.PreferredFormat, backgroundData.Parameters[BackgroundDataIdentifiers.PreferredFormat]); + } + else + { + CollectionAssert.IsEmpty(backgroundData.Parameters); + } } + private static void AssertBackgroundMapDataProperties(WellKnownTileSourceMapData mapData, BackgroundData backgroundData) + { + Assert.AreEqual(mapData.Name, backgroundData.Name); + Assert.IsTrue(backgroundData.IsVisible); + Assert.AreEqual(mapData.IsConfigured, backgroundData.IsConfigured); + Assert.AreEqual(mapData.Transparency, backgroundData.Transparency); + + Assert.AreEqual(((int)mapData.TileSource).ToString(), backgroundData.Parameters[BackgroundDataIdentifiers.WellKnownTileSource]); + } + private static void AssertBackgroundMapDataProperties(BackgroundData expectedBackgroundData, BackgroundData actualBackgroundData) { Assert.AreEqual(expectedBackgroundData.Name, actualBackgroundData.Name);