/// <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); }
public void Create_BackgroundDataContainsConfiguredWMTSConfiguration_ReturnsBackgroundDataEntity() { // 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; var 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 <string, string> { { BackgroundDataIdentifiers.IsConfigured, Convert.ToByte(isConfigured).ToString() }, { BackgroundDataIdentifiers.SourceCapabilitiesUrl, sourceCapabilitiesUrl }, { BackgroundDataIdentifiers.SelectedCapabilityIdentifier, selectedCapabilityName }, { BackgroundDataIdentifiers.PreferredFormat, preferredFormat } }; IEnumerable <KeyValuePair <string, string> > actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( metaEntity => new KeyValuePair <string, string>(metaEntity.Key, metaEntity.Value)); CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); }
/// <summary> /// Creates a <see cref="BackgroundDataEntity"/> based on the information of the /// <see cref="BackgroundData"/>. /// </summary> /// <param name="backgroundData">The container to create a <see cref="BackgroundDataEntity"/> for.</param> /// <returns>The created <see cref="BackgroundDataEntity"/>.</returns> internal static BackgroundDataEntity Create(this BackgroundData backgroundData) { if (backgroundData == null) { throw new ArgumentNullException(nameof(backgroundData)); } var entity = new BackgroundDataEntity { Name = backgroundData.Name.DeepClone(), IsVisible = Convert.ToByte(backgroundData.IsVisible), Transparency = backgroundData.Transparency }; AddEntitiesForBackgroundDataMeta(backgroundData, entity); return(entity); }
public void Read_WmtsConfigurationIsConfiguredFalse_NoParametersAdded() { // Setup const bool isConfigured = false; var entity = new BackgroundDataEntity { BackgroundDataMetaEntities = new List <BackgroundDataMetaEntity> { new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.IsConfigured, Value = Convert.ToByte(isConfigured).ToString() }, new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl, Value = "//url" }, new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, Value = "capability name" }, new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.PreferredFormat, Value = "image/jpeg" } }, BackgroundDataType = Convert.ToByte(BackgroundDataType.Wmts) }; // Call BackgroundData backgroundData = entity.Read(); // Assert var configuration = (WmtsBackgroundDataConfiguration)backgroundData.Configuration; Assert.AreEqual(false, configuration.IsConfigured); Assert.IsNull(configuration.SourceCapabilitiesUrl); Assert.IsNull(configuration.SelectedCapabilityIdentifier); Assert.IsNull(configuration.PreferredFormat); }
public void Read_EntityWithWellKnownData_ReturnBackgroundData() { // Setup const string name = "map data"; const bool isVisible = false; const double transparancy = 0.4; const BackgroundDataType backgroundDataType = BackgroundDataType.WellKnown; var random = new Random(21); var wellKnownTileSource = random.NextEnumValue <RiskeerWellKnownTileSource>(); var entity = new BackgroundDataEntity { Name = name, BackgroundDataMetaEntities = new List <BackgroundDataMetaEntity> { new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.WellKnownTileSource, Value = ((int)wellKnownTileSource).ToString() } }, IsVisible = Convert.ToByte(isVisible), Transparency = transparancy, BackgroundDataType = Convert.ToByte(backgroundDataType) }; // Call BackgroundData backgroundData = entity.Read(); // Assert Assert.AreEqual(isVisible, backgroundData.IsVisible); Assert.AreEqual(transparancy, backgroundData.Transparency.Value); Assert.AreEqual(name, backgroundData.Name); Assert.IsNotNull(backgroundData.Configuration); var configuration = (WellKnownBackgroundDataConfiguration)backgroundData.Configuration; Assert.AreEqual(wellKnownTileSource, configuration.WellKnownTileSource); }
public void Create_BackgroundDataContainsWellKnownConfiguration_ReturnsBackgroundDataEntity() { // Setup var random = new Random(21); var wellKnownTileSource = random.NextEnumValue <RiskeerWellKnownTileSource>(); const string name = "background"; const bool isVisible = true; const BackgroundDataType backgroundDataType = BackgroundDataType.WellKnown; var 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 <string, string> { { BackgroundDataIdentifiers.WellKnownTileSource, ((int)wellKnownTileSource).ToString() } }; IEnumerable <KeyValuePair <string, string> > actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( metaEntity => new KeyValuePair <string, string>(metaEntity.Key, metaEntity.Value)); CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); }
public void Create_BackgroundDataContainsUnconfiguredWMTSConfiguration_ReturnsBackgroundDataEntity() { // Setup const string name = "background"; const bool isVisible = true; const bool isConfigured = false; var 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 <string, string> { { BackgroundDataIdentifiers.IsConfigured, Convert.ToByte(isConfigured).ToString() } }; IEnumerable <KeyValuePair <string, string> > actualKeyValuePairs = entity.BackgroundDataMetaEntities.Select( metaEntity => new KeyValuePair <string, string>(metaEntity.Key, metaEntity.Value)); CollectionAssert.AreEquivalent(expectedKeyValuePairs, actualKeyValuePairs); }
public void Create_WithCollector_ReturnsAssessmentSectionEntityWithCompositionAndFailureMechanisms(AssessmentSectionComposition assessmentSectionComposition) { // Setup const string testId = "testId"; const string testName = "testName"; const string comments = "Some text"; const double maximumAllowableFloodingProbability = 0.05; const double signalFloodingProbability = 0.02; var random = new Random(65); const string mapDataName = "map data name"; const double transparency = 0.3; const bool isVisible = true; const BackgroundDataType backgroundType = BackgroundDataType.Wmts; var normativeProbabilityType = random.NextEnumValue <NormativeProbabilityType>(); IEnumerable <SpecificFailureMechanism> specificFailureMechanisms = Enumerable.Repeat(new SpecificFailureMechanism(), random.Next(1, 10)) .ToArray(); var assessmentSection = new AssessmentSection(assessmentSectionComposition) { Id = testId, Name = testName, Comments = { Body = comments }, FailureMechanismContribution = { MaximumAllowableFloodingProbability = maximumAllowableFloodingProbability, SignalFloodingProbability = signalFloodingProbability, NormativeProbabilityType = normativeProbabilityType }, BackgroundData = { Name = mapDataName, Transparency = (RoundedDouble)transparency, IsVisible = isVisible, Configuration = new WmtsBackgroundDataConfiguration(false,null, null, null) } }; assessmentSection.SpecificFailureMechanisms.AddRange(specificFailureMechanisms); var registry = new PersistenceRegistry(); // Call AssessmentSectionEntity entity = assessmentSection.Create(registry); // Assert Assert.IsNotNull(entity); Assert.AreEqual(Convert.ToByte(assessmentSectionComposition), entity.Composition); Assert.AreEqual(testId, entity.Id); Assert.AreEqual(testName, entity.Name); Assert.AreEqual(comments, entity.Comments); Assert.AreEqual(maximumAllowableFloodingProbability, entity.MaximumAllowableFloodingProbability); Assert.AreEqual(signalFloodingProbability, entity.SignalFloodingProbability); Assert.AreEqual(Convert.ToByte(normativeProbabilityType), entity.NormativeProbabilityType); Assert.AreEqual(15, entity.FailureMechanismEntities.Count); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.Piping)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentTopErosionAndInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.MacroStabilityInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.Microstability)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.StabilityStoneRevetment)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.WaveImpactOnAsphaltRevetment)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.WaterOverpressureAsphaltRevetment)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentErosionOutwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentSlidingOutwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentSlidingInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.StructureHeight)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.ReliabilityClosingOfStructure)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.PipingAtStructure)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.StabilityPointStructures)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.DuneErosion)); Assert.AreEqual(assessmentSection.SpecificFailureMechanisms.Count, entity.SpecificFailureMechanismEntities.Count); Assert.IsNull(entity.ReferenceLinePointXml); Assert.AreEqual(1, entity.BackgroundDataEntities.Count); BackgroundDataEntity backgroundDataEntity = entity.BackgroundDataEntities.Single(); Assert.IsNotNull(backgroundDataEntity); Assert.AreEqual(mapDataName, backgroundDataEntity.Name); Assert.AreEqual(transparency, backgroundDataEntity.Transparency); Assert.AreEqual(Convert.ToByte(isVisible), backgroundDataEntity.IsVisible); Assert.AreEqual(Convert.ToByte(backgroundType), backgroundDataEntity.BackgroundDataType); Assert.AreEqual(1, backgroundDataEntity.BackgroundDataMetaEntities.Count); BackgroundDataMetaEntity isConfiguredMetaEntity = backgroundDataEntity.BackgroundDataMetaEntities.Single(); Assert.AreEqual("IsConfigured", isConfiguredMetaEntity.Key); Assert.AreEqual("0", isConfiguredMetaEntity.Value); }
private static void AddWmtsMetaEntities(WmtsBackgroundDataConfiguration wmtsBackgroundDataConfiguration, BackgroundDataEntity entity) { entity.BackgroundDataMetaEntities.Add(new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.IsConfigured, Value = Convert.ToByte(wmtsBackgroundDataConfiguration.IsConfigured).ToString() }); if (wmtsBackgroundDataConfiguration.IsConfigured) { entity.BackgroundDataMetaEntities.Add(new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier.DeepClone(), Value = wmtsBackgroundDataConfiguration.SelectedCapabilityIdentifier.DeepClone() }); entity.BackgroundDataMetaEntities.Add(new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl.DeepClone(), Value = wmtsBackgroundDataConfiguration.SourceCapabilitiesUrl.DeepClone() }); entity.BackgroundDataMetaEntities.Add(new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.PreferredFormat.DeepClone(), Value = wmtsBackgroundDataConfiguration.PreferredFormat.DeepClone() }); } }
private static void AddWellKnownTileSourceMetaEntities(WellKnownBackgroundDataConfiguration wellKnownConfiguration, BackgroundDataEntity entity) { entity.BackgroundDataMetaEntities.Add(new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.WellKnownTileSource.DeepClone(), Value = ((int)wellKnownConfiguration.WellKnownTileSource).ToString() }); }
private static void AddEntitiesForBackgroundDataMeta(BackgroundData backgroundData, BackgroundDataEntity entity) { var wmtsBackgroundDataConfiguration = backgroundData.Configuration as WmtsBackgroundDataConfiguration; var wellKnownBackgroundDataConfiguration = backgroundData.Configuration as WellKnownBackgroundDataConfiguration; if (wmtsBackgroundDataConfiguration != null) { entity.BackgroundDataType = Convert.ToByte(BackgroundDataType.Wmts); AddWmtsMetaEntities(wmtsBackgroundDataConfiguration, entity); } else if (wellKnownBackgroundDataConfiguration != null) { entity.BackgroundDataType = Convert.ToByte(BackgroundDataType.WellKnown); AddWellKnownTileSourceMetaEntities(wellKnownBackgroundDataConfiguration, entity); } }
public void Read_EntityWithWmtsData_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; const BackgroundDataType backgroundDataType = BackgroundDataType.Wmts; var backgroundDataMetaEntities = new[] { new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.IsConfigured, Value = Convert.ToByte(isConfigured).ToString() }, new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.SourceCapabilitiesUrl, Value = url }, new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.SelectedCapabilityIdentifier, Value = capabilityName }, new BackgroundDataMetaEntity { Key = BackgroundDataIdentifiers.PreferredFormat, Value = preferredFormat } }; var entity = new BackgroundDataEntity { Name = name, BackgroundDataMetaEntities = backgroundDataMetaEntities, IsVisible = Convert.ToByte(isVisible), Transparency = transparancy, BackgroundDataType = Convert.ToByte(backgroundDataType) }; // Call BackgroundData backgroundData = entity.Read(); // Assert Assert.AreEqual(isVisible, backgroundData.IsVisible); Assert.AreEqual(transparancy, backgroundData.Transparency.Value); Assert.AreEqual(name, backgroundData.Name); Assert.IsNotNull(backgroundData.Configuration); var configuration = (WmtsBackgroundDataConfiguration)backgroundData.Configuration; Assert.AreEqual(isConfigured, configuration.IsConfigured); Assert.AreEqual(url, configuration.SourceCapabilitiesUrl); Assert.AreEqual(capabilityName, configuration.SelectedCapabilityIdentifier); Assert.AreEqual(preferredFormat, configuration.PreferredFormat); }