/// <summary> /// Read the <see cref="BackgroundDataEntity"/> and use the information /// to construct <see cref="BackgroundData"/>. /// </summary> /// <param name="entity">The <see cref="BackgroundDataEntity"/> /// to create <see cref="BackgroundData"/> for.</param> /// <returns>A new <see cref="BackgroundData"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when /// <paramref name="entity"/> is <c>null</c>.</exception> internal static BackgroundData Read(this BackgroundDataEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } IBackgroundDataConfiguration configuration = null; if ((BackgroundDataType)entity.BackgroundDataType == BackgroundDataType.Wmts) { configuration = ReadWmtsConfiguration(entity.BackgroundDataMetaEntities); } else if ((BackgroundDataType)entity.BackgroundDataType == BackgroundDataType.WellKnown) { configuration = ReadWellKnownConfiguration(entity.BackgroundDataMetaEntities); } var backgroundData = new BackgroundData(configuration) { IsVisible = Convert.ToBoolean(entity.IsVisible), Transparency = (RoundedDouble)entity.Transparency, Name = entity.Name }; return(backgroundData); }
/// <summary> /// Assert the background data. /// </summary> /// <param name="expectedBackgroundData">The background data with the expected properties.</param> /// <param name="actualBackgroundData">The background data to assert.</param> /// <exception cref="AssertionException">Thrown when the properties of the <paramref name="actualBackgroundData"/> /// are not equal to the properties of <paramref name="expectedBackgroundData"/> or when /// the set <see cref="BackgroundData.Configuration"/> is not supported.</exception> public static void AssertBackgroundData(BackgroundData expectedBackgroundData, BackgroundData actualBackgroundData) { Assert.AreEqual(expectedBackgroundData.Name, actualBackgroundData.Name); Assert.AreEqual(expectedBackgroundData.IsVisible, actualBackgroundData.IsVisible); Assert.AreEqual(expectedBackgroundData.Transparency, actualBackgroundData.Transparency); IBackgroundDataConfiguration backgroundDataConfiguration = expectedBackgroundData.Configuration; var wmtsBackgroundDataConfiguration = backgroundDataConfiguration as WmtsBackgroundDataConfiguration; var wellKnownBackgroundDataConfiguration = backgroundDataConfiguration as WellKnownBackgroundDataConfiguration; if (wmtsBackgroundDataConfiguration != null) { var actualWmtsBackgroundDataConfiguration = (WmtsBackgroundDataConfiguration)actualBackgroundData.Configuration; AssertWmtsBackgroundConfiguration(wmtsBackgroundDataConfiguration, actualWmtsBackgroundDataConfiguration); return; } if (wellKnownBackgroundDataConfiguration != null) { var actualWellKnownBackgroundDataConfiguration = (WellKnownBackgroundDataConfiguration)actualBackgroundData.Configuration; AssertWellKnownBackgroundConfiguration(wellKnownBackgroundDataConfiguration, actualWellKnownBackgroundDataConfiguration); return; } Assert.Fail($"Unsupported type of {nameof(IBackgroundDataConfiguration)} in {expectedBackgroundData.Configuration}"); }
/// <summary> /// Creates a new <see cref="BackgroundData"/>. /// </summary> public BackgroundData(IBackgroundDataConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } Configuration = configuration; IsVisible = true; transparency = new RoundedDouble(transparencyNumberOfDecimals, 0.60); }