/// <summary>
        /// Creates a <see cref="DuneLocationCalculationForTargetProbabilityCollectionEntity"/> based on the information
        /// of the <paramref name="calculations"/>.
        /// </summary>
        /// <param name="calculations">The collection of <see cref="DuneLocationCalculationsForTargetProbability"/>
        /// to create a database entity 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="DuneLocationCalculationForTargetProbabilityCollectionEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculations"/> or <paramref name="registry"/> is <c>null</c>.</exception>
        internal static DuneLocationCalculationForTargetProbabilityCollectionEntity Create(this DuneLocationCalculationsForTargetProbability calculations,
                                                                                           int order,
                                                                                           PersistenceRegistry registry)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

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

            var collectionEntity = new DuneLocationCalculationForTargetProbabilityCollectionEntity
            {
                TargetProbability = calculations.TargetProbability,
                Order             = order
            };

            foreach (DuneLocationCalculation calculation in calculations.DuneLocationCalculations)
            {
                collectionEntity.DuneLocationCalculationEntities.Add(calculation.Create(registry));
            }

            return(collectionEntity);
        }
Esempio n. 2
0
        public void Create_WithValidCollection_ReturnsEntityWithExpectedResults()
        {
            // Setup
            var random = new Random(21);
            int order  = random.Next();

            var duneLocation = new TestDuneLocation();
            var calculation  = new DuneLocationCalculation(duneLocation);

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

            var duneLocationEntity = new DuneLocationEntity();
            var registry           = new PersistenceRegistry();

            registry.Register(duneLocationEntity, duneLocation);

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

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(order, entity.Order);
            Assert.AreEqual(calculations.TargetProbability, entity.TargetProbability);

            DuneLocationCalculationEntity duneLocationCalculationEntity = entity.DuneLocationCalculationEntities.Single();

            Assert.AreSame(duneLocationEntity, duneLocationCalculationEntity.DuneLocationEntity);
            CollectionAssert.IsEmpty(duneLocationCalculationEntity.DuneLocationCalculationOutputEntities);
        }
Esempio n. 3
0
 private static void AssertDuneLocationCalculationCollectionEntity(
     DuneLocationCalculationsForTargetProbability expectedCalculations,
     DuneLocationCalculationForTargetProbabilityCollectionEntity entity)
 {
     Assert.AreEqual(expectedCalculations.TargetProbability, entity.TargetProbability);
     Assert.AreEqual(expectedCalculations.DuneLocationCalculations.Count, entity.DuneLocationCalculationEntities.Count);
 }
Esempio n. 4
0
        public void Read_EntityWithValidValues_SetsCalculationsWithExpectedValues()
        {
            // Setup
            var random = new Random(21);

            var duneLocationEntityOne          = new DuneLocationEntity();
            var calculationEntityWithoutOutput = new DuneLocationCalculationEntity
            {
                DuneLocationEntity = duneLocationEntityOne
            };

            var duneLocationEntityTwo       = new DuneLocationEntity();
            var calculationEntityWithOutput = new DuneLocationCalculationEntity
            {
                DuneLocationEntity = duneLocationEntityTwo,
                DuneLocationCalculationOutputEntities =
                {
                    new DuneLocationCalculationOutputEntity()
                }
            };

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

            var duneLocationOne = new TestDuneLocation("1");
            var duneLocationTwo = new TestDuneLocation("2");
            var collector       = new ReadConversionCollector();

            collector.Read(duneLocationEntityOne, duneLocationOne);
            collector.Read(duneLocationEntityTwo, duneLocationTwo);

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

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

            IEnumerable <DuneLocationCalculation> duneLocationCalculations = calculations.DuneLocationCalculations;

            Assert.AreEqual(collectionEntity.DuneLocationCalculationEntities.Count, duneLocationCalculations.Count());

            DuneLocationCalculation calculationOne = duneLocationCalculations.ElementAt(0);

            Assert.AreSame(collector.Get(duneLocationEntityOne), calculationOne.DuneLocation);
            Assert.IsNull(calculationOne.Output);

            DuneLocationCalculation calculationTwo = duneLocationCalculations.ElementAt(1);

            Assert.AreSame(collector.Get(duneLocationEntityTwo), calculationTwo.DuneLocation);
            Assert.IsNotNull(calculationTwo.Output);
        }
Esempio n. 5
0
        private static void AssertDuneLocationCalculationCollectionEntity(
            IEnumerable <DuneLocationCalculationsForTargetProbability> expectedCalculationCollections,
            IEnumerable <DuneLocationCalculationForTargetProbabilityCollectionEntity> actualCalculationCollectionEntities)
        {
            Assert.AreEqual(expectedCalculationCollections.Count(), actualCalculationCollectionEntities.Count());

            for (var i = 0; i < expectedCalculationCollections.Count(); i++)
            {
                DuneLocationCalculationForTargetProbabilityCollectionEntity actualCalculationCollectionEntity = actualCalculationCollectionEntities.ElementAt(i);
                AssertDuneLocationCalculationCollectionEntity(expectedCalculationCollections.ElementAt(i), actualCalculationCollectionEntity);
            }
        }
Esempio n. 6
0
        public void Read_CollectorNull_ThrowsArgumentNullException()
        {
            // Setup
            var entity = new DuneLocationCalculationForTargetProbabilityCollectionEntity();

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

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

            Assert.AreEqual("collector", exception.ParamName);
        }
Esempio n. 7
0
        /// <summary>
        /// Reads the <see cref="DuneLocationCalculationForTargetProbabilityCollectionEntity"/> and uses the information
        /// to update a collection of <see cref="DuneLocationCalculationsForTargetProbability"/>.
        /// </summary>
        /// <param name="entity">The <see cref="DuneLocationCalculationForTargetProbabilityCollectionEntity"/> to create the
        /// <see cref="DuneLocationCalculationsForTargetProbability"/>.</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 DuneLocationCalculationsForTargetProbability Read(this DuneLocationCalculationForTargetProbabilityCollectionEntity entity,
                                                                          ReadConversionCollector collector)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

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

            var calculations = new DuneLocationCalculationsForTargetProbability(entity.TargetProbability);
            IEnumerable <DuneLocationCalculation> duneLocationCalculations =
                entity.DuneLocationCalculationEntities
                .Select(dlce => CreateDuneLocationCalculation(dlce, collector))
                .ToArray();

            calculations.DuneLocationCalculations.AddRange(duneLocationCalculations);

            return(calculations);
        }