private void UpdateBackgroundMapData() { ImageBasedMapData newData = BackgroundDataConverter.ConvertFrom(backgroundData); if (backgroundData.Configuration is WmtsBackgroundDataConfiguration) { if (newData.IsConfigured) { var newWmtsData = (WmtsMapData)newData; ((WmtsMapData)mapControl.BackgroundMapData).Configure(newWmtsData.SourceCapabilitiesUrl, newWmtsData.SelectedCapabilityIdentifier, newWmtsData.PreferredFormat); } else { ((WmtsMapData)mapControl.BackgroundMapData).RemoveConfiguration(); } } else if (backgroundData.Configuration is WellKnownBackgroundDataConfiguration) { ((WellKnownTileSourceMapData)mapControl.BackgroundMapData).SetTileSource(((WellKnownTileSourceMapData)newData).TileSource); } mapControl.BackgroundMapData.IsVisible = newData.IsVisible; mapControl.BackgroundMapData.Name = newData.Name; mapControl.BackgroundMapData.Transparency = newData.Transparency; }
public void ConvertFrom_BackgroundDataNull_ThrowArgumentNullException() { // Call TestDelegate test = () => BackgroundDataConverter.ConvertFrom(null); // Assert var exception = Assert.Throws <ArgumentNullException>(test); Assert.AreEqual("backgroundData", exception.ParamName); }
public void ConvertFrom_BackgroundDataWithInvalidWellKnownTileSourceValue_ThrowsInvalidEnumArgumentException() { // Setup var backgroundData = new BackgroundData(new WellKnownBackgroundDataConfiguration((RiskeerWellKnownTileSource)999)); // Call TestDelegate call = () => BackgroundDataConverter.ConvertFrom(backgroundData); // Assert Assert.Throws <InvalidEnumArgumentException>(call); }
public void ConvertFrom_BackgroundData_ReturnWmtsMapData(WmtsMapData mapData) { // Setup BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData); // Call ImageBasedMapData convertedMapData = BackgroundDataConverter.ConvertFrom(backgroundData); // Assert MapDataTestHelper.AssertImageBasedMapData(backgroundData, convertedMapData); }
public void ConvertFrom_BackgroundData_ReturnWellKnownMapData() { // Setup var random = new Random(21); var wellKnownTileSource = random.NextEnumValue <WellKnownTileSource>(); BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(new WellKnownTileSourceMapData(wellKnownTileSource)); // Call ImageBasedMapData convertedMapData = BackgroundDataConverter.ConvertFrom(backgroundData); // Assert MapDataTestHelper.AssertImageBasedMapData(backgroundData, convertedMapData); }
private void OnBackgroundDataUpdated() { if (backgroundData.Configuration is WmtsBackgroundDataConfiguration && mapControl.BackgroundMapData is WmtsMapData || backgroundData.Configuration is WellKnownBackgroundDataConfiguration && mapControl.BackgroundMapData is WellKnownTileSourceMapData) { UpdateBackgroundMapData(); mapControl.BackgroundMapData.NotifyObservers(); } else { mapControl.BackgroundMapData = BackgroundDataConverter.ConvertFrom(backgroundData); } }
public void ConvertFrom_ConfigurationTypeNotSupportedForConversion_ThrowNotSupportedException() { // Setup var backgroundData = new BackgroundData(new TestBackgroundDataConfiguration()); // Call TestDelegate test = () => BackgroundDataConverter.ConvertFrom(backgroundData); // Assert var exception = Assert.Throws <NotSupportedException>(test); string expectedMessage = $"Can't create a image based map data for {typeof(TestBackgroundDataConfiguration)}."; Assert.AreEqual(expectedMessage, exception.Message); }
/// <summary> /// Sets all data to the control. /// </summary> /// <param name="data">The <see cref="MapDataCollection"/> to set to the control.</param> /// <param name="background">The <see cref="BackgroundData"/> to set to the control.</param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters is <c>null</c>.</exception> public void SetAllData(MapDataCollection data, BackgroundData background) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (background == null) { throw new ArgumentNullException(nameof(background)); } backgroundData = background; backgroundDataObserver.Observable = backgroundData; mapControl.Data = data; mapControl.BackgroundMapData = BackgroundDataConverter.ConvertFrom(backgroundData); }
public void GivenBackgroundData_WhenBackgroundDataChangedToOtherTypeAndNotified_ThenNewInstanceSetOnBackgroundMapData( BackgroundData originalBackgroundData, BackgroundData newBackgroundData) { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); mocks.ReplayAll(); using (new UseCustomSettingsHelper(testSettingsHelper)) using (new UseCustomTileSourceFactoryConfig(new TestTileSourceFactory(BackgroundDataConverter.ConvertFrom(originalBackgroundData)))) { var riskeerMapControl = new RiskeerMapControl(); var mapDataCollection = new MapDataCollection("Collection"); riskeerMapControl.SetAllData(mapDataCollection, originalBackgroundData); riskeerMapControl.MapControl.BackgroundMapData.Attach(observer); ImageBasedMapData oldMapData = riskeerMapControl.MapControl.BackgroundMapData; // When originalBackgroundData.Name = newBackgroundData.Name; originalBackgroundData.IsVisible = newBackgroundData.IsVisible; originalBackgroundData.Transparency = newBackgroundData.Transparency; originalBackgroundData.Configuration = newBackgroundData.Configuration; originalBackgroundData.NotifyObservers(); // Then Assert.IsNotNull(riskeerMapControl.MapControl.BackgroundMapData); Assert.AreNotSame(oldMapData, riskeerMapControl.MapControl.BackgroundMapData); Assert.AreNotEqual(oldMapData.GetType(), riskeerMapControl.MapControl.BackgroundMapData.GetType()); mocks.VerifyAll(); // Expect no observers notified } }