Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public void Configure_PreferredImageFormatNull_ThrowArgumentNullException()
        {
            // Setup
            WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData();

            // Call
            TestDelegate call = () => mapData.Configure(url, capabilityIdentifier, null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("preferredFormat", paramName);
        }
Exemplo n.º 3
0
        public void Configure_SelectedCapabilityNameNull_ThrowArgumentNullException()
        {
            // Setup
            WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData();

            // Call
            TestDelegate call = () => mapData.Configure(url, null, imageFormat);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("selectedCapabilityName", paramName);
        }
Exemplo n.º 4
0
        public void Configure_CapabilitiesUrlNull_ThrowArgumentNullException()
        {
            // Setup
            WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData();

            // Call
            TestDelegate call = () => mapData.Configure(null, capabilityIdentifier, imageFormat);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("sourceCapabilitiesUrl", paramName);
        }
Exemplo n.º 5
0
        public void Configure_ValidArguments_SetConnectionProperties()
        {
            // Setup
            WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData();

            // Call
            mapData.Configure(url, capabilityIdentifier, imageFormat);

            // Assert
            Assert.AreEqual(url, mapData.SourceCapabilitiesUrl);
            Assert.AreEqual(capabilityIdentifier, mapData.SelectedCapabilityIdentifier);
            Assert.IsTrue(mapData.IsConfigured);
            Assert.IsTrue(mapData.IsVisible);
        }
Exemplo n.º 6
0
        public void Configure_PreferredImageFormatNotMime_ThrowArgumentException()
        {
            // Setup
            WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData();

            // Call
            TestDelegate call = () => mapData.Configure(url, capabilityIdentifier, "png");

            // Assert
            const string message   = "Specified image format is not a MIME type.";
            string       paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message).ParamName;

            Assert.AreEqual("preferredFormat", paramName);
        }
Exemplo n.º 7
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);
            }
        }
        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);
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
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();
        }