示例#1
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }