// 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 System.Linq; using Application.Ringtoets.Storage.Create; using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; namespace Application.Ringtoets.Storage.Test.Create { [TestFixture] public class BackgroundDataCreateExtensionsTest { [Test] public void Create_BackgroundDataNull_ThrowArgumentNullException() { // Setup BackgroundData backgroundData = null; // Call TestDelegate test = () => backgroundData.Create(); // Assert var exception = Assert.Throws(test); Assert.AreEqual("backgroundData", exception.ParamName); } [Test] public void Create_BackgroundDataContainsConfiguredWMTSConfiguration_ReturnsBackgroundMapDataEntity() { // Setup const string name = "background"; const string sourceCapabilitiesUrl = "//url"; const string selectedCapabilityName = "selectedName"; const string preferredFormat = "image/png"; const bool isVisible = true; const bool isConfigured = true; RoundedDouble transparancy = (RoundedDouble) 0.3; var configuration = new WmtsBackgroundDataConfiguration(isConfigured, sourceCapabilitiesUrl, selectedCapabilityName, preferredFormat); var backgroundData = new BackgroundData(configuration) { IsVisible = isVisible, Transparency = transparancy, Name = name }; // Call BackgroundDataEntity entity = backgroundData.Create(); // Assert Assert.AreEqual(name, entity.Name); Assert.AreEqual(Convert.ToByte(isVisible), entity.IsVisible); Assert.AreEqual(transparancy, entity.Transparency); var expectedKeyValuePairs = new Dictionary { { BackgroundDataIdentifiers.IsConfigured, Convert.ToByte(isConfigured).ToString() }, { BackgroundDataIdentifiers.SourceCapabilitiesUrl, sourceCapabilitiesUrl }, { BackgroundDataIdentifiers.SelectedCapabilityIdentifier, selectedCapabilityName }, { BackgroundDataIdentifiers.PreferredFormat, preferredFormat } }; var actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( metaEntity => new KeyValuePair(metaEntity.Key, metaEntity.Value)); CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); } [Test] public void Create_BackgroundDataContainsUnconfiguredWMTSConfiguration_ReturnsBackgroundMapDataEntity() { // Setup const string name = "background"; const bool isVisible = true; const bool isConfigured = false; RoundedDouble transparancy = (RoundedDouble)0.3; var configuration = new WmtsBackgroundDataConfiguration(); var backgroundData = new BackgroundData(configuration) { IsVisible = isVisible, Transparency = transparancy, Name = name }; // Call BackgroundDataEntity entity = backgroundData.Create(); // Assert Assert.AreEqual(name, entity.Name); Assert.AreEqual(Convert.ToByte(isVisible), entity.IsVisible); Assert.AreEqual(transparancy, entity.Transparency); var expectedKeyValuePairs = new Dictionary { { BackgroundDataIdentifiers.IsConfigured, Convert.ToByte(isConfigured).ToString() } }; var actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( metaEntity => new KeyValuePair(metaEntity.Key, metaEntity.Value)); CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); } [Test] public void Create_BackgroundDataContainsWellKnownConfiguration_ReturnsBackgroundMapDataEntity() { // Setup var random = new Random(21); var wellKnownTileSource = random.NextEnumValue(); const string name = "background"; const bool isVisible = true; const BackgroundMapDataType backgroundDataType = BackgroundMapDataType.WellKnown; RoundedDouble transparancy = (RoundedDouble) 0.3; var configuration = new WellKnownBackgroundDataConfiguration(wellKnownTileSource); var backgroundData = new BackgroundData(configuration) { IsVisible = isVisible, Transparency = transparancy, Name = name }; // Call BackgroundDataEntity entity = backgroundData.Create(); // Assert Assert.AreEqual(name, entity.Name); Assert.AreEqual(Convert.ToByte(isVisible), entity.IsVisible); Assert.AreEqual(transparancy, entity.Transparency); Assert.AreEqual(Convert.ToByte(backgroundDataType), entity.BackgroundDataType); var expectedKeyValuePairs = new Dictionary { { BackgroundDataIdentifiers.WellKnownTileSource, ((int) wellKnownTileSource).ToString() } }; var actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( metaEntity => new KeyValuePair(metaEntity.Key, metaEntity.Value)); CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); } } }