Пример #1
0
        /// <summary>
        /// Creates a new instance of <see cref="StochasticSoilModel"/>.
        /// </summary>
        /// <param name="name">The name of the stochastic soil model.</param>
        /// <param name="failureMechanismType">The failure mechanism this stochastic soil model belongs to.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is <c>null</c>.</exception>
        public StochasticSoilModel(string name, FailureMechanismType failureMechanismType)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name = name;
            FailureMechanismType   = failureMechanismType;
            Geometry               = new List <Point2D>();
            StochasticSoilProfiles = new List <StochasticSoilProfile>();
        }
Пример #2
0
        /// <summary>
        /// Creates a <see cref="StochasticSoilModel"/> with a predefined geometry.
        /// </summary>
        /// <param name="soilModelName">The name of the stochastic soil model.</param>
        /// <param name="failureMechanismType">The failure mechanism type of the stochastic soil model.</param>
        /// <param name="stochasticSoilProfiles">The stochastic soil profiles belonging to the soil model.</param>
        /// <returns>A configured <see cref="StochasticSoilModel"/> with a predefined geometry.</returns>
        /// <exception cref="ArgumentNullException">Throw when <paramref name="soilModelName"/> or
        /// <paramref name="stochasticSoilProfiles"/> is <c>null</c>.</exception>
        public static StochasticSoilModel CreateStochasticSoilModelWithGeometry(string soilModelName,
                                                                                FailureMechanismType failureMechanismType,
                                                                                IEnumerable <StochasticSoilProfile> stochasticSoilProfiles)
        {
            var model = new StochasticSoilModel(soilModelName, failureMechanismType)
            {
                Geometry =
                {
                    new Point2D(1, 2),
                    new Point2D(3, 4)
                }
            };

            model.StochasticSoilProfiles.AddRange(stochasticSoilProfiles);

            return(model);
        }
Пример #3
0
 private static FailureMechanismEntity GetFailureMechanismEntityOfType(AssessmentSectionEntity entity, FailureMechanismType type)
 {
     return(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (int)type));
 }
Пример #4
0
 private static void FilterFailureMechanismSpecificModel(MethodInvocation invocation, FailureMechanismType failureMechanismType)
 {
     invocation.ReturnValue = failureMechanismType == ((StochasticSoilModel)invocation.Arguments[0]).FailureMechanismType;
 }
Пример #5
0
        public void Import_VariousFailureMechanismTypes_ShowProgressAndUpdatesCollection(FailureMechanismType failureMechanismType,
                                                                                         int nrOfFailureMechanismSpecificModelsInDatabase)
        {
            // Setup
            string    validFilePath = Path.Combine(testDataPath, "complete.soil");
            const int totalNrOfStochasticSoilModelInDatabase = 6;

            const string expectedAddDataText = "Adding Data";

            var filter = mocks.StrictMock <IStochasticSoilModelMechanismFilter>();

            filter.Expect(f => f.IsValidForFailureMechanism(null))
            .IgnoreArguments()
            .Return(false)
            .WhenCalled(invocation =>
            {
                FilterFailureMechanismSpecificModel(invocation, failureMechanismType);
            })
            .Repeat
            .Times(totalNrOfStochasticSoilModelInDatabase);

            var messageProvider = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText())
            .Return(expectedAddDataText);

            var updateStrategy = mocks.StrictMock <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >();

            updateStrategy.Expect(u => u.UpdateModelWithImportedData(null, null))
            .IgnoreArguments()
            .WhenCalled(invocation =>
            {
                var soilModels = (IEnumerable <IMechanismStochasticSoilModel>)invocation.Arguments[0];
                var filePath   = (string)invocation.Arguments[1];

                Assert.AreEqual(nrOfFailureMechanismSpecificModelsInDatabase, soilModels.Count());
                Assert.AreEqual(validFilePath, filePath);
            });

            mocks.ReplayAll();

            var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>(
                new TestStochasticSoilModelCollection(),
                validFilePath,
                messageProvider,
                new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>(
                    transformer,
                    filter,
                    updateStrategy));

            var progressChangeNotifications = new List <ProgressNotification>();

            importer.SetProgressChanged((description, step, steps) =>
                                        progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.Import();

            // Assert
            TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{validFilePath}'.", 1);
            Assert.IsTrue(importResult);

            var expectedProgressMessages = new List <ProgressNotification>
            {
                new ProgressNotification("Inlezen van de D-Soil Model database.", 1, 1)
            };

            for (var i = 1; i <= totalNrOfStochasticSoilModelInDatabase; i++)
            {
                expectedProgressMessages.Add(new ProgressNotification(
                                                 "Inlezen van de stochastische ondergrondmodellen.", i, totalNrOfStochasticSoilModelInDatabase));
            }

            for (var i = 1; i <= nrOfFailureMechanismSpecificModelsInDatabase; i++)
            {
                expectedProgressMessages.Add(new ProgressNotification(
                                                 "Valideren van ingelezen data.", i, nrOfFailureMechanismSpecificModelsInDatabase));
            }

            expectedProgressMessages.Add(new ProgressNotification(expectedAddDataText, 1, 1));
            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages,
                                                                               progressChangeNotifications);
        }
        public void Transform_InvalidFailureMechanismType_ThrowsImportedDataTransformException(FailureMechanismType failureMechanismType)
        {
            // Setup
            var transformer = new PipingStochasticSoilModelTransformer();
            var soilModel   = new StochasticSoilModel("some name", failureMechanismType);

            // Call
            TestDelegate test = () => transformer.Transform(soilModel);

            // Assert
            var exception = Assert.Throws <ImportedDataTransformException>(test);

            Assert.AreEqual($"Het stochastische ondergrondmodel met '{failureMechanismType}' als faalmechanisme type is niet ondersteund. " +
                            "Alleen stochastische ondergrondmodellen met 'Piping' als faalmechanisme type zijn ondersteund.", exception.Message);
        }
Пример #7
0
        /// <summary>
        /// Creates a <see cref="FailureMechanismEntity"/> based on the information of the <see cref="ICalculatableFailureMechanism"/>.
        /// </summary>
        /// <param name="mechanism">The failure mechanism to create a database entity for.</param>
        /// <param name="type">The type of the failure mechanism that is being created.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <returns>A new <see cref="FailureMechanismEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception>
        internal static FailureMechanismEntity Create(this ICalculatableFailureMechanism mechanism, FailureMechanismType type, PersistenceRegistry registry)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            var entity = Create <FailureMechanismEntity>(mechanism, registry);

            entity.FailureMechanismType      = (short)type;
            entity.CalculationsInputComments = mechanism.CalculationsInputComments.Body.DeepClone();

            return(entity);
        }
Пример #8
0
        /// <summary>
        /// Creates a <see cref="FailureMechanismEntity"/> based on the information of the <see cref="IFailureMechanism"/>.
        /// </summary>
        /// <param name="mechanism">The failure mechanism to create a database entity for.</param>
        /// <param name="type">The type of the failure mechanism that is being created.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <returns>A new <see cref="FailureMechanismEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception>
        internal static FailureMechanismEntity Create(this IFailureMechanism mechanism, FailureMechanismType type, PersistenceRegistry registry)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            var entity = Create <FailureMechanismEntity>(mechanism, registry);

            entity.FailureMechanismType = (short)type;
            return(entity);
        }