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 RemoveAllData_Always_RemovesAllDataFromMapControl()
        {
            // Setup
            var            mapDataCollection = new MapDataCollection("Collection");
            WmtsMapData    backgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(backgroundMapData);

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(backgroundMapData))
                    using (var riskeerMapControl = new RiskeerMapControl())
                    {
                        riskeerMapControl.SetAllData(mapDataCollection, backgroundData);

                        // Precondition
                        Assert.IsNotNull(riskeerMapControl.MapControl.Data);
                        Assert.IsNotNull(riskeerMapControl.MapControl.BackgroundMapData);

                        // Call
                        riskeerMapControl.RemoveAllData();

                        // Assert
                        Assert.IsNull(riskeerMapControl.MapControl.Data);
                        Assert.IsNull(riskeerMapControl.MapControl.BackgroundMapData);
                    }
        }
        public void SetAllData_BackgroundDataNull_ThrowsArgumentNullException()
        {
            // Setup
            var riskeerMapControl = new RiskeerMapControl();
            var mapDataCollection = new MapDataCollection("Collection");

            // Call
            TestDelegate test = () => riskeerMapControl.SetAllData(mapDataCollection, null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(test).ParamName;

            Assert.AreEqual("background", paramName);
        }
        public void SetAllData_MapDataCollectionNull_ThrowsArgumentNullException()
        {
            // Setup
            var riskeerMapControl = new RiskeerMapControl();
            var backgroundData    = new BackgroundData(new TestBackgroundDataConfiguration());

            // Call
            TestDelegate test = () => riskeerMapControl.SetAllData(null, backgroundData);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(test).ParamName;

            Assert.AreEqual("data", paramName);
        }
        public void SetAllData_Always_SetsAllDataToMapControl()
        {
            // Setup
            var            mapDataCollection = new MapDataCollection("Collection");
            WmtsMapData    backgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(backgroundMapData);

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(backgroundMapData))
                    using (var riskeerMapControl = new RiskeerMapControl())
                    {
                        // Call
                        riskeerMapControl.SetAllData(mapDataCollection, backgroundData);

                        // Assert
                        Assert.AreSame(mapDataCollection, riskeerMapControl.MapControl.Data);
                        Assert.IsNotNull(riskeerMapControl.MapControl.BackgroundMapData);
                        MapDataTestHelper.AssertImageBasedMapData(backgroundData, riskeerMapControl.MapControl.BackgroundMapData);
                    }
        }
        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();
                }
        }