Index: Core/Components/test/Core.Components.BruTile.TestUtil.Test/Core.Components.BruTile.TestUtil.Test.csproj =================================================================== diff -u -r99f9004206bfb9de084275d749b7aeccafd6da18 -r6e700ec6ce8242c0c41a3c1028729995981ea44b --- Core/Components/test/Core.Components.BruTile.TestUtil.Test/Core.Components.BruTile.TestUtil.Test.csproj (.../Core.Components.BruTile.TestUtil.Test.csproj) (revision 99f9004206bfb9de084275d749b7aeccafd6da18) +++ Core/Components/test/Core.Components.BruTile.TestUtil.Test/Core.Components.BruTile.TestUtil.Test.csproj (.../Core.Components.BruTile.TestUtil.Test.csproj) (revision 6e700ec6ce8242c0c41a3c1028729995981ea44b) @@ -61,6 +61,7 @@ + Index: Core/Components/test/Core.Components.BruTile.TestUtil.Test/TestWellKnownTileSourceTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.BruTile.TestUtil.Test/TestWellKnownTileSourceTest.cs (revision 0) +++ Core/Components/test/Core.Components.BruTile.TestUtil.Test/TestWellKnownTileSourceTest.cs (revision 6e700ec6ce8242c0c41a3c1028729995981ea44b) @@ -0,0 +1,101 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Drawing; +using System.IO; +using BruTile; +using BruTile.Web; +using Core.Common.TestUtil; +using Core.Components.Gis.Data; +using NUnit.Framework; + +namespace Core.Components.BruTile.TestUtil.Test +{ + [TestFixture] + public class TestWellKnownTileSourceTest + { + [Test] + public void Constructor_NullWellKnownMapData_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new TestWellKnownTileSource(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("mapData", paramName); + } + + [Test] + public void Constructor_WellKnownMapData_ExpectedValues() + { + // Setup + var mapData = new WellKnownTileSourceMapData(new Random(6754).NextEnumValue()); + + // Call + var source = new TestWellKnownTileSource(mapData); + + // Assert + Assert.IsInstanceOf(source); + Assert.AreEqual("Stub schema", source.Name); + Assert.IsNotNull(source.Attribution); + Assert.IsNotNull(source.PersistentCache); + + ITileSchema wellKnownSchema = source.Schema; + Assert.AreEqual(mapData.Name, wellKnownSchema.Name); + Assert.AreEqual("png", wellKnownSchema.Format); + Assert.AreEqual(YAxis.TMS, wellKnownSchema.YAxis); + } + + [Test] + public void GetTile_ForAnyTileInfo_ReturnsStubTileData() + { + // Setup + var mapData = new WellKnownTileSourceMapData(new Random(6754).NextEnumValue()); + var source = new TestWellKnownTileSource(mapData); + + // Call + byte[] tileData = source.GetTile(new TileInfo()); + + // Assert + using (var stream = new MemoryStream(tileData)) + using (var tileImage = new Bitmap(stream)) + { + Assert.AreEqual(256, tileImage.Width); + Assert.AreEqual(256, tileImage.Height); + } + } + + [Test] + public void GetUri_ForAnyTileInfo_ReturnStubUrl() + { + // Setup + var mapData = new WellKnownTileSourceMapData(new Random(6754).NextEnumValue()); + var source = new TestWellKnownTileSource(mapData); + + // Call + Uri url = source.GetUri(new TileInfo()); + + // Assert + Assert.AreEqual(@"https://www.stub.org/tiles/someTile.png", url.ToString()); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.BruTile.TestUtil/Core.Components.BruTile.TestUtil.csproj =================================================================== diff -u -r99f9004206bfb9de084275d749b7aeccafd6da18 -r6e700ec6ce8242c0c41a3c1028729995981ea44b --- Core/Components/test/Core.Components.BruTile.TestUtil/Core.Components.BruTile.TestUtil.csproj (.../Core.Components.BruTile.TestUtil.csproj) (revision 99f9004206bfb9de084275d749b7aeccafd6da18) +++ Core/Components/test/Core.Components.BruTile.TestUtil/Core.Components.BruTile.TestUtil.csproj (.../Core.Components.BruTile.TestUtil.csproj) (revision 6e700ec6ce8242c0c41a3c1028729995981ea44b) @@ -58,6 +58,7 @@ True + Index: Core/Components/test/Core.Components.BruTile.TestUtil/TestWellKnownTileSource.cs =================================================================== diff -u --- Core/Components/test/Core.Components.BruTile.TestUtil/TestWellKnownTileSource.cs (revision 0) +++ Core/Components/test/Core.Components.BruTile.TestUtil/TestWellKnownTileSource.cs (revision 6e700ec6ce8242c0c41a3c1028729995981ea44b) @@ -0,0 +1,86 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Drawing.Imaging; +using System.IO; +using BruTile; +using BruTile.Predefined; +using BruTile.Web; +using Core.Components.BruTile.TestUtil.Properties; +using Core.Components.Gis.Data; + +namespace Core.Components.BruTile.TestUtil +{ + /// + /// Defines an suitable to most unit test cases related to + /// dealing with . + /// + public class TestWellKnownTileSource : HttpTileSource + { + private static byte[] pngTileDataStub; + + /// + /// Create a new instance of suitable to work for + /// a given . + /// + /// The map data to work with. + /// Thrown when is null. + public TestWellKnownTileSource(WellKnownTileSourceMapData mapData) + : base(CreateTileSchema(mapData), new WellKnownRequestStub(), "Stub schema", null, GetStubTile) {} + + /// + /// Create a new tile schema. + /// + /// The map data to work with. + /// The new tile schema. + /// Thrown when is null. + 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 byte[] GetStubTile(Uri url) + { + if (pngTileDataStub == null) + { + using (var stream = new MemoryStream()) + { + Resources.stubTile.Save(stream, ImageFormat.Png); + pngTileDataStub = stream.ToArray(); + } + } + return pngTileDataStub; + } + + private class WellKnownRequestStub : IRequest + { + public Uri GetUri(TileInfo info) + { + return new Uri(@"https://www.stub.org/tiles/someTile.png"); + } + } + } +} \ No newline at end of file