Пример #1
0
        public void Constructor_MapDataNull_DefaultProperties()
        {
            // Setup
            var dialogParent = mockRepository.Stub <IWin32Window>();

            mockRepository.ReplayAll();

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
            {
                // Call
                using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null))
                {
                    // Assert
                    Assert.IsInstanceOf <DialogBase>(dialog);
                    Assert.AreEqual("Selecteer achtergrondkaart", dialog.Text);

                    Icon   icon          = BitmapToIcon(RiskeerCommonFormsResources.SelectionDialogIcon);
                    Bitmap expectedImage = icon.ToBitmap();
                    Bitmap actualImage   = dialog.Icon.ToBitmap();
                    TestHelper.AssertImagesAreEqual(expectedImage, actualImage);

                    AssertMapDataControls <WellKnownMapDataControl>(dialog);
                }
            }
        }
Пример #2
0
        public void Dispose_DisposedAlreadyCalled_DoesNotThrowException()
        {
            // Setup
            mockRepository.ReplayAll();

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
            {
                // Call
                TestDelegate call = () =>
                {
                    using (var dialogParent = new Form())
                        using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null))
                        {
                            dialog.Dispose();
                        }
                };

                // Assert
                Assert.DoesNotThrow(call);
            }
        }
Пример #3
0
        private static void AssertMapDataControls <T>(BackgroundMapDataSelectionDialog dialog)
            where T : BackgroundMapDataSelectionControl
        {
            var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject;

            Assert.AreEqual("DisplayName", mapLayers.DisplayMember);
            Assert.AreEqual(ComboBoxStyle.DropDownList, mapLayers.DropDownStyle);
            Assert.IsTrue(mapLayers.Sorted);
            Assert.IsInstanceOf <T>(mapLayers.SelectedItem);

            var backgroundMapDataSelectionControls = (BackgroundMapDataSelectionControl[])mapLayers.DataSource;

            Assert.AreEqual(2, backgroundMapDataSelectionControls.Length);
            Assert.IsInstanceOf <WellKnownMapDataControl>(backgroundMapDataSelectionControls[0]);
            Assert.IsInstanceOf <WmtsLocationControl>(backgroundMapDataSelectionControls[1]);

            Assert.IsInstanceOf <BackgroundMapDataSelectionControl[]>(mapLayers.DataSource);
            Assert.AreEqual("DisplayName", mapLayers.DisplayMember);

            var groupBoxProperties = (GroupBox) new ControlTester("propertiesGroupBox", dialog).TheObject;

            Assert.AreEqual(DockStyle.Fill, groupBoxProperties.Dock);
            Assert.AreEqual(1, groupBoxProperties.Controls.Count);
            Assert.AreSame(mapLayers.SelectedItem, groupBoxProperties.Controls[0]);
        }
Пример #4
0
        public void GivenValidDialog_WhenSelectPressed_ThenSelectedMapDataSet()
        {
            // Given
            mockRepository.ReplayAll();

            DialogBoxHandler = (name, wnd) =>
            {
                using (new FormTester(name))
                {
                    var button = new ButtonTester("selectButton", name);
                    button.Click();
                }
            };

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
                using (var dialogParent = new Form())
                    using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null))
                    {
                        // When
                        DialogResult dialogResult = dialog.ShowDialog();

                        // Then
                        Assert.AreEqual(DialogResult.OK, dialogResult);
                        Assert.IsNotNull(dialog.SelectedMapData);
                    }
        }
Пример #5
0
        public void MapDataConstructor_WithWellKnownMapData_DefaultProperties()
        {
            // Setup
            var dialogParent = mockRepository.Stub <IWin32Window>();

            mockRepository.ReplayAll();

            var random  = new Random(124);
            var mapData = new WellKnownTileSourceMapData(random.NextEnumValue <WellKnownTileSource>());

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
                using (new UseCustomTileSourceFactoryConfig(tileFactory))
                {
                    // Call
                    using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, mapData))
                    {
                        // Assert
                        AssertMapDataControls <WellKnownMapDataControl>(dialog);
                    }
                }
        }
Пример #6
0
        public void GivenValidDialog_WhenControlSwitched_ThenDoesNotListenToEventOfOldControl()
        {
            // Given
            WmtsMapData activeWmtsMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();

            var capabilities = new[]
            {
                new TestWmtsTileSource(WmtsMapDataTestHelper.CreateAlternativePdokMapData()),
                new TestWmtsTileSource(activeWmtsMapData)
            };

            tileFactory.Expect(tf => tf.GetWmtsTileSources(activeWmtsMapData.SourceCapabilitiesUrl)).Return(capabilities);
            mockRepository.ReplayAll();

            var wmtsLocationControlSelectedMapDataChanged = 0;

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
                using (new UseCustomTileSourceFactoryConfig(tileFactory))
                    using (var dialogParent = new Form())
                        using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, activeWmtsMapData))
                        {
                            dialog.Show();

                            var comboBox = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject;
                            var wellKnownMapDataControl = GetComboBoxItem <WellKnownMapDataControl>(comboBox);
                            var wmtsLocationControl     = GetComboBoxItem <WmtsLocationControl>(comboBox);

                            comboBox.SelectedItem = wmtsLocationControl;

                            Button connectButton = dialog.Controls.Find("connectToButton", true).OfType <Button>().First();
                            connectButton.PerformClick();

                            DataGridViewControl wmtsDataGridViewControl = dialog.Controls.Find("dataGridViewControl", true).OfType <DataGridViewControl>().First();
                            wmtsLocationControl.SelectedMapDataChanged += (sender, args) => wmtsLocationControlSelectedMapDataChanged++;

                            comboBox.SelectedItem = wellKnownMapDataControl;
                            DataGridViewControl wellKnownDataGridViewControl = dialog.Controls.Find("dataGridViewControl", true).OfType <DataGridViewControl>().First();
                            wellKnownDataGridViewControl.ClearCurrentCell();

                            var button = (Button) new ButtonTester("selectButton", dialog).TheObject;
                            Assert.IsFalse(button.Enabled);

                            // When
                            wmtsDataGridViewControl.SetCurrentCell(wmtsDataGridViewControl.GetCell(0, 0));

                            // Then
                            Assert.IsFalse(button.Enabled);
                            Assert.AreEqual(1, wmtsLocationControlSelectedMapDataChanged);
                        }
        }
Пример #7
0
        public void MapDataConstructor_WithWmtsMapData_DefaultProperties()
        {
            // Setup
            var dialogParent = mockRepository.Stub <IWin32Window>();

            mockRepository.ReplayAll();

            WmtsMapData mapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();

            using (new UseCustomTileSourceFactoryConfig(tileFactory))
            {
                // Call
                using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, mapData))
                {
                    // Assert
                    AssertMapDataControls <WmtsLocationControl>(dialog);
                }
            }
        }
Пример #8
0
        public void GivenValidDialogWithoutMapData_WhenBackgroundMapDataSelectionControlSwitchedBackAndForth_ThenSelectButtonAsExpected()
        {
            // Given
            mockRepository.ReplayAll();

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
                using (new UseCustomTileSourceFactoryConfig(tileFactory))
                    using (var dialogParent = new Form())
                        using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null))
                        {
                            dialog.Show();

                            var selectButton            = (Button) new ButtonTester("selectButton", dialog).TheObject;
                            var comboBox                = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject;
                            var wellKnownMapDataControl = GetComboBoxItem <WellKnownMapDataControl>(comboBox);
                            var wmtsLocationControl     = GetComboBoxItem <WmtsLocationControl>(comboBox);

                            // Precondition state
                            comboBox.SelectedItem = wmtsLocationControl;
                            DataGridViewControl wmtsDataGridViewControl = dialog.Controls.Find("dataGridViewControl", true).OfType <DataGridViewControl>().First();
                            Assert.IsNull(wmtsDataGridViewControl.CurrentRow);
                            Assert.IsFalse(selectButton.Enabled);

                            // When
                            comboBox.SelectedItem = wellKnownMapDataControl;
                            DataGridViewControl wellKnownDataGridViewControl = dialog.Controls.Find("dataGridViewControl", true).OfType <DataGridViewControl>().First();
                            DataGridViewRow     currentRow = wellKnownDataGridViewControl.CurrentRow;
                            Assert.AreEqual(0, currentRow.Index);
                            Assert.IsTrue(selectButton.Enabled);

                            // Then
                            comboBox.SelectedItem = wmtsLocationControl;
                            Assert.IsNull(wmtsDataGridViewControl.CurrentRow);
                            Assert.IsFalse(selectButton.Enabled);
                        }
        }
Пример #9
0
        public void GivenValidDialog_WhenControlSwitched_ThenListenToEventOfNewControl()
        {
            // Given
            WmtsMapData activeWmtsMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();

            mockRepository.ReplayAll();

            var wellKnownSelectedMapDataChanged = 0;

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
                using (new UseCustomTileSourceFactoryConfig(tileFactory))
                    using (var dialogParent = new Form())
                        using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, activeWmtsMapData))
                        {
                            dialog.Show();

                            var comboBox         = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject;
                            var wellKnownControl = GetComboBoxItem <WellKnownMapDataControl>(comboBox);

                            comboBox.SelectedItem = wellKnownControl;

                            DataGridViewControl wellKnownDataGridViewControl = dialog.Controls.Find("dataGridViewControl", true).OfType <DataGridViewControl>().First();
                            wellKnownControl.SelectedMapDataChanged += (sender, args) => wellKnownSelectedMapDataChanged++;

                            // When
                            wellKnownDataGridViewControl.SetCurrentCell(wellKnownDataGridViewControl.GetCell(4, 0));
                            var button = new ButtonTester("selectButton", dialog);
                            button.Click();

                            // Then
                            Assert.IsInstanceOf <WellKnownTileSourceMapData>(dialog.SelectedMapData);
                            Assert.AreEqual(1, wellKnownSelectedMapDataChanged);
                        }
        }
Пример #10
0
        public void ShowDialog_Always_DefaultProperties()
        {
            // Setup
            mockRepository.ReplayAll();

            string settingsDirectory = Path.Combine(testPath, "EmptyWmtsConnectionInfo");

            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = settingsDirectory
            }))
                using (var dialogParent = new Form())
                    using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null))
                    {
                        // Call
                        dialog.Show();

                        // Assert
                        var mapLayerLabel = new LabelTester("mapLayerLabel", dialog);
                        Assert.AreEqual("Type kaartlaag", mapLayerLabel.Text);

                        var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject;
                        Assert.IsTrue(mapLayers.Enabled);

                        var groupBoxProperties = new ControlTester("propertiesGroupBox", dialog);
                        Assert.AreEqual("Eigenschappen", groupBoxProperties.Text);

                        var buttonSelect = (Button) new ButtonTester("selectButton", dialog).TheObject;
                        Assert.AreEqual("Selecteren", buttonSelect.Text);
                        Assert.IsTrue(buttonSelect.Enabled);

                        var buttonCancel = (Button) new ButtonTester("cancelButton", dialog).TheObject;
                        Assert.AreEqual("Annuleren", buttonCancel.Text);

                        Assert.AreEqual(500, dialog.MinimumSize.Width);
                        Assert.AreEqual(350, dialog.MinimumSize.Height);
                    }
        }