Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/BackgroundDataCreateExtensions.cs =================================================================== diff -u -r5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca -r2865b0fc522e96a2f12c47f29805b13259ecde4f --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/BackgroundDataCreateExtensions.cs (.../BackgroundDataCreateExtensions.cs) (revision 5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/BackgroundDataCreateExtensions.cs (.../BackgroundDataCreateExtensions.cs) (revision 2865b0fc522e96a2f12c47f29805b13259ecde4f) @@ -38,23 +38,14 @@ /// . /// /// The container to create a for. - /// The entity, or null if is not supported. + /// The created . internal static BackgroundDataEntity Create(this BackgroundData backgroundData) { if (backgroundData == null) { throw new ArgumentNullException(nameof(backgroundData)); } - - if (backgroundData.BackgroundMapDataType == BackgroundMapDataType.Wmts) - { - return CreateWithWmtsData(backgroundData); - } - return null; // TODO: WTI-1141 - } - private static BackgroundDataEntity CreateWithWmtsData(BackgroundData backgroundData) - { var entity = new BackgroundDataEntity { Name = backgroundData.Name.DeepClone(), @@ -67,7 +58,6 @@ { AddEntitiesForBackgroundDataMeta(backgroundData, entity); } - return entity; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/BackgroundDataEntityReadExtensions.cs =================================================================== diff -u -r5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca -r2865b0fc522e96a2f12c47f29805b13259ecde4f --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/BackgroundDataEntityReadExtensions.cs (.../BackgroundDataEntityReadExtensions.cs) (revision 5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/BackgroundDataEntityReadExtensions.cs (.../BackgroundDataEntityReadExtensions.cs) (revision 2865b0fc522e96a2f12c47f29805b13259ecde4f) @@ -64,7 +64,7 @@ { KeyValuePair parameter = backgroundDataMetaEntity.Read(); - if (ValidKey(parameter.Key)) + if (ValidKey(parameter.Key, backgroundData.BackgroundMapDataType)) { backgroundData.Parameters[parameter.Key] = parameter.Value; } @@ -74,11 +74,13 @@ return backgroundData; } - private static bool ValidKey(string keyToValidate) + private static bool ValidKey(string keyToValidate, BackgroundMapDataType backgroundMapDataType) { - return keyToValidate == BackgroundDataIdentifiers.SourceCapabilitiesUrl - || keyToValidate == BackgroundDataIdentifiers.SelectedCapabilityIdentifier - || keyToValidate == BackgroundDataIdentifiers.PreferredFormat; + return backgroundMapDataType == BackgroundMapDataType.Wmts + ? keyToValidate == BackgroundDataIdentifiers.SourceCapabilitiesUrl + || keyToValidate == BackgroundDataIdentifiers.SelectedCapabilityIdentifier + || keyToValidate == BackgroundDataIdentifiers.PreferredFormat + : keyToValidate == BackgroundDataIdentifiers.WellKnownTileSource; } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/BackgroundDataCreateExtensionsTest.cs =================================================================== diff -u -r5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca -r2865b0fc522e96a2f12c47f29805b13259ecde4f --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/BackgroundDataCreateExtensionsTest.cs (.../BackgroundDataCreateExtensionsTest.cs) (revision 5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/BackgroundDataCreateExtensionsTest.cs (.../BackgroundDataCreateExtensionsTest.cs) (revision 2865b0fc522e96a2f12c47f29805b13259ecde4f) @@ -25,7 +25,6 @@ using Core.Common.Base.Data; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Data.TestUtil; namespace Application.Ringtoets.Storage.Test.Create { @@ -49,7 +48,7 @@ [Test] [TestCase(true)] [TestCase(false)] - public void Create_BackgroundDataWithTypeWmts_ReturnsBackgroundMapDataEntity(bool isConfigured) + public void Create_Always_ReturnsBackgroundMapDataEntity(bool isConfigured) { // Setup const string name = "background"; @@ -109,18 +108,5 @@ CollectionAssert.IsEmpty(entity.BackgroundDataMetaEntities); } } - - [Test] - public void Create_BackgroundDataTypeWellKnown_ReturnsNull() - { - // Setup - var backgroundData = BackgroundDataTestDataGenerator.GetWellKnownBackgroundMapData(); - - // Call - BackgroundDataEntity entity = backgroundData.Create(); - - // Assert - Assert.IsNull(entity); // TODO: WTI-1141 - } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/BackgroundDataEntityReadExtensionsTest.cs =================================================================== diff -u -r5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca -r2865b0fc522e96a2f12c47f29805b13259ecde4f --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/BackgroundDataEntityReadExtensionsTest.cs (.../BackgroundDataEntityReadExtensionsTest.cs) (revision 5a5fe803bd7b9feef47a3ff1b0dac3fa42309aca) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/BackgroundDataEntityReadExtensionsTest.cs (.../BackgroundDataEntityReadExtensionsTest.cs) (revision 2865b0fc522e96a2f12c47f29805b13259ecde4f) @@ -46,7 +46,7 @@ } [Test] - public void Read_WithEntity_ReturnBackgroundData() + public void Read_EntityWithWmtsData_ReturnBackgroundData() { // Setup const string name = "map data"; @@ -56,8 +56,9 @@ const bool isVisible = false; const double transparancy = 0.4; const bool isConfigured = true; - const BackgroundMapDataType backgroundMapDataType = BackgroundMapDataType.Wmts; + BackgroundMapDataType backgroundMapDataType = BackgroundMapDataType.Wmts; + var entity = new BackgroundDataEntity { Name = name, @@ -101,6 +102,48 @@ } [Test] + public void Read_EntityWithWellKnownData_ReturnBackgroundData() + { + // Setup + const string name = "map data"; + const bool isVisible = false; + const double transparancy = 0.4; + const bool isConfigured = true; + + BackgroundMapDataType backgroundMapDataType = BackgroundMapDataType.WellKnown; + var enumNumber = (int) backgroundMapDataType; + + var entity = new BackgroundDataEntity + { + Name = name, + BackgroundDataMetaEntities = new List + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.WellKnownTileSource, + Value = enumNumber.ToString() + } + }, + IsVisible = Convert.ToByte(isVisible), + Transparency = transparancy, + IsConfigured = Convert.ToByte(isConfigured), + BackgroundDataType = Convert.ToByte(backgroundMapDataType) + }; + + // Call + BackgroundData backgroundData = entity.Read(); + + // Assert + Assert.AreEqual(isVisible, backgroundData.IsVisible); + Assert.AreEqual(transparancy, backgroundData.Transparency.Value); + + Assert.AreEqual(name, backgroundData.Name); + Assert.AreEqual(enumNumber, Convert.ToInt32(backgroundData.Parameters[BackgroundDataIdentifiers.WellKnownTileSource])); + Assert.AreEqual(isConfigured, backgroundData.IsConfigured); + Assert.AreEqual(backgroundMapDataType, backgroundData.BackgroundMapDataType); + } + + [Test] public void Read_IsConfiguredFalse_NoParametersAdded() { // Setup @@ -138,33 +181,72 @@ } [Test] - public void Read_BackgroundDataMetaEntityKeyNotValid_MetaDataNotAddedToBackgroundData() + [TestCase(BackgroundMapDataType.Wmts)] + [TestCase(BackgroundMapDataType.WellKnown)] + public void Read_BackgroundDataMetaEntityKeyNotValid_MetaDataNotAddedToBackgroundData(BackgroundMapDataType backgroundMapDataType) { // Setup + const string invalidKey = "some key"; + var entity = new BackgroundDataEntity { BackgroundDataMetaEntities = new List { new BackgroundDataMetaEntity { - Key = "some key", + Key = invalidKey, Value = "//url" }, new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, - Value = "capability name" + Value = "SelectedCapabilityIdentifier" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl, + Value = "SourceCapabilitiesUrl" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.PreferredFormat, + Value = "PreferredFormat" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.WellKnownTileSource, + Value = "WellKnownTileSource" } }, - IsConfigured = Convert.ToByte(true) + IsConfigured = Convert.ToByte(true), + BackgroundDataType = Convert.ToByte(backgroundMapDataType) }; // Call BackgroundData backgroundData = entity.Read(); // Assert - Assert.AreEqual(1, backgroundData.Parameters.Count); - CollectionAssert.DoesNotContain(backgroundData.Parameters, "some key"); + var addedKeys = new List(); + foreach (KeyValuePair backgroundDataParameter in backgroundData.Parameters) + { + addedKeys.Add(backgroundDataParameter.Key); + } + + if (backgroundMapDataType == BackgroundMapDataType.Wmts) + { + Assert.AreEqual(3, backgroundData.Parameters.Count); + + CollectionAssert.Contains(addedKeys, BackgroundDataIdentifiers.SourceCapabilitiesUrl); + CollectionAssert.Contains(addedKeys, BackgroundDataIdentifiers.SelectedCapabilityIdentifier); + CollectionAssert.Contains(addedKeys, BackgroundDataIdentifiers.PreferredFormat); + } + else if (backgroundMapDataType == BackgroundMapDataType.WellKnown) + { + Assert.AreEqual(1, backgroundData.Parameters.Count); + CollectionAssert.Contains(addedKeys, BackgroundDataIdentifiers.WellKnownTileSource); + } + + CollectionAssert.DoesNotContain(addedKeys, invalidKey); } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/BackgroundDataIdentifiers.cs =================================================================== diff -u -rb50726abfd7d4bbda64385e9c7b2c781d2c594ed -r2865b0fc522e96a2f12c47f29805b13259ecde4f --- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/BackgroundDataIdentifiers.cs (.../BackgroundDataIdentifiers.cs) (revision b50726abfd7d4bbda64385e9c7b2c781d2c594ed) +++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/BackgroundDataIdentifiers.cs (.../BackgroundDataIdentifiers.cs) (revision 2865b0fc522e96a2f12c47f29805b13259ecde4f) @@ -40,5 +40,10 @@ /// The identifier for the preferred format. /// public const string PreferredFormat = "PreferredFormat"; + + /// + /// The identifier for the well known tile source. + /// + public const string WellKnownTileSource = "WellKnownTileSource"; } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/BackgroundDataIdentifiersTest.cs =================================================================== diff -u -rb50726abfd7d4bbda64385e9c7b2c781d2c594ed -r2865b0fc522e96a2f12c47f29805b13259ecde4f --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/BackgroundDataIdentifiersTest.cs (.../BackgroundDataIdentifiersTest.cs) (revision b50726abfd7d4bbda64385e9c7b2c781d2c594ed) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/BackgroundDataIdentifiersTest.cs (.../BackgroundDataIdentifiersTest.cs) (revision 2865b0fc522e96a2f12c47f29805b13259ecde4f) @@ -33,6 +33,7 @@ Assert.AreEqual("SourceCapabilitiesUrl", BackgroundDataIdentifiers.SourceCapabilitiesUrl); Assert.AreEqual("SelectedCapabilityIdentifier", BackgroundDataIdentifiers.SelectedCapabilityIdentifier); Assert.AreEqual("PreferredFormat", BackgroundDataIdentifiers.PreferredFormat); + Assert.AreEqual("WellKnownTileSource", BackgroundDataIdentifiers.WellKnownTileSource); } } } \ No newline at end of file