Beispiel #1
0
        public void Create_HasHydraulicLocationCalculationsForTargetProbability_EntityHasHydraulicLocationCalculationForTargetProbabilityCollectionEntity()
        {
            // Setup
            var random = new Random(21);
            var hydraulicCalculations       = new HydraulicBoundaryLocationCalculationsForTargetProbability(random.NextDouble(0, 0.1));
            var hydraulicCalculationsEntity = new HydraulicLocationCalculationForTargetProbabilityCollectionEntity();

            var registry = new PersistenceRegistry();

            registry.Register(hydraulicCalculationsEntity, hydraulicCalculations);

            var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation
            {
                InputParameters =
                {
                    CalculationsTargetProbability = hydraulicCalculations
                }
            };

            // Call
            WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            Assert.AreSame(hydraulicCalculationsEntity, entity.HydraulicLocationCalculationForTargetProbabilityCollectionEntity);
        }
        /// <summary>
        /// Creates a <see cref="HydraulicLocationCalculationForTargetProbabilityCollectionEntity"/> based on the information
        /// of the <paramref name="calculations"/>.
        /// </summary>
        /// <param name="calculations">
        /// The collection of <see cref="HydraulicBoundaryLocationCalculationsForTargetProbability"/>
        /// to create a database entity for.
        /// </param>
        /// <param name="calculationType">The type of calculation the entity should be created for.</param>
        /// <param name="order">Index at which this instance resides inside its parent container.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <returns>A new <see cref="HydraulicLocationCalculationForTargetProbabilityCollectionEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculations"/> or <paramref name="registry"/> is <c>null</c>.</exception>
        internal static HydraulicLocationCalculationForTargetProbabilityCollectionEntity Create(this HydraulicBoundaryLocationCalculationsForTargetProbability calculations,
                                                                                                HydraulicBoundaryLocationCalculationType calculationType,
                                                                                                int order,
                                                                                                PersistenceRegistry registry)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (registry.Contains(calculations))
            {
                return(registry.Get(calculations));
            }

            var collectionEntity = new HydraulicLocationCalculationForTargetProbabilityCollectionEntity
            {
                HydraulicBoundaryLocationCalculationType = Convert.ToByte(calculationType),
                TargetProbability = calculations.TargetProbability,
                Order             = order
            };

            foreach (HydraulicBoundaryLocationCalculation calculation in calculations.HydraulicBoundaryLocationCalculations)
            {
                collectionEntity.HydraulicLocationCalculationEntities.Add(calculation.Create(registry));
            }

            registry.Register(collectionEntity, calculations);
            return(collectionEntity);
        }
Beispiel #3
0
        /// <summary>
        /// Reads the <see cref="HydraulicLocationCalculationForTargetProbabilityCollectionEntity"/> and uses
        /// the information to create a <see cref="HydraulicBoundaryLocationCalculationsForTargetProbability"/>.
        /// </summary>
        /// <param name="entity">The <see cref="HydraulicLocationCalculationForTargetProbabilityCollectionEntity"/> to create the
        /// <see cref="HydraulicBoundaryLocationCalculationsForTargetProbability"/>.</param>
        /// <param name="collector">The object keeping track of the read operations.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        internal static HydraulicBoundaryLocationCalculationsForTargetProbability Read(
            this HydraulicLocationCalculationForTargetProbabilityCollectionEntity entity,
            ReadConversionCollector collector)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            if (collector.Contains(entity))
            {
                return(collector.Get(entity));
            }

            var calculations = new HydraulicBoundaryLocationCalculationsForTargetProbability(entity.TargetProbability);
            IEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations =
                entity.HydraulicLocationCalculationEntities
                .Select(hlce => CreateHydraulicBoundaryLocationCalculation(hlce, collector))
                .ToArray();

            calculations.HydraulicBoundaryLocationCalculations.AddRange(hydraulicBoundaryLocationCalculations);

            collector.Read(entity, calculations);
            return(calculations);
        }
Beispiel #4
0
 private static void AssertHydraulicLocationCalculationForTargetProbabilityCollectionEntity(
     HydraulicBoundaryLocationCalculationsForTargetProbability expectedCalculations,
     HydraulicLocationCalculationForTargetProbabilityCollectionEntity entity)
 {
     Assert.AreEqual(expectedCalculations.TargetProbability, entity.TargetProbability);
     AssertHydraulicLocationCalculationCollectionEntity(expectedCalculations.HydraulicBoundaryLocationCalculations,
                                                        entity.HydraulicLocationCalculationEntities);
 }
Beispiel #5
0
        public void Read_CollectorNull_ThrowsArgumentNullException()
        {
            // Setup
            var entity = new HydraulicLocationCalculationForTargetProbabilityCollectionEntity();

            // Call
            void Call() => entity.Read(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("collector", exception.ParamName);
        }
Beispiel #6
0
        private static void AssertHydraulicLocationCalculationForTargetProbabilityCollectionEntity(
            IEnumerable <HydraulicBoundaryLocationCalculationsForTargetProbability> expectedCalculationCollections,
            IEnumerable <HydraulicLocationCalculationForTargetProbabilityCollectionEntity> actualCalculationCollectionEntities)
        {
            Assert.AreEqual(expectedCalculationCollections.Count(), actualCalculationCollectionEntities.Count());

            var i = 0;

            foreach (HydraulicBoundaryLocationCalculationsForTargetProbability expectedCalculationCollection in expectedCalculationCollections)
            {
                HydraulicLocationCalculationForTargetProbabilityCollectionEntity actualCalculationCollectionEntity = actualCalculationCollectionEntities.ElementAt(i);
                AssertHydraulicLocationCalculationForTargetProbabilityCollectionEntity(expectedCalculationCollection, actualCalculationCollectionEntity);
                i++;
            }
        }
Beispiel #7
0
        public void Create_HydraulicLocationCalculationForTargetProbabilitySavedMultipleTimes_ReturnsSameEntity()
        {
            // Setup
            var random       = new Random(21);
            var calculations = new HydraulicBoundaryLocationCalculationsForTargetProbability(random.NextDouble(0, 0.1));

            var registry = new PersistenceRegistry();

            // Call
            HydraulicLocationCalculationForTargetProbabilityCollectionEntity entityOne =
                calculations.Create(random.NextEnumValue <HydraulicBoundaryLocationCalculationType>(), random.Next(), registry);
            HydraulicLocationCalculationForTargetProbabilityCollectionEntity entityTwo =
                calculations.Create(random.NextEnumValue <HydraulicBoundaryLocationCalculationType>(), random.Next(), registry);

            // Assert
            Assert.AreSame(entityOne, entityTwo);
        }
Beispiel #8
0
        public void Create_WithValidCollection_ReturnsEntityWithExpectedResults()
        {
            // Setup
            var random          = new Random(21);
            int order           = random.Next();
            var calculationType = random.NextEnumValue <HydraulicBoundaryLocationCalculationType>();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation)
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = random.NextBoolean()
                }
            };

            var calculations = new HydraulicBoundaryLocationCalculationsForTargetProbability(random.NextDouble(0, 0.1))
            {
                HydraulicBoundaryLocationCalculations =
                {
                    calculation
                }
            };

            var hydraulicLocationEntity = new HydraulicLocationEntity();
            var registry = new PersistenceRegistry();

            registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation);

            // Call
            HydraulicLocationCalculationForTargetProbabilityCollectionEntity entity = calculations.Create(calculationType, order, registry);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(order, entity.Order);
            Assert.AreEqual(calculations.TargetProbability, entity.TargetProbability);
            Assert.AreEqual(Convert.ToByte(calculationType), entity.HydraulicBoundaryLocationCalculationType);

            HydraulicLocationCalculationEntity hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationEntities.Single();

            Assert.AreSame(hydraulicLocationEntity, hydraulicLocationCalculationEntity.HydraulicLocationEntity);
            Assert.AreEqual(Convert.ToByte(calculation.InputParameters.ShouldIllustrationPointsBeCalculated),
                            hydraulicLocationCalculationEntity.ShouldIllustrationPointsBeCalculated);
            CollectionAssert.IsEmpty(hydraulicLocationCalculationEntity.HydraulicLocationOutputEntities);
        }
        public void Read_EntityWithHydraulicBoundaryLocationCalculationsForTargetProbabilityNotYetInCollector_CalculationWithCreatedHydraulicBoundaryLocationCalculationsForTargetProbabilityAndRegisteredNewEntities()
        {
            // Setup
            HydraulicLocationCalculationForTargetProbabilityCollectionEntity calculationForTargetProbabilityCollectionEntity =
                HydraulicLocationCalculationForTargetProbabilityCollectionEntityTestFactory.CreateHydraulicLocationCalculationForTargetProbabilityCollectionEntity();
            var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity
            {
                HydraulicLocationCalculationForTargetProbabilityCollectionEntity = calculationForTargetProbabilityCollectionEntity
            };

            var collector = new ReadConversionCollector();

            // Call
            entity.Read(collector);

            // Assert
            Assert.IsTrue(collector.Contains(calculationForTargetProbabilityCollectionEntity));
        }
Beispiel #10
0
        public void Read_SameHydraulicLocationCalculationForTargetProbabilityCollectionEntityTwice_ReturnsSameHydraulicBoundaryLocationCalculationsForTargetProbability()
        {
            // Setup
            var random           = new Random(21);
            var collectionEntity = new HydraulicLocationCalculationForTargetProbabilityCollectionEntity
            {
                TargetProbability = random.NextDouble(0, 0.1)
            };

            var collector = new ReadConversionCollector();

            // Call
            HydraulicBoundaryLocationCalculationsForTargetProbability calculationsOne = collectionEntity.Read(collector);
            HydraulicBoundaryLocationCalculationsForTargetProbability calculationsTwo = collectionEntity.Read(collector);

            // Assert
            Assert.AreSame(calculationsOne, calculationsTwo);
        }
        public void Read_EntityWithHydraulicBoundaryLocationCalculationsForTargetProbabilityInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocationCalculationsForTargetProbability()
        {
            // Setup
            var hydraulicBoundaryLocationCalculationsForTargetProbability = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.05);
            HydraulicLocationCalculationForTargetProbabilityCollectionEntity calculationForTargetProbabilityCollectionEntity =
                HydraulicLocationCalculationForTargetProbabilityCollectionEntityTestFactory.CreateHydraulicLocationCalculationForTargetProbabilityCollectionEntity();
            var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity
            {
                HydraulicLocationCalculationForTargetProbabilityCollectionEntity = calculationForTargetProbabilityCollectionEntity
            };

            var collector = new ReadConversionCollector();

            collector.Read(calculationForTargetProbabilityCollectionEntity, hydraulicBoundaryLocationCalculationsForTargetProbability);

            // Call
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(hydraulicBoundaryLocationCalculationsForTargetProbability, calculation.InputParameters.CalculationsTargetProbability);
        }
Beispiel #12
0
 private static HydraulicBoundaryLocationCalculationsForTargetProbability GetHydraulicBoundaryLocationCalculationsForTargetProbabilityValue(
     HydraulicLocationCalculationForTargetProbabilityCollectionEntity hydraulicLocationCalculationForTargetProbabilityCollectionEntity,
     ReadConversionCollector collector)
 {
     return(hydraulicLocationCalculationForTargetProbabilityCollectionEntity?.Read(collector));
 }
Beispiel #13
0
 /// <summary>
 /// Registers a create operation for <paramref name="model"/> and the <paramref name="entity"/>
 /// that was constructed with the information.
 /// </summary>
 /// <param name="entity">The <see cref="HydraulicLocationCalculationForTargetProbabilityCollectionEntity"/> to be registered.</param>
 /// <param name="model">The <see cref="HydraulicBoundaryLocationCalculationsForTargetProbability"/> to be registered.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 internal void Register(HydraulicLocationCalculationForTargetProbabilityCollectionEntity entity, HydraulicBoundaryLocationCalculationsForTargetProbability model)
 {
     Register(hydraulicLocationCalculationsForTargetProbabilities, entity, model);
 }
Beispiel #14
0
        public void Read_EntityWithValidValues_SetsCalculationsWithExpectedValues()
        {
            // Setup
            var random = new Random(21);

            HydraulicLocationEntity hydraulicLocationEntityOne = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity();
            var calculationEntityWithoutOutput = new HydraulicLocationCalculationEntity
            {
                HydraulicLocationEntity = hydraulicLocationEntityOne,
                ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean())
            };

            HydraulicLocationEntity hydraulicLocationEntityTwo = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity();
            var calculationEntityWithOutput = new HydraulicLocationCalculationEntity
            {
                HydraulicLocationEntity = hydraulicLocationEntityTwo,
                ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()),
                HydraulicLocationOutputEntities      =
                {
                    new HydraulicLocationOutputEntity()
                }
            };

            var collectionEntity = new HydraulicLocationCalculationForTargetProbabilityCollectionEntity
            {
                TargetProbability = random.NextDouble(0, 0.1),
                HydraulicLocationCalculationEntities =
                {
                    calculationEntityWithoutOutput,
                    calculationEntityWithOutput
                }
            };

            var hydraulicBoundaryLocationOne = new TestHydraulicBoundaryLocation("1");
            var hydraulicBoundaryLocationTwo = new TestHydraulicBoundaryLocation("2");
            var collector = new ReadConversionCollector();

            collector.Read(hydraulicLocationEntityOne, hydraulicBoundaryLocationOne);
            collector.Read(hydraulicLocationEntityTwo, hydraulicBoundaryLocationTwo);

            // Call
            HydraulicBoundaryLocationCalculationsForTargetProbability calculations = collectionEntity.Read(collector);

            // Assert
            Assert.AreEqual(collectionEntity.TargetProbability, calculations.TargetProbability);

            IEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = calculations.HydraulicBoundaryLocationCalculations;

            Assert.AreEqual(collectionEntity.HydraulicLocationCalculationEntities.Count, hydraulicBoundaryLocationCalculations.Count());

            HydraulicBoundaryLocationCalculation calculationOne = hydraulicBoundaryLocationCalculations.ElementAt(0);

            Assert.AreEqual(Convert.ToBoolean(calculationEntityWithoutOutput.ShouldIllustrationPointsBeCalculated),
                            calculationOne.InputParameters.ShouldIllustrationPointsBeCalculated);
            Assert.AreSame(hydraulicBoundaryLocationOne, calculationOne.HydraulicBoundaryLocation);
            Assert.IsNull(calculationOne.Output);

            HydraulicBoundaryLocationCalculation calculationTwo = hydraulicBoundaryLocationCalculations.ElementAt(1);

            Assert.AreEqual(Convert.ToBoolean(calculationEntityWithOutput.ShouldIllustrationPointsBeCalculated),
                            calculationTwo.InputParameters.ShouldIllustrationPointsBeCalculated);
            Assert.AreSame(hydraulicBoundaryLocationTwo, calculationTwo.HydraulicBoundaryLocation);
            Assert.IsNotNull(calculationTwo.Output);
        }