Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r40793165416093e9d2fefb6b12acf82fbd8a84c2 -r1c9b0e9cabaad22335799a442889c63bfc651e59 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 40793165416093e9d2fefb6b12acf82fbd8a84c2) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 1c9b0e9cabaad22335799a442889c63bfc651e59) @@ -326,7 +326,7 @@ - + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs =================================================================== diff -u -r40793165416093e9d2fefb6b12acf82fbd8a84c2 -r1c9b0e9cabaad22335799a442889c63bfc651e59 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision 40793165416093e9d2fefb6b12acf82fbd8a84c2) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision 1c9b0e9cabaad22335799a442889c63bfc651e59) @@ -79,10 +79,10 @@ AddEntityForHydraulicDatabase(section, entity, registry); AddEntityForReferenceLine(section, entity); - BackgroundDataEntity backgroundMapDataEntity = section.BackgroundData.Create(); - if (backgroundMapDataEntity != null) + BackgroundDataEntity backgroundDataEntity = section.BackgroundData.Create(); + if (backgroundDataEntity != null) { - entity.BackgroundDataEntities.Add(backgroundMapDataEntity); + entity.BackgroundDataEntities.Add(backgroundDataEntity); } entity.FailureMechanismEntities.Add(section.PipingFailureMechanism.Create(registry)); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs =================================================================== diff -u -r40793165416093e9d2fefb6b12acf82fbd8a84c2 -r1c9b0e9cabaad22335799a442889c63bfc651e59 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision 40793165416093e9d2fefb6b12acf82fbd8a84c2) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision 1c9b0e9cabaad22335799a442889c63bfc651e59) @@ -67,7 +67,7 @@ } }; - entity.ReadBackgroundMapData(assessmentSection); + entity.ReadBackgroundData(assessmentSection); entity.ReadHydraulicDatabase(assessmentSection, collector); entity.ReadReferenceLine(assessmentSection); @@ -108,7 +108,7 @@ GC.Collect(); } - private static void ReadBackgroundMapData(this AssessmentSectionEntity entity, IAssessmentSection assessmentSection) + private static void ReadBackgroundData(this AssessmentSectionEntity entity, IAssessmentSection assessmentSection) { BackgroundData backgroundData = entity.BackgroundDataEntities.Single().Read(); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/BackgroundDataEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/BackgroundDataEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/BackgroundDataEntityReadExtensions.cs (revision 1c9b0e9cabaad22335799a442889c63bfc651e59) @@ -0,0 +1,83 @@ +// 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 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 General Public License for more details. +// +// You should have received a copy of the GNU 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.Collections.Generic; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Data; +using Ringtoets.Common.Data.AssessmentSection; + +namespace Application.Ringtoets.Storage.Read +{ + /// + /// Extension methods for read operations for + /// based on the . + /// + internal static class BackgroundDataEntityReadExtensions + { + /// + /// Read the and use the information + /// to construct . + /// + /// The + /// to create for. + /// A new . + /// Thrown when + /// is null. + internal static BackgroundData Read(this BackgroundDataEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + var backgroundData = new BackgroundData + { + IsVisible = Convert.ToBoolean(entity.IsVisible), + Transparency = (RoundedDouble) entity.Transparency, + Name = entity.Name, + IsConfigured = Convert.ToBoolean(entity.IsConfigured) + }; + + if (backgroundData.IsConfigured) + { + foreach (BackgroundDataMetaEntity backgroundDataMetaEntity in entity.BackgroundDataMetaEntities) + { + KeyValuePair parameter = backgroundDataMetaEntity.Read(); + + if (ValidKey(parameter.Key)) + { + backgroundData.Parameters[parameter.Key] = parameter.Value; + } + } + } + + return backgroundData; + } + + private static bool ValidKey(string keyToValidate) + { + return keyToValidate == BackgroundDataIdentifiers.SourceCapabilitiesUrl + || keyToValidate == BackgroundDataIdentifiers.SelectedCapabilityIdentifier + || keyToValidate == BackgroundDataIdentifiers.PreferredFormat; + } + } +} \ No newline at end of file Fisheye: Tag 1c9b0e9cabaad22335799a442889c63bfc651e59 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Read/BackgroundMapDataEntityReadExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r40793165416093e9d2fefb6b12acf82fbd8a84c2 -r1c9b0e9cabaad22335799a442889c63bfc651e59 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 40793165416093e9d2fefb6b12acf82fbd8a84c2) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 1c9b0e9cabaad22335799a442889c63bfc651e59) @@ -127,7 +127,7 @@ - + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/BackgroundDataEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/BackgroundDataEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/BackgroundDataEntityReadExtensionsTest.cs (revision 1c9b0e9cabaad22335799a442889c63bfc651e59) @@ -0,0 +1,167 @@ +// 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 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 General Public License for more details. +// +// You should have received a copy of the GNU 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.Collections.Generic; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class BackgroundDataEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowArgumentNullException() + { + // Setup + BackgroundDataEntity entity = null; + + // Call + TestDelegate test = () => entity.Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_WithEntity_ReturnBackgroundData() + { + // Setup + const string name = "map data"; + const string url = "//url"; + const string capabilityName = "capability name"; + const string preferredFormat = "image/jpeg"; + const bool isVisible = false; + const double transparancy = 0.4; + const bool isConfigured = true; + + var entity = new BackgroundDataEntity + { + Name = name, + BackgroundDataMetaEntities = new List + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl, + Value = url + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, + Value = capabilityName + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.PreferredFormat, + Value = preferredFormat + } + }, + IsVisible = Convert.ToByte(isVisible), + Transparency = transparancy, + IsConfigured = Convert.ToByte(isConfigured) + }; + + // Call + BackgroundData backgroundData = entity.Read(); + + // Assert + Assert.AreEqual(isVisible, backgroundData.IsVisible); + Assert.AreEqual(transparancy, backgroundData.Transparency.Value); + + Assert.AreEqual(name, backgroundData.Name); + Assert.AreEqual(url, backgroundData.Parameters[BackgroundDataIdentifiers.SourceCapabilitiesUrl]); + Assert.AreEqual(capabilityName, backgroundData.Parameters[BackgroundDataIdentifiers.SelectedCapabilityIdentifier]); + Assert.AreEqual(preferredFormat, backgroundData.Parameters[BackgroundDataIdentifiers.PreferredFormat]); + Assert.AreEqual(isConfigured, backgroundData.IsConfigured); + } + + [Test] + public void Read_IsConfiguredFalse_NoParametersAdded() + { + // Setup + const bool isConfigured = false; + + var entity = new BackgroundDataEntity + { + BackgroundDataMetaEntities = new List + { + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl, + Value = "//url" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, + Value = "capability name" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.PreferredFormat, + Value = "image/jpeg" + } + }, + IsConfigured = Convert.ToByte(isConfigured) + }; + + // Call + BackgroundData backgroundData = entity.Read(); + + // Assert + CollectionAssert.IsEmpty(backgroundData.Parameters); + Assert.AreEqual(isConfigured, backgroundData.IsConfigured); + } + + [Test] + public void Read_BackgroundDataMetaEntityKeyNotValid_MetaDataNotAddedToBackgroundData() + { + // Setup + var entity = new BackgroundDataEntity + { + BackgroundDataMetaEntities = new List + { + new BackgroundDataMetaEntity + { + Key = "some key", + Value = "//url" + }, + new BackgroundDataMetaEntity + { + Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, + Value = "capability name" + } + }, + IsConfigured = Convert.ToByte(true) + }; + + // Call + BackgroundData backgroundData = entity.Read(); + + // Assert + Assert.AreEqual(1, backgroundData.Parameters.Count); + CollectionAssert.DoesNotContain(backgroundData.Parameters, "some key"); + } + } +} \ No newline at end of file Fisheye: Tag 1c9b0e9cabaad22335799a442889c63bfc651e59 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/BackgroundMapDataEntityReadExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff?