コード例 #1
0
        public void CreateInitializedConfiguration_LayerIdNotInWmts_ThrowCannotFindTileSourceException()
        {
            // Setup
            const string url     = "url";
            const string id      = "id";
            var          mocks   = new MockRepository();
            var          factory = mocks.Stub <ITileSourceFactory>();

            factory.Stub(f => f.GetWmtsTileSources(url)).Return(Enumerable.Empty <ITileSource>());
            mocks.ReplayAll();

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(factory))
                {
                    // Call
                    TestDelegate call = () => WmtsLayerConfiguration.CreateInitializedConfiguration(url, id, validPreferredFormat);

                    // Assert
                    string message         = Assert.Throws <CannotFindTileSourceException>(call).Message;
                    string expectedMessage = $"Niet in staat om de databron met naam '{id}' te kunnen vinden bij de WMTS URL '{url}'.";
                    Assert.AreEqual(expectedMessage, message);
                }

            mocks.VerifyAll();
        }
コード例 #2
0
        public void CreateInitializedConfiguration_CapabilityIdNull_ThrowArgumentNullException()
        {
            // Call
            TestDelegate call = () => WmtsLayerConfiguration.CreateInitializedConfiguration("A", null, validPreferredFormat);

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

            Assert.AreEqual("capabilityIdentifier", paramName);
        }
コード例 #3
0
        public void CreateInitializedConfiguration_PreferredFormatNull_ThrowArgumentNullException()
        {
            // Call
            TestDelegate call = () => WmtsLayerConfiguration.CreateInitializedConfiguration("A", "B", null);

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

            Assert.AreEqual("preferredFormat", paramName);
        }
コード例 #4
0
        public void CreateInitializedConfiguration_PreferredFormatNotMime_ThrowArgumentNullException()
        {
            // Call
            TestDelegate call = () => WmtsLayerConfiguration.CreateInitializedConfiguration("A", "B", "png");

            // Assert
            const string message   = "Afbeelding formaat moet opgegeven worden als MIME-type.";
            string       paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message).ParamName;

            Assert.AreEqual("preferredFormat", paramName);
        }
コード例 #5
0
        public void CreateInitializedConfiguration_CannotCreateCache_ThrowCannotCreateCacheException()
        {
            // Setup
            WmtsMapData targetMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();

            var tileSource = new HttpTileSource(TileSchemaFactory.CreateWmtsTileSchema(targetMapData),
                                                (IRequest)null);

            var mocks   = new MockRepository();
            var factory = mocks.Stub <ITileSourceFactory>();

            factory.Stub(f => f.GetWmtsTileSources(targetMapData.SourceCapabilitiesUrl))
            .Return(new[]
            {
                tileSource
            });
            mocks.ReplayAll();

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(factory))
                {
                    directoryDisposeHelper.LockDirectory(FileSystemRights.Write);

                    // Call
                    TestDelegate call = () => WmtsLayerConfiguration.CreateInitializedConfiguration(targetMapData.SourceCapabilitiesUrl,
                                                                                                    targetMapData.SelectedCapabilityIdentifier,
                                                                                                    targetMapData.PreferredFormat);

                    try
                    {
                        // Assert
                        string       message         = Assert.Throws <CannotCreateTileCacheException>(call).Message;
                        const string expectedMessage = "Een kritieke fout is opgetreden bij het aanmaken van de cache.";
                        Assert.AreEqual(expectedMessage, message);
                    }
                    finally
                    {
                        directoryDisposeHelper.UnlockDirectory();
                    }
                }

            mocks.VerifyAll();
        }
コード例 #6
0
 /// <summary>
 /// Creates a new initialized <see cref="PersistentCacheConfiguration"/>.
 /// </summary>
 /// <param name="wmtsBackgroundMapData">The <see cref="WmtsMapData"/>
 /// to create the configuration for.</param>
 /// <returns>A new initialized <see cref="PersistentCacheConfiguration"/>.</returns>
 /// <exception cref="ConfigurationInitializationException">Thrown when the configuration
 /// can't connect with the tile service or creating the file cache failed.</exception>
 private static PersistentCacheConfiguration CreateInitializedConfiguration(WmtsMapData wmtsBackgroundMapData)
 {
     try
     {
         return(WmtsLayerConfiguration.CreateInitializedConfiguration(wmtsBackgroundMapData.SourceCapabilitiesUrl,
                                                                      wmtsBackgroundMapData.SelectedCapabilityIdentifier,
                                                                      wmtsBackgroundMapData.PreferredFormat));
     }
     catch (Exception e) when(e is CannotFindTileSourceException || e is CannotReceiveTilesException)
     {
         throw new ConfigurationInitializationException(
                   Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Wmts_connection_failed,
                   e);
     }
     catch (CannotCreateTileCacheException e)
     {
         throw new ConfigurationInitializationException(
                   Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Persistent_cache_creation_failed,
                   e);
     }
 }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
        }