public void GivenWmtsLocationControlWithActiveData_WhenConnectClicked_ThenDataGridUpdatedAndActiveDataSelected() { // Given WmtsMapData backgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData(); WmtsMapData selectedBackgroundMapData = WmtsMapDataTestHelper.CreateAlternativePdokMapData(); wmtsCapabilityFactory.Expect(wcf => wcf.GetWmtsCapabilities(selectedBackgroundMapData.SourceCapabilitiesUrl)) .Return(new[] { CreateWmtsCapability(new TestWmtsTileSource(backgroundMapData)), CreateWmtsCapability(new TestWmtsTileSource(selectedBackgroundMapData)) }); mockRepository.ReplayAll(); using (new UseCustomTileSourceFactoryConfig(selectedBackgroundMapData)) using (var form = new Form()) using (var control = new WmtsLocationControl(selectedBackgroundMapData, wmtsCapabilityFactory)) { form.Controls.Add(control); form.Show(); var connectToButton = new ButtonTester("connectToButton", form); // When connectToButton.Click(); // Then DataGridViewControl dataGridViewControl = form.Controls.Find("dataGridViewControl", true).OfType<DataGridViewControl>().First(); DataGridViewRowCollection rows = dataGridViewControl.Rows; Assert.AreEqual(2, rows.Count); AssertAreEqual(selectedBackgroundMapData, control.SelectedMapData); } }
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); } }
public void CreateBackgroundLayerStatus_WmtsMapData_ReturnsWmtsBackgroundLayerStatus() { // Setup WmtsMapData mapData = WmtsMapDataTestHelper.CreateAlternativePdokMapData(); // Call BackgroundLayerStatus backgroundLayerStatus = BackgroundLayerStatusFactory.CreateBackgroundLayerStatus(mapData); // Assert Assert.IsInstanceOf <WmtsBackgroundLayerStatus>(backgroundLayerStatus); }
public void Clone_FromFullyInitializedConfiguration_CreateNewUninitializedInstance() { // Setup WmtsMapData targetMapData = WmtsMapDataTestHelper.CreateAlternativePdokMapData(); var tileSource = new HttpTileSource(TileSchemaFactory.CreateWmtsTileSchema(targetMapData), (IRequest)null); var tileSources = new ITileSource[] { tileSource }; var mocks = new MockRepository(); var factory = mocks.Stub <ITileSourceFactory>(); factory.Stub(f => f.GetWmtsTileSources(targetMapData.SourceCapabilitiesUrl)).Return(tileSources); mocks.ReplayAll(); using (new UseCustomSettingsHelper(testSettingsHelper)) using (new UseCustomTileSourceFactoryConfig(factory)) using (WmtsLayerConfiguration configuration = WmtsLayerConfiguration.CreateInitializedConfiguration(targetMapData.SourceCapabilitiesUrl, targetMapData.SelectedCapabilityIdentifier, targetMapData.PreferredFormat)) { // Call IConfiguration clone = configuration.Clone(); // Assert Assert.IsInstanceOf <WmtsLayerConfiguration>(clone); Assert.AreNotSame(configuration, clone); Assert.IsFalse(clone.Initialized); Assert.IsNull(clone.TileFetcher, "TileFetcher should be null because the clone hasn't been initialized yet."); Assert.IsNull(clone.TileSchema, "TileSchema should be null because the clone hasn't been initialized yet."); } mocks.VerifyAll(); }
public void CreateInitializedConfiguration_MatchingLayerAvailable_ReturnConfiguration() { // Setup WmtsMapData targetMapData = WmtsMapDataTestHelper.CreateAlternativePdokMapData(); var tileSource1 = new HttpTileSource(TileSchemaFactory.CreateWmtsTileSchema(WmtsMapDataTestHelper.CreateDefaultPdokMapData()), (IRequest)null); var tileSource2 = new HttpTileSource(TileSchemaFactory.CreateWmtsTileSchema(targetMapData), (IRequest)null); var tileSources = new ITileSource[] { tileSource1, tileSource2 }; var mocks = new MockRepository(); var factory = mocks.Stub <ITileSourceFactory>(); factory.Stub(f => f.GetWmtsTileSources(targetMapData.SourceCapabilitiesUrl)).Return(tileSources); mocks.ReplayAll(); using (new UseCustomSettingsHelper(testSettingsHelper)) using (new UseCustomTileSourceFactoryConfig(factory)) { // Call using (WmtsLayerConfiguration configuration = WmtsLayerConfiguration.CreateInitializedConfiguration(targetMapData.SourceCapabilitiesUrl, targetMapData.SelectedCapabilityIdentifier, targetMapData.PreferredFormat)) { // Assert Assert.IsTrue(configuration.Initialized); Assert.IsTrue(configuration.TileFetcher.IsReady()); Assert.AreSame(tileSource2.Schema, configuration.TileSchema); } } mocks.VerifyAll(); }
public void Initialize_ConfigurationDisposed_ThrowsObjectDisposedException() { // Setup WmtsMapData targetMapData = WmtsMapDataTestHelper.CreateAlternativePdokMapData(); var tileSource = new HttpTileSource(TileSchemaFactory.CreateWmtsTileSchema(targetMapData), (IRequest)null); var tileSources = new ITileSource[] { tileSource }; var mocks = new MockRepository(); var factory = mocks.Stub <ITileSourceFactory>(); factory.Stub(f => f.GetWmtsTileSources(targetMapData.SourceCapabilitiesUrl)).Return(tileSources); mocks.ReplayAll(); using (new UseCustomSettingsHelper(testSettingsHelper)) using (new UseCustomTileSourceFactoryConfig(factory)) { WmtsLayerConfiguration configuration = WmtsLayerConfiguration.CreateInitializedConfiguration(targetMapData.SourceCapabilitiesUrl, targetMapData.SelectedCapabilityIdentifier, targetMapData.PreferredFormat); configuration.Dispose(); // Call TestDelegate call = () => configuration.Initialize(); // Assert string objectName = Assert.Throws <ObjectDisposedException>(call).ObjectName; Assert.AreEqual("WmtsLayerConfiguration", objectName); } mocks.VerifyAll(); }
public void GivenFullyInitializedConfiguration_WhenClonedAndInitialized_ConfigurationAreEqual() { // Given WmtsMapData targetMapData = WmtsMapDataTestHelper.CreateAlternativePdokMapData(); var tileSource = new HttpTileSource(TileSchemaFactory.CreateWmtsTileSchema(targetMapData), (IRequest)null); var tileSources = new ITileSource[] { tileSource }; var mocks = new MockRepository(); var factory = mocks.Stub <ITileSourceFactory>(); factory.Stub(f => f.GetWmtsTileSources(targetMapData.SourceCapabilitiesUrl)).Return(tileSources); mocks.ReplayAll(); using (new UseCustomSettingsHelper(testSettingsHelper)) using (new UseCustomTileSourceFactoryConfig(factory)) using (WmtsLayerConfiguration configuration = WmtsLayerConfiguration.CreateInitializedConfiguration(targetMapData.SourceCapabilitiesUrl, targetMapData.SelectedCapabilityIdentifier, targetMapData.PreferredFormat)) { // When IConfiguration clone = configuration.Clone(); clone.Initialize(); // Assert Assert.IsTrue(clone.Initialized); Assert.IsTrue(clone.TileFetcher.IsReady()); Assert.AreSame(configuration.TileSchema, clone.TileSchema); } mocks.VerifyAll(); }