Exemplo n.º 1
0
        public void Create_WithDikeProfiles_AddDikeProfileEntities()
        {
            // Setup
            const string filePath         = "some/path/to/my/dikeprofiles";
            var          failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.DikeProfiles.AddRange(new[]
            {
                DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id1"),
                DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id2")
            }, filePath);

            var registry = new PersistenceRegistry();

            // Call
            FailureMechanismEntity entity = failureMechanism.Create(registry);

            // Assert
            Assert.AreEqual(2, entity.DikeProfileEntities.Count);

            GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity =
                entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single();

            TestHelper.AssertAreEqualButNotSame(filePath, generalInputEntity.DikeProfileCollectionSourcePath);
        }
Exemplo n.º 2
0
        private static void AddEntitiesForGeneralInput(GrassCoverErosionInwardsFailureMechanism mechanism, FailureMechanismEntity entity)
        {
            var metaEntity = new GrassCoverErosionInwardsFailureMechanismMetaEntity
            {
                N = mechanism.GeneralInput.N,
                DikeProfileCollectionSourcePath = mechanism.DikeProfiles.SourcePath.DeepClone(),
                ApplyLengthEffectInSection      = Convert.ToByte(mechanism.GeneralInput.ApplyLengthEffectInSection)
            };

            entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Add(metaEntity);
        }
Exemplo n.º 3
0
        public void Read_GeneralInputNull_ThrowArgumentNullException()
        {
            // Setup
            var entity = new GrassCoverErosionInwardsFailureMechanismMetaEntity();

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

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("input", paramName);
        }
Exemplo n.º 4
0
        public void Create_WithCollectorAndPropertiesSet_ReturnsFailureMechanismEntityWithPropertiesSet(bool inAssembly)
        {
            // Setup
            var random           = new Random();
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism
            {
                InAssembly = inAssembly,
                InAssemblyInputComments =
                {
                    Body = "Some input text"
                },
                InAssemblyOutputComments =
                {
                    Body = "Some output text"
                },
                NotInAssemblyComments =
                {
                    Body = "Really not in assembly"
                },
                CalculationsInputComments =
                {
                    Body = "Some calculation text"
                },
                GeneralInput =
                {
                    N                          = random.NextRoundedDouble(1, 20),
                    ApplyLengthEffectInSection = random.NextBoolean()
                }
            };
            var registry = new PersistenceRegistry();

            // Call
            FailureMechanismEntity entity = failureMechanism.Create(registry);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual((short)FailureMechanismType.GrassRevetmentTopErosionAndInwards, entity.FailureMechanismType);
            Assert.AreEqual(Convert.ToByte(inAssembly), entity.InAssembly);
            Assert.AreEqual(failureMechanism.InAssemblyInputComments.Body, entity.InAssemblyInputComments);
            Assert.AreEqual(failureMechanism.InAssemblyOutputComments.Body, entity.InAssemblyOutputComments);
            Assert.AreEqual(failureMechanism.NotInAssemblyComments.Body, entity.NotInAssemblyComments);
            Assert.AreEqual(failureMechanism.CalculationsInputComments.Body, entity.CalculationsInputComments);

            Assert.AreEqual(1, entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Count);
            GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity = entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single();

            Assert.AreEqual(failureMechanism.GeneralInput.N, generalInputEntity.N);
            Assert.AreEqual(Convert.ToByte(failureMechanism.GeneralInput.ApplyLengthEffectInSection), generalInputEntity.ApplyLengthEffectInSection);
        }
        /// <summary>
        /// Read the <see cref="GrassCoverErosionInwardsFailureMechanismMetaEntity"/> and use the information
        /// to update the <paramref name="input"/>.
        /// </summary>
        /// <param name="entity">The <see cref="GrassCoverErosionInwardsFailureMechanismMetaEntity"/> to use
        /// to update the <paramref name="input"/>.</param>
        /// <param name="input">The <see cref="GeneralGrassCoverErosionInwardsInput"/> to be updated.</param>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        internal static void Read(this GrassCoverErosionInwardsFailureMechanismMetaEntity entity, GeneralGrassCoverErosionInwardsInput input)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

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

            input.N = (RoundedDouble)entity.N;
            input.ApplyLengthEffectInSection = Convert.ToBoolean(entity.ApplyLengthEffectInSection);
        }
Exemplo n.º 6
0
        public void Create_WithoutDikeProfiles_EmptyDikeProfileEntities()
        {
            // Setup
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
            var registry         = new PersistenceRegistry();

            // Call
            FailureMechanismEntity entity = failureMechanism.Create(registry);

            // Assert
            CollectionAssert.IsEmpty(entity.DikeProfileEntities);

            GrassCoverErosionInwardsFailureMechanismMetaEntity generalInputEntity =
                entity.GrassCoverErosionInwardsFailureMechanismMetaEntities.Single();

            Assert.IsNull(generalInputEntity.DikeProfileCollectionSourcePath);
        }
Exemplo n.º 7
0
        public void Read_ValidEntity_ReturnGeneralGrassCoverErosionInwardsInput()
        {
            // Setup
            var random        = new Random();
            var inputToUpdate = new GeneralGrassCoverErosionInwardsInput();
            var entity        = new GrassCoverErosionInwardsFailureMechanismMetaEntity
            {
                N = random.NextRoundedDouble(1.0, 20.0),
                ApplyLengthEffectInSection = Convert.ToByte(random.NextBoolean())
            };

            // Call
            entity.Read(inputToUpdate);

            // Assert
            Assert.AreEqual(entity.N, inputToUpdate.N, inputToUpdate.N.GetAccuracy());
            Assert.AreEqual(Convert.ToBoolean(entity.ApplyLengthEffectInSection), inputToUpdate.ApplyLengthEffectInSection);
        }