Esempio n. 1
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);
                        }
        }