/// <summary>
        /// Reads the <see cref="HydraulicLocationCalculationCollectionEntity"/> and uses
        /// the information to update a collection of <see cref="HydraulicBoundaryLocationCalculation"/>.
        /// </summary>
        /// <param name="entity">The <see cref="HydraulicLocationCalculationEntity"/> to update the
        /// <see cref="HydraulicBoundaryLocationCalculation"/>.</param>
        /// <param name="calculations">The target of the read operation.</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 void Read(this HydraulicLocationCalculationCollectionEntity entity,
                                  IEnumerable <HydraulicBoundaryLocationCalculation> calculations,
                                  ReadConversionCollector collector)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

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

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

            Dictionary <HydraulicBoundaryLocation, HydraulicBoundaryLocationCalculation> calculationsLookup =
                calculations.ToDictionary(calc => calc.HydraulicBoundaryLocation, calc => calc);

            foreach (HydraulicLocationCalculationEntity calculationEntity in entity.HydraulicLocationCalculationEntities)
            {
                HydraulicBoundaryLocation            hydraulicBoundaryLocation = collector.Get(calculationEntity.HydraulicLocationEntity);
                HydraulicBoundaryLocationCalculation calculation = calculationsLookup[hydraulicBoundaryLocation];

                calculationEntity.Read(calculation);
            }
        }
Ejemplo n.º 2
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 HydraulicLocationCalculationCollectionEntity
            {
                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);

            var calculationOne = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocationOne);
            var calculationTwo = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocationTwo);

            // Call
            collectionEntity.Read(new[]
            {
                calculationOne,
                calculationTwo
            }, collector);

            // Assert
            Assert.AreEqual(Convert.ToBoolean(calculationEntityWithoutOutput.ShouldIllustrationPointsBeCalculated),
                            calculationOne.InputParameters.ShouldIllustrationPointsBeCalculated);
            Assert.IsNull(calculationOne.Output);

            Assert.AreEqual(Convert.ToBoolean(calculationEntityWithOutput.ShouldIllustrationPointsBeCalculated),
                            calculationTwo.InputParameters.ShouldIllustrationPointsBeCalculated);
            Assert.IsNotNull(calculationTwo.Output);
        }
Ejemplo n.º 3
0
        public void Read_CalculationsNull_ThrowsArgumentNullException()
        {
            // Setup
            var entity = new HydraulicLocationCalculationCollectionEntity();

            // Call
            TestDelegate call = () => entity.Read(null, new ReadConversionCollector());

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

            Assert.AreEqual("calculations", exception.ParamName);
        }
Ejemplo n.º 4
0
        public void Read_CollectorNull_ThrowsArgumentNullException()
        {
            // Setup
            var entity = new HydraulicLocationCalculationCollectionEntity();

            // Call
            TestDelegate call = () => entity.Read(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(),
                                                  null);

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

            Assert.AreEqual("collector", exception.ParamName);
        }
        /// <summary>
        /// Creates a <see cref="HydraulicLocationCalculationCollectionEntity"/> based on the information
        /// of the <paramref name="calculations"/>.
        /// </summary>
        /// <param name="calculations">The collection of <see cref="HydraulicBoundaryLocationCalculation"/>
        /// to create a database entity for.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <returns>A new <see cref="HydraulicLocationCalculationCollectionEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        internal static HydraulicLocationCalculationCollectionEntity Create(this IEnumerable <HydraulicBoundaryLocationCalculation> calculations,
                                                                            PersistenceRegistry registry)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

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

            var collectionEntity = new HydraulicLocationCalculationCollectionEntity();

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

            return(collectionEntity);
        }
Ejemplo n.º 6
0
        public void Create_WithValidCollection_ReturnsEntityWithExpectedResults()
        {
            // Setup
            var random = new Random(21);

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

            var calculationCollection = new ObservableList <HydraulicBoundaryLocationCalculation>
            {
                calculation
            };

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

            registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation);

            // Call
            HydraulicLocationCalculationCollectionEntity entity = calculationCollection.Create(registry);

            // Assert
            Assert.IsNotNull(entity);

            HydraulicLocationCalculationEntity hydraulicLocationCalculationEntity = entity.HydraulicLocationCalculationEntities.Single();

            Assert.AreSame(hydraulicLocationEntity, hydraulicLocationCalculationEntity.HydraulicLocationEntity);
            Assert.AreEqual(Convert.ToByte(calculation.InputParameters.ShouldIllustrationPointsBeCalculated),
                            hydraulicLocationCalculationEntity.ShouldIllustrationPointsBeCalculated);
            CollectionAssert.IsEmpty(hydraulicLocationCalculationEntity.HydraulicLocationOutputEntities);
        }