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 GivenBackgroundData_WhenBackgroundDataChangedButSameTypeAndNotified_ThenBackgroundMapDataUpdatedAndNotified()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            WmtsMapData    mapData           = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            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.Transparency = (RoundedDouble)0.3;
                    backgroundData.NotifyObservers();

                    // Then
                    Assert.AreSame(oldBackgroundMapData, riskeerMapControl.MapControl.BackgroundMapData);
                    Assert.AreEqual(0.3, riskeerMapControl.MapControl.BackgroundMapData.Transparency.Value);
                    mocks.VerifyAll();
                }
        }
        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
                }
        }
        public void GivenConfiguredWmtsBackgroundData_WhenWmtsConfigurationSetToFalseAndNotified_ThenBackgroundMapDataConfigurationRemovedAndNotified()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            WmtsMapData    mapData           = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            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 WmtsBackgroundDataConfiguration();
                    backgroundData.NotifyObservers();

                    // Then
                    Assert.AreSame(oldBackgroundMapData, riskeerMapControl.MapControl.BackgroundMapData);

                    var newWmtsMapData = (WmtsMapData)riskeerMapControl.MapControl.BackgroundMapData;
                    Assert.IsNull(newWmtsMapData.SourceCapabilitiesUrl);
                    Assert.IsNull(newWmtsMapData.SelectedCapabilityIdentifier);
                    Assert.IsNull(newWmtsMapData.PreferredFormat);
                    mocks.VerifyAll();
                }
        }