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 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); } } }
public void HasSameConfiguration_ForInitializedLayer_ReturnTrue() { // Setup var mocks = new MockRepository(); var tileFetcher = mocks.Stub <ITileFetcher>(); using (var layerStatus = new WellKnownBackgroundLayerStatus()) { IConfiguration configuration = CreateStubConfiguration(mocks, tileFetcher); mocks.ReplayAll(); using (var layer = new BruTileLayer(configuration)) { var source = new Random(789).NextEnum <WellKnownTileSource>(); var mapData1 = new WellKnownTileSourceMapData(source); var mapData2 = new WellKnownTileSourceMapData(source); layerStatus.LayerInitializationSuccessful(layer, mapData1); // Call bool isSame = layerStatus.HasSameConfiguration(mapData2); // Assert Assert.IsTrue(isSame, "Should recognize same configuration even if instance is not the same."); } } mocks.VerifyAll(); }
/// <summary> /// Creates a new instance of <see cref="WellKnownMapDataControl"/>. /// </summary> /// <param name="activeWellKnownTileSourceMapData">The active <see cref="WellKnownTileSourceMapData"/> /// or <c>null</c> if none active.</param> public WellKnownMapDataControl(WellKnownTileSourceMapData activeWellKnownTileSourceMapData) : base(Resources.WellKnownMapDataControl_DisplayName) { InitializeComponent(); InitializeDataGridView(); InitializeEventHandlers(); PreSelectDataGridView(activeWellKnownTileSourceMapData); }
/// <summary> /// Create a new tile schema. /// </summary> /// <param name="mapData">The map data to work with.</param> /// <returns>The new tile schema.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="mapData"/> is <c>null</c>.</exception> private static GlobalSphericalMercator CreateTileSchema(WellKnownTileSourceMapData mapData) { if (mapData == null) { throw new ArgumentNullException(nameof(mapData)); } return(new GlobalSphericalMercator(YAxis.TMS, 0, 19, mapData.Name)); }
private static void AssertBackgroundData(WellKnownTileSourceMapData mapData, BackgroundData backgroundData) { Assert.AreEqual(mapData.Name, backgroundData.Name); Assert.IsTrue(backgroundData.IsVisible); Assert.AreEqual(mapData.Transparency, backgroundData.Transparency); var configuration = (WellKnownBackgroundDataConfiguration)backgroundData.Configuration; var wellKnownTileSource = (RiskeerWellKnownTileSource)mapData.TileSource; Assert.AreEqual(wellKnownTileSource, configuration.WellKnownTileSource); }
public void CreateBackgroundLayerStatus_WellKnownTileSourceMapData_ReturnsWellKnownBackgroundLayerStatus() { // Setup var mapData = new WellKnownTileSourceMapData(new Random().NextEnum <WellKnownTileSource>()); // Call BackgroundLayerStatus backgroundLayerStatus = BackgroundLayerStatusFactory.CreateBackgroundLayerStatus(mapData); // Assert Assert.IsInstanceOf <WellKnownBackgroundLayerStatus>(backgroundLayerStatus); }
public void Constructor_ValidWellKnownTileSourceMapData_ExpectedProperties() { // Setup var activeWellKnownTileSourceMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); // Call using (var control = new WellKnownMapDataControl(activeWellKnownTileSourceMapData)) { // Assert AssertAreEqual(activeWellKnownTileSourceMapData, control.SelectedMapData); } }
public void SetTileSource_UnknownTileSource_ThrowInvalidEnumArgumentException() { // Setup var mapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); // Call TestDelegate test = () => mapData.SetTileSource((WellKnownTileSource)99); // Assert const string message = "The value of argument 'enumValue' (99) is invalid for Enum type 'WellKnownTileSource'."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(test, message); }
private static void AssertAreEqual(WellKnownTileSourceMapData expected, ImageBasedMapData actual) { if (expected == null) { Assert.IsNull(actual); return; } var actualWellKnownTileSourceMapData = (WellKnownTileSourceMapData)actual; Assert.AreEqual(expected.Name, actualWellKnownTileSourceMapData.Name); Assert.AreEqual(expected.TileSource, actualWellKnownTileSourceMapData.TileSource); }
public void Constructor_ForAllWellKnownTileSources_ProperlySetName() { // Setup foreach (WellKnownTileSource wellKnownTileSource in Enum.GetValues(typeof(WellKnownTileSource))) { // Call var mapData = new WellKnownTileSourceMapData(wellKnownTileSource); // Assert Assert.AreEqual(TypeUtils.GetDisplayName(wellKnownTileSource), mapData.Name); Assert.AreEqual(wellKnownTileSource, mapData.TileSource); } }
public void SetTileSource_ForAllWellKnownTileSources_ProperlySetName() { // Setup var mapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); foreach (WellKnownTileSource wellKnownTileSource in Enum.GetValues(typeof(WellKnownTileSource))) { // Call mapData.SetTileSource(wellKnownTileSource); // Assert Assert.AreEqual(TypeUtils.GetDisplayName(wellKnownTileSource), mapData.Name); Assert.AreEqual(wellKnownTileSource, mapData.TileSource); } }
public void Constructor_InvalidWellKnownTileSourceMapData_ExpectedProperties() { // Setup var activeWellKnownTileSourceMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial) { Name = "invalid" }; // Call using (var control = new WellKnownMapDataControl(activeWellKnownTileSourceMapData)) { // Assert Assert.IsNull(control.SelectedMapData); } }
public void ClearConfiguration_WithFailedLayerInitializationAndExpectingRecreation_ConfigurationClearedButKeepFailedFlagSet() { // Setup using (var layerStatus = new WellKnownBackgroundLayerStatus()) { var mapData = new WellKnownTileSourceMapData(new Random(465).NextEnum <WellKnownTileSource>()); layerStatus.LayerInitializationFailed(); // Call layerStatus.ClearConfiguration(true); // Assert Assert.IsTrue(layerStatus.PreviousBackgroundLayerCreationFailed); Assert.IsFalse(layerStatus.HasSameConfiguration(mapData)); } }
public void WellKnownMapDataControl_WithData_DataGridViewCorrectlyInitialized() { // Setup var random = new Random(124); var selectedWellKnownTileSourceMapData = new WellKnownTileSourceMapData(random.NextEnumValue <WellKnownTileSource>()); using (var form = new Form()) { // Call using (var control = new WellKnownMapDataControl(selectedWellKnownTileSourceMapData)) { form.Controls.Add(control); // Assert var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; DataGridViewRowCollection rows = dataGridViewControl.Rows; Assert.AreEqual(6, rows.Count); string[] blaat = { "Bing Maps - Satelliet", "Bing Maps - Satelliet + Wegen", "Bing Maps - Wegen", "Esri World - Reliëf", "Esri World - Topografisch", "OpenStreetMap" }; string selectedWellKnownTileSourceMapDataDisplayName = TypeUtils.GetDisplayName(selectedWellKnownTileSourceMapData.TileSource); int expectedIndex = -1; for (var index = 0; index < blaat.Length; index++) { DataGridViewCellCollection cells = rows[index].Cells; Assert.AreEqual(1, cells.Count); Assert.AreEqual(blaat[index], cells[0].FormattedValue); if (selectedWellKnownTileSourceMapDataDisplayName.Equals(cells[0].FormattedValue)) { expectedIndex = index; } } DataGridViewRow currentRow = dataGridViewControl.CurrentRow; Assert.IsNotNull(currentRow); Assert.AreEqual(expectedIndex, currentRow.Cells[0].RowIndex); } } }
public void Constructor_ValidValues_ExpectedValues() { // Setup const WellKnownTileSource value = WellKnownTileSource.BingAerial; // Call var mapData = new WellKnownTileSourceMapData(value); // Assert Assert.IsInstanceOf <ImageBasedMapData>(mapData); Assert.AreEqual("Bing Maps - Satelliet", mapData.Name); Assert.IsTrue(mapData.IsVisible); Assert.IsTrue(mapData.IsConfigured); Assert.AreEqual(0, mapData.Transparency.Value); Assert.AreEqual(value, mapData.TileSource); }
private void PreSelectDataGridView(WellKnownTileSourceMapData activeWellKnownTileSourceMapData) { if (activeWellKnownTileSourceMapData == null) { return; } DataGridViewRow dataGridViewRow = dataGridViewControl.Rows.OfType <DataGridViewRow>() .FirstOrDefault(row => IsMatch((WellKnownTileSourceMapData)row.DataBoundItem, activeWellKnownTileSourceMapData)); if (dataGridViewRow == null) { return; } DataGridViewCell cell = dataGridViewControl.GetCell(dataGridViewRow.Index, 0); dataGridViewControl.SetCurrentCell(cell); }
public void CreateInitializedConfiguration_ValidWellKnownMapData_ReturnWellKnownTileSourceLayerConfiguration() { // Setup var wellKnownMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); using (new UseCustomSettingsHelper(new TestSettingsHelper { ApplicationLocalUserSettingsDirectory = Path.Combine(TestHelper.GetScratchPadPath(), nameof(BrutileConfigurationFactoryTest)) })) using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(BrutileConfigurationFactoryTest))) using (new UseCustomTileSourceFactoryConfig(wellKnownMapData)) { // Call IConfiguration configuration = BrutileConfigurationFactory.CreateInitializedConfiguration(wellKnownMapData); // Assert Assert.IsInstanceOf <WellKnownTileSourceLayerConfiguration>(configuration); Assert.IsTrue(configuration.Initialized); } }
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 CreateInitializedConfiguration_WellKnownTileSourceFactoryThrowsNotSupportedException_ThrowConfigurationInitializationException() { // Setup var factoryThrowingNotSupportedException = MockRepository.GenerateStub <ITileSourceFactory>(); factoryThrowingNotSupportedException.Stub(f => f.GetKnownTileSource(Arg <KnownTileSource> .Is.NotNull)) .Throw(new NotSupportedException()); using (new UseCustomTileSourceFactoryConfig(factoryThrowingNotSupportedException)) { var wellKnownMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); // Call TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(wellKnownMapData); // Assert var exception = Assert.Throws <ConfigurationInitializationException>(test); Assert.IsInstanceOf <NotSupportedException>(exception.InnerException); Assert.AreEqual("Verbinden met 'Bing Maps - Satelliet' is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.", exception.Message); } }
public void ClearConfiguration_HasLayer_ConfigurationCleared() { // Setup var mocks = new MockRepository(); var tileFetcher = mocks.Stub <ITileFetcher>(); IConfiguration configuration = CreateStubConfiguration(mocks, tileFetcher); mocks.ReplayAll(); using (var layer = new BruTileLayer(configuration)) using (var layerStatus = new WellKnownBackgroundLayerStatus()) { var mapData = new WellKnownTileSourceMapData(new Random(789).NextEnum <WellKnownTileSource>()); layerStatus.LayerInitializationSuccessful(layer, mapData); // Call layerStatus.ClearConfiguration(); // Assert Assert.IsFalse(layerStatus.PreviousBackgroundLayerCreationFailed); Assert.IsFalse(layerStatus.HasSameConfiguration(mapData)); } }
private static IEnumerable <TestCaseData> ValidBackgroundDatas() { var wellKnownMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingRoads); WmtsMapData wmtsMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData(); yield return(new TestCaseData( new BackgroundData(new TestBackgroundDataConfiguration())) .SetName("Arbitrary BackgroundData Configuration")); yield return(new TestCaseData( new BackgroundData(new WellKnownBackgroundDataConfiguration((RiskeerWellKnownTileSource)wellKnownMapData.TileSource)) { Name = wellKnownMapData.Name }).SetName("WellKnown BingRoads BackgroundData")); yield return(new TestCaseData(new BackgroundData(new WmtsBackgroundDataConfiguration(wmtsMapData.IsConfigured, wmtsMapData.SourceCapabilitiesUrl, wmtsMapData.SelectedCapabilityIdentifier, wmtsMapData.PreferredFormat)) { Name = wmtsMapData.Name }).SetName("Wmts DefaultPdok BackgroundData")); }
public void SelectedMapData_DifferentRowSelected_UpdatesSelectedMapData() { // Setup var selectedWellKnownTileSourceMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); var selectionChanged = 0; using (var form = new Form()) using (var control = new WellKnownMapDataControl(selectedWellKnownTileSourceMapData)) { form.Controls.Add(control); var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; dataGridViewControl.CurrentRowChanged += (sender, args) => selectionChanged++; DataGridViewRow row = dataGridViewControl.GetRowFromIndex(2); dataGridViewControl.SetCurrentCell(row.Cells[0]); // Call ImageBasedMapData actualImageBasedMapData = control.SelectedMapData; // Assert AssertAreEqual(row.DataBoundItem as WellKnownTileSourceMapData, actualImageBasedMapData); Assert.AreEqual(1, selectionChanged); } }
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(); }
private static bool IsMatch(WellKnownTileSourceMapData mapData, WellKnownTileSourceMapData otherMapData) { return(mapData.TileSource == otherMapData.TileSource && string.Equals(mapData.Name, otherMapData.Name)); }
private void SetWellKnownTileSource(WellKnownTileSourceMapData wellKnownMapData) { wellKnownTileSource = new TestWellKnownTileSource(wellKnownMapData); }
/// <summary> /// Create a new instance of <see cref="TestWellKnownTileSource"/> suitable to work for /// a given <see cref="WellKnownTileSourceMapData"/>. /// </summary> /// <param name="mapData">The map data to work with.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="mapData"/> is <c>null</c>.</exception> public TestWellKnownTileSource(WellKnownTileSourceMapData mapData) : base(CreateTileSchema(mapData), new WellKnownRequestStub(), "Stub schema", null, GetStubTile) { }
/// <summary> /// Creates a new initialized <see cref="WellKnownTileSourceLayerConfiguration"/>. /// </summary> /// <param name="wellKnownBackgroundMapData">The <see cref="WellKnownTileSourceMapData"/> /// to create the configuration for.</param> /// <returns>A new initialized <see cref="WellKnownTileSourceLayerConfiguration"/>.</returns> /// <exception cref="ConfigurationInitializationException">Thrown when the configuration /// can't connect with the tile service or creating the file cache failed.</exception> private static WellKnownTileSourceLayerConfiguration CreateInitializedConfiguration(WellKnownTileSourceMapData wellKnownBackgroundMapData) { try { return(WellKnownTileSourceLayerConfiguration.CreateInitializedConfiguration(wellKnownBackgroundMapData.TileSource)); } catch (NotSupportedException e) { string tileDisplayName; try { tileDisplayName = TypeUtils.GetDisplayName(wellKnownBackgroundMapData.TileSource); } catch (InvalidEnumArgumentException) { tileDisplayName = wellKnownBackgroundMapData.TileSource.ToString(); } throw new ConfigurationInitializationException( string.Format(Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Connect_to_TileSourceName_0_failed, tileDisplayName), e); } catch (CannotCreateTileCacheException e) { throw new ConfigurationInitializationException( Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Persistent_cache_creation_failed, e); } }
private static WellKnownBackgroundDataConfiguration CreateWellKnownBackgroundDataConfiguration(WellKnownTileSourceMapData mapData) { return(new WellKnownBackgroundDataConfiguration((RiskeerWellKnownTileSource)mapData.TileSource)); }