public void RemoveAllData_Always_RemovesAllDataFromMapControl()
        {
            // Setup
            var            mapDataCollection = new MapDataCollection("Collection");
            WmtsMapData    backgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(backgroundMapData);

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(backgroundMapData))
                    using (var riskeerMapControl = new RiskeerMapControl())
                    {
                        riskeerMapControl.SetAllData(mapDataCollection, backgroundData);

                        // Precondition
                        Assert.IsNotNull(riskeerMapControl.MapControl.Data);
                        Assert.IsNotNull(riskeerMapControl.MapControl.BackgroundMapData);

                        // Call
                        riskeerMapControl.RemoveAllData();

                        // Assert
                        Assert.IsNull(riskeerMapControl.MapControl.Data);
                        Assert.IsNull(riskeerMapControl.MapControl.BackgroundMapData);
                    }
        }
Beispiel #2
0
        private void UpdateBackgroundMapData()
        {
            ImageBasedMapData newData = BackgroundDataConverter.ConvertFrom(backgroundData);

            if (backgroundData.Configuration is WmtsBackgroundDataConfiguration)
            {
                if (newData.IsConfigured)
                {
                    var newWmtsData = (WmtsMapData)newData;
                    ((WmtsMapData)mapControl.BackgroundMapData).Configure(newWmtsData.SourceCapabilitiesUrl,
                                                                          newWmtsData.SelectedCapabilityIdentifier,
                                                                          newWmtsData.PreferredFormat);
                }
                else
                {
                    ((WmtsMapData)mapControl.BackgroundMapData).RemoveConfiguration();
                }
            }
            else if (backgroundData.Configuration is WellKnownBackgroundDataConfiguration)
            {
                ((WellKnownTileSourceMapData)mapControl.BackgroundMapData).SetTileSource(((WellKnownTileSourceMapData)newData).TileSource);
            }

            mapControl.BackgroundMapData.IsVisible    = newData.IsVisible;
            mapControl.BackgroundMapData.Name         = newData.Name;
            mapControl.BackgroundMapData.Transparency = newData.Transparency;
        }
        public void GivenConfiguredWellKnownBackgroundData_WhenTileSourceChangedAndNotified_ThenBackgroundMapDataUpdatedAndNotified()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var            mapData           = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial);
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(mapData);
            var            mapDataCollection = new MapDataCollection("Collection");

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(mapData))
                {
                    var riskeerMapControl = new RiskeerMapControl();
                    riskeerMapControl.SetAllData(mapDataCollection, backgroundData);
                    riskeerMapControl.MapControl.BackgroundMapData.Attach(observer);

                    ImageBasedMapData oldBackgroundMapData = riskeerMapControl.MapControl.BackgroundMapData;

                    // When
                    backgroundData.Configuration = new WellKnownBackgroundDataConfiguration(RiskeerWellKnownTileSource.BingRoads);
                    backgroundData.NotifyObservers();

                    // Then
                    Assert.AreSame(oldBackgroundMapData, riskeerMapControl.MapControl.BackgroundMapData);

                    var newWellKnownMapData = (WellKnownTileSourceMapData)riskeerMapControl.MapControl.BackgroundMapData;
                    Assert.AreEqual(WellKnownTileSource.BingRoads, newWellKnownMapData.TileSource);
                    mocks.VerifyAll();
                }
        }
        public void GivenBackgroundData_WhenBackgroundDataChangedButSameTypeAndNotified_ThenBackgroundMapDataUpdatedAndNotified()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            WmtsMapData    mapData           = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(mapData);
            var            mapDataCollection = new MapDataCollection("Collection");

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(mapData))
                {
                    var riskeerMapControl = new RiskeerMapControl();
                    riskeerMapControl.SetAllData(mapDataCollection, backgroundData);
                    riskeerMapControl.MapControl.BackgroundMapData.Attach(observer);

                    ImageBasedMapData oldBackgroundMapData = riskeerMapControl.MapControl.BackgroundMapData;

                    // When
                    backgroundData.Transparency = (RoundedDouble)0.3;
                    backgroundData.NotifyObservers();

                    // Then
                    Assert.AreSame(oldBackgroundMapData, riskeerMapControl.MapControl.BackgroundMapData);
                    Assert.AreEqual(0.3, riskeerMapControl.MapControl.BackgroundMapData.Transparency.Value);
                    mocks.VerifyAll();
                }
        }
Beispiel #5
0
        public void GivenMapDataSet_WhenSelectingMapDataFromContextMenuCancelled_ThenNoObserversNotified()
        {
            // Given
            var mockRepository            = new MockRepository();
            var assessmentSectionObserver = mockRepository.StrictMock <IObserver>();
            var backgroundDataObserver    = mockRepository.StrictMock <IObserver>();

            WmtsMapData    mapData        = WmtsMapDataTestHelper.CreateUnconnectedMapData();
            BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData);

            WmtsMapData    newMapData        = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData newBackgroundData = BackgroundDataConverter.ConvertTo(newMapData);

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "noConfig")
            }))
                using (new UseCustomTileSourceFactoryConfig(newMapData))
                    using (var treeViewControl = new TreeViewControl())
                        using (var plugin = new RiskeerPlugin())
                        {
                            var viewCommands = mockRepository.Stub <IViewCommands>();
                            var mainWindow   = mockRepository.Stub <IMainWindow>();

                            IGui gui = StubFactory.CreateGuiStub(mockRepository);
                            gui.Stub(g => g.MainWindow).Return(mainWindow);
                            gui.Stub(g => g.ViewCommands).Return(viewCommands);
                            gui.Stub(cmp => cmp.Get(newBackgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                            mockRepository.ReplayAll();

                            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                            var assessmentSectionStateRootContext = new AssessmentSectionStateRootContext(assessmentSection);
                            assessmentSection.Attach(assessmentSectionObserver);
                            assessmentSection.BackgroundData.Attach(backgroundDataObserver);

                            SetBackgroundData(assessmentSection, mapData);

                            DialogBoxHandler = (name, wnd) =>
                            {
                                var tester = (BackgroundMapDataSelectionDialog) new FormTester(name).TheObject;
                                tester.DialogResult = DialogResult.Cancel;
                                tester.Close();
                            };

                            TreeNodeInfo info = GetInfo(plugin);
                            plugin.Gui = gui;

                            using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(newBackgroundData, assessmentSectionStateRootContext, treeViewControl))
                            {
                                // When
                                contextMenuStrip.Items[selectContextMenuIndex].PerformClick();

                                // Then
                                BackgroundDataTestHelper.AssertBackgroundData(backgroundData, assessmentSection.BackgroundData);
                            }
                        }

            mockRepository.VerifyAll();
        }
        public void ConvertTo_MapDataNull_ThrowArgumentNullException()
        {
            // Call
            TestDelegate test = () => BackgroundDataConverter.ConvertTo(null);

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

            Assert.AreEqual("mapData", exception.ParamName);
        }
        public void ConvertFrom_BackgroundDataWithInvalidWellKnownTileSourceValue_ThrowsInvalidEnumArgumentException()
        {
            // Setup
            var backgroundData = new BackgroundData(new WellKnownBackgroundDataConfiguration((RiskeerWellKnownTileSource)999));

            // Call
            TestDelegate call = () => BackgroundDataConverter.ConvertFrom(backgroundData);

            // Assert
            Assert.Throws <InvalidEnumArgumentException>(call);
        }
        public void ConvertFrom_BackgroundData_ReturnWmtsMapData(WmtsMapData mapData)
        {
            // Setup
            BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData);

            // Call
            ImageBasedMapData convertedMapData = BackgroundDataConverter.ConvertFrom(backgroundData);

            // Assert
            MapDataTestHelper.AssertImageBasedMapData(backgroundData, convertedMapData);
        }
        public void ConvertFrom_BackgroundData_ReturnWellKnownMapData()
        {
            // Setup
            var            random = new Random(21);
            var            wellKnownTileSource = random.NextEnumValue <WellKnownTileSource>();
            BackgroundData backgroundData      = BackgroundDataConverter.ConvertTo(new WellKnownTileSourceMapData(wellKnownTileSource));

            // Call
            ImageBasedMapData convertedMapData = BackgroundDataConverter.ConvertFrom(backgroundData);

            // Assert
            MapDataTestHelper.AssertImageBasedMapData(backgroundData, convertedMapData);
        }
Beispiel #10
0
 private void OnBackgroundDataUpdated()
 {
     if (backgroundData.Configuration is WmtsBackgroundDataConfiguration && mapControl.BackgroundMapData is WmtsMapData ||
         backgroundData.Configuration is WellKnownBackgroundDataConfiguration && mapControl.BackgroundMapData is WellKnownTileSourceMapData)
     {
         UpdateBackgroundMapData();
         mapControl.BackgroundMapData.NotifyObservers();
     }
     else
     {
         mapControl.BackgroundMapData = BackgroundDataConverter.ConvertFrom(backgroundData);
     }
 }
        public void ConvertFrom_ConfigurationTypeNotSupportedForConversion_ThrowNotSupportedException()
        {
            // Setup
            var backgroundData = new BackgroundData(new TestBackgroundDataConfiguration());

            // Call
            TestDelegate test = () => BackgroundDataConverter.ConvertFrom(backgroundData);

            // Assert
            var    exception       = Assert.Throws <NotSupportedException>(test);
            string expectedMessage = $"Can't create a image based map data for {typeof(TestBackgroundDataConfiguration)}.";

            Assert.AreEqual(expectedMessage, exception.Message);
        }
        public void ConvertTo_MapDataNotSupportedForConversion_ThrowNotSupportedException()
        {
            // Setup
            var unsupportedImageBasedMapData = new TestImageBasedMapData("What's in a name?", false);

            // Call
            TestDelegate call = () => BackgroundDataConverter.ConvertTo(unsupportedImageBasedMapData);

            // Assert
            var    exception       = Assert.Throws <NotSupportedException>(call);
            string expectedMessage = $"Can't create a background data configuration for {typeof(TestImageBasedMapData)}.";

            Assert.AreEqual(expectedMessage, exception.Message);
        }
Beispiel #13
0
        public void ForeColor_UnconnectedWtmsBackgroundDataConfiguration_ReturnGrayText()
        {
            // Setup
            WmtsMapData    mapData        = WmtsMapDataTestHelper.CreateUnconnectedMapData();
            BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData);

            using (var plugin = new RiskeerPlugin())
            {
                TreeNodeInfo info = GetInfo(plugin);

                // Call
                Color image = info.ForeColor(backgroundData);

                // Assert
                Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), image);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Sets all data to the control.
        /// </summary>
        /// <param name="data">The <see cref="MapDataCollection"/> to set to the control.</param>
        /// <param name="background">The <see cref="BackgroundData"/> to set to the control.</param>
        /// <exception cref="ArgumentNullException">Thrown when any of the parameters is <c>null</c>.</exception>
        public void SetAllData(MapDataCollection data, BackgroundData background)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (background == null)
            {
                throw new ArgumentNullException(nameof(background));
            }

            backgroundData = background;
            backgroundDataObserver.Observable = backgroundData;

            mapControl.Data = data;
            mapControl.BackgroundMapData = BackgroundDataConverter.ConvertFrom(backgroundData);
        }
Beispiel #15
0
        public void ForeColor_WellKnownBackgroundDataConfiguration_ReturnControlText()
        {
            // Setup
            var            random = new Random(21);
            var            wellKnownTileSource = random.NextEnumValue <WellKnownTileSource>();
            BackgroundData backgroundData      = BackgroundDataConverter.ConvertTo(new WellKnownTileSourceMapData(wellKnownTileSource));

            using (var plugin = new RiskeerPlugin())
            {
                TreeNodeInfo info = GetInfo(plugin);

                // Call
                Color image = info.ForeColor(backgroundData);

                // Assert
                Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), image);
            }
        }
        public void ConvertTo_WellKnownMapData_ReturnBackgroundData()
        {
            // Setup
            var random = new Random(21);
            var wellKnownTileSource = random.NextEnumValue <WellKnownTileSource>();
            var mapData             = new WellKnownTileSourceMapData(wellKnownTileSource);

            // Call
            BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData);

            // Assert
            Assert.AreEqual(mapData.Name, backgroundData.Name);
            Assert.AreEqual(mapData.IsVisible, backgroundData.IsVisible);
            Assert.AreEqual(mapData.Transparency, backgroundData.Transparency);

            var configuration     = (WellKnownBackgroundDataConfiguration)backgroundData.Configuration;
            var mapDataTileSource = (RiskeerWellKnownTileSource)mapData.TileSource;

            Assert.AreEqual(mapDataTileSource, configuration.WellKnownTileSource);
        }
        public void SetAllData_Always_SetsAllDataToMapControl()
        {
            // Setup
            var            mapDataCollection = new MapDataCollection("Collection");
            WmtsMapData    backgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(backgroundMapData);

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(backgroundMapData))
                    using (var riskeerMapControl = new RiskeerMapControl())
                    {
                        // Call
                        riskeerMapControl.SetAllData(mapDataCollection, backgroundData);

                        // Assert
                        Assert.AreSame(mapDataCollection, riskeerMapControl.MapControl.Data);
                        Assert.IsNotNull(riskeerMapControl.MapControl.BackgroundMapData);
                        MapDataTestHelper.AssertImageBasedMapData(backgroundData, riskeerMapControl.MapControl.BackgroundMapData);
                    }
        }
        public void ConvertTo_WmtsMapData_ReturnBackgroundData(bool configured)
        {
            // Setup
            WmtsMapData mapData = configured
                                      ? WmtsMapDataTestHelper.CreateDefaultPdokMapData()
                                      : WmtsMapDataTestHelper.CreateUnconnectedMapData();

            // Call
            BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData);

            // Assert
            Assert.AreEqual(mapData.Name, backgroundData.Name);
            Assert.AreEqual(mapData.IsVisible, backgroundData.IsVisible);
            Assert.AreEqual(mapData.Transparency, backgroundData.Transparency);

            var configuration = (WmtsBackgroundDataConfiguration)backgroundData.Configuration;

            Assert.AreEqual(configured, configuration.IsConfigured);
            Assert.AreEqual(mapData.SourceCapabilitiesUrl, configuration.SourceCapabilitiesUrl);
            Assert.AreEqual(mapData.SelectedCapabilityIdentifier, configuration.SelectedCapabilityIdentifier);
            Assert.AreEqual(mapData.PreferredFormat, configuration.PreferredFormat);
        }
        public void GivenConfiguredWmtsBackgroundData_WhenWmtsConfigurationSetToFalseAndNotified_ThenBackgroundMapDataConfigurationRemovedAndNotified()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            WmtsMapData    mapData           = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(mapData);
            var            mapDataCollection = new MapDataCollection("Collection");

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(mapData))
                {
                    var riskeerMapControl = new RiskeerMapControl();
                    riskeerMapControl.SetAllData(mapDataCollection, backgroundData);
                    riskeerMapControl.MapControl.BackgroundMapData.Attach(observer);

                    ImageBasedMapData oldBackgroundMapData = riskeerMapControl.MapControl.BackgroundMapData;

                    // When
                    backgroundData.Configuration = new WmtsBackgroundDataConfiguration();
                    backgroundData.NotifyObservers();

                    // Then
                    Assert.AreSame(oldBackgroundMapData, riskeerMapControl.MapControl.BackgroundMapData);

                    var newWmtsMapData = (WmtsMapData)riskeerMapControl.MapControl.BackgroundMapData;
                    Assert.IsNull(newWmtsMapData.SourceCapabilitiesUrl);
                    Assert.IsNull(newWmtsMapData.SelectedCapabilityIdentifier);
                    Assert.IsNull(newWmtsMapData.PreferredFormat);
                    mocks.VerifyAll();
                }
        }
        public void GivenBackgroundData_WhenBackgroundDataChangedToOtherTypeAndNotified_ThenNewInstanceSetOnBackgroundMapData(
            BackgroundData originalBackgroundData,
            BackgroundData newBackgroundData)
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            mocks.ReplayAll();

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(new TestTileSourceFactory(BackgroundDataConverter.ConvertFrom(originalBackgroundData))))
                {
                    var riskeerMapControl = new RiskeerMapControl();
                    var mapDataCollection = new MapDataCollection("Collection");

                    riskeerMapControl.SetAllData(mapDataCollection, originalBackgroundData);
                    riskeerMapControl.MapControl.BackgroundMapData.Attach(observer);

                    ImageBasedMapData oldMapData = riskeerMapControl.MapControl.BackgroundMapData;

                    // When
                    originalBackgroundData.Name          = newBackgroundData.Name;
                    originalBackgroundData.IsVisible     = newBackgroundData.IsVisible;
                    originalBackgroundData.Transparency  = newBackgroundData.Transparency;
                    originalBackgroundData.Configuration = newBackgroundData.Configuration;
                    originalBackgroundData.NotifyObservers();

                    // Then
                    Assert.IsNotNull(riskeerMapControl.MapControl.BackgroundMapData);
                    Assert.AreNotSame(oldMapData, riskeerMapControl.MapControl.BackgroundMapData);
                    Assert.AreNotEqual(oldMapData.GetType(), riskeerMapControl.MapControl.BackgroundMapData.GetType());
                    mocks.VerifyAll(); // Expect no observers notified
                }
        }
Beispiel #21
0
        public void GivenNoMapDataSet_WhenSelectingValidWmtsMapDataFromContextMenu_ThenBackgroundDataSetAndNotifiesObserver()
        {
            // Given
            var mockRepository = new MockRepository();
            var tileFactory    = mockRepository.StrictMock <ITileSourceFactory>();
            var newMapData     = new WmtsMapData("Actueel Hoogtebestand Nederland (AHN1)",
                                                 "https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilities",
                                                 "()", "image/png");

            tileFactory.Expect(tf => tf.GetWmtsTileSources(null))
            .IgnoreArguments()
            .Return(new[]
            {
                new TestWmtsTileSource(newMapData)
            });

            var backgroundDataObserver = mockRepository.StrictMock <IObserver>();

            backgroundDataObserver.Expect(o => o.UpdateObserver());

            WmtsMapData    mapData        = WmtsMapDataTestHelper.CreateUnconnectedMapData();
            BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData);

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "twoValidWmtsConnectionInfos")
            }))
                using (new UseCustomTileSourceFactoryConfig(tileFactory))
                    using (var treeViewControl = new TreeViewControl())
                        using (var plugin = new RiskeerPlugin())
                        {
                            var viewCommands = mockRepository.Stub <IViewCommands>();
                            var mainWindow   = mockRepository.Stub <IMainWindow>();

                            IGui gui = StubFactory.CreateGuiStub(mockRepository);
                            gui.Stub(g => g.MainWindow).Return(mainWindow);
                            gui.Stub(g => g.ViewCommands).Return(viewCommands);
                            gui.Stub(cmp => cmp.Get(backgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                            mockRepository.ReplayAll();

                            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                            var assessmentSectionStateRootContext = new AssessmentSectionStateRootContext(assessmentSection);
                            assessmentSection.BackgroundData.Attach(backgroundDataObserver);

                            DialogBoxHandler = (name, wnd) =>
                            {
                                var dialog        = (BackgroundMapDataSelectionDialog) new FormTester(name).TheObject;
                                var connectButton = new ButtonTester("connectToButton", dialog);
                                connectButton.Click();

                                var layersControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject;
                                layersControl.SetCurrentCell(layersControl.GetCell(0, 0));

                                var button = new ButtonTester("selectButton", dialog);
                                button.Click();
                                dialog.Close();
                            };

                            TreeNodeInfo info = GetInfo(plugin);
                            plugin.Gui = gui;

                            using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(backgroundData, assessmentSectionStateRootContext, treeViewControl))
                            {
                                // When
                                contextMenuStrip.Items[selectContextMenuIndex].PerformClick();

                                // Then
                                AssertBackgroundData(newMapData, assessmentSection.BackgroundData);
                            }
                        }

            mockRepository.VerifyAll();
        }
Beispiel #22
0
        public void GivenMapDataSet_WhenSelectingValidWellKnownMapDataFromContextMenu_ThenBackgroundDataSetAndNotifiesObserver()
        {
            // Given
            var mockRepository = new MockRepository();

            var backgroundDataObserver = mockRepository.StrictMock <IObserver>();

            backgroundDataObserver.Expect(o => o.UpdateObserver());

            WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData();

            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
            var assessmentSectionStateRootContext = new AssessmentSectionStateRootContext(assessmentSection);

            const WellKnownTileSource wellKnownTileSource = WellKnownTileSource.BingAerial;
            var            newMapData        = new WellKnownTileSourceMapData(wellKnownTileSource);
            BackgroundData newBackgroundData = BackgroundDataConverter.ConvertTo(newMapData);

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.Forms, "EmptyWmtsConnectionInfo")
            }))
                using (var treeViewControl = new TreeViewControl())
                    using (var plugin = new RiskeerPlugin())
                    {
                        var viewCommands = mockRepository.Stub <IViewCommands>();
                        var mainWindow   = mockRepository.Stub <IMainWindow>();

                        IGui gui = StubFactory.CreateGuiStub(mockRepository);
                        gui.Stub(g => g.MainWindow).Return(mainWindow);
                        gui.Stub(g => g.ViewCommands).Return(viewCommands);
                        gui.Stub(cmp => cmp.Get(newBackgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                        mockRepository.ReplayAll();

                        assessmentSection.BackgroundData.Attach(backgroundDataObserver);
                        SetBackgroundData(assessmentSection, mapData);

                        DialogBoxHandler = (name, wnd) =>
                        {
                            var dialog = (BackgroundMapDataSelectionDialog) new FormTester(name).TheObject;

                            var comboBox = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject;
                            comboBox.SelectedItem = ((BackgroundMapDataSelectionControl[])comboBox.DataSource).OfType <WellKnownMapDataControl>().First();
                            var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject;
                            dataGridViewControl.SetCurrentCell(dataGridViewControl.GetCell(0, 0));

                            var button = new ButtonTester("selectButton", dialog);
                            button.Click();
                            dialog.Close();
                        };

                        TreeNodeInfo info = GetInfo(plugin);
                        plugin.Gui = gui;

                        using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(newBackgroundData, assessmentSectionStateRootContext, treeViewControl))
                        {
                            // When
                            contextMenuStrip.Items[selectContextMenuIndex].PerformClick();

                            // Then
                            AssertBackgroundData(newMapData, assessmentSection.BackgroundData);
                        }
                    }

            mockRepository.VerifyAll();
        }