コード例 #1
0
        public void UpdateModelWithImportedData_WithCurrentModelsAndImportedMultipleModelsWithSameName_ThrowsUpdateDataException()
        {
            // Setup
            const string nonUniqueName = "non-unique name";

            var targetCollection = new PipingStochasticSoilModelCollection();

            targetCollection.AddRange(new[]
            {
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(nonUniqueName)
            }, sourceFilePath);

            var strategy = new PipingStochasticSoilModelUpdateDataStrategy(new PipingFailureMechanism());

            PipingStochasticSoilModel[] importedStochasticSoilModels =
            {
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(nonUniqueName),
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(nonUniqueName)
            };

            // Call
            TestDelegate test = () => strategy.UpdateModelWithImportedData(importedStochasticSoilModels, sourceFilePath);

            // Assert
            var          exception       = Assert.Throws <UpdateDataException>(test);
            const string expectedMessage = "Geïmporteerde data moet unieke elementen bevatten.";

            Assert.AreEqual(expectedMessage, exception.Message);
        }
コード例 #2
0
        public void Create_WithStochasticSoilModels_ReturnsFailureMechanismEntityWithStochasticSoilModelEntities()
        {
            // Setup
            var failureMechanism = new PipingFailureMechanism();
            PipingStochasticSoilModelCollection stochasticSoilModels = failureMechanism.StochasticSoilModels;

            stochasticSoilModels.AddRange(new[]
            {
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name"),
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name2")
            }, "some/path/to/file");

            var registry = new PersistenceRegistry();

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

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(stochasticSoilModels.Count, entity.StochasticSoilModelEntities.Count);
            for (var i = 0; i < stochasticSoilModels.Count; i++)
            {
                AssertStochasticSoilModel(stochasticSoilModels[i],
                                          entity.StochasticSoilModelEntities.ElementAt(i));
            }

            string stochasticSoilModelCollectionSourcePath = entity.PipingFailureMechanismMetaEntities
                                                             .Single()
                                                             .StochasticSoilModelCollectionSourcePath;

            TestHelper.AssertAreEqualButNotSame(stochasticSoilModels.SourcePath, stochasticSoilModelCollectionSourcePath);
        }
コード例 #3
0
        public void UpdateModelWithImportedData_UpdateCurrentModelWithImportedModelWithOtherProfiles_ProfilesAdded()
        {
            // Setup
            const string modelsName = "same model";
            PipingStochasticSoilModel existingModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(modelsName);

            var failureMechanism = new PipingFailureMechanism();
            PipingStochasticSoilModelCollection targetCollection = failureMechanism.StochasticSoilModels;

            targetCollection.AddRange(new[]
            {
                existingModel
            }, sourceFilePath);

            var strategy = new PipingStochasticSoilModelUpdateDataStrategy(failureMechanism);
            PipingStochasticSoilModel readModel = CreateSimpleModel(modelsName, "new profile A", "new profile B");

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new[]
            {
                readModel
            }, sourceFilePath);

            // Assert
            Assert.AreEqual(1, targetCollection.Count);
            Assert.AreSame(existingModel, targetCollection[0]);
            Assert.AreEqual(2, targetCollection[0].StochasticSoilProfiles.Count());
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                targetCollection,
                existingModel
            }, affectedObjects);
        }
コード例 #4
0
        public void CurrentPath_StochasticSoilModelCollectionHasPathSet_ReturnsExpectedPath()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            const string expectedFilePath = "some/path";
            var          stochasticSoilModelCollection = new PipingStochasticSoilModelCollection();

            stochasticSoilModelCollection.AddRange(new[]
            {
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel()
            }, expectedFilePath);

            var failureMechanism = new PipingFailureMechanism();

            var context = new PipingStochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection);

            // Call
            string currentPath = updateInfo.CurrentPath(context);

            // Assert
            Assert.AreEqual(expectedFilePath, currentPath);
            mocks.VerifyAll();
        }
コード例 #5
0
        public void UpdateModelWithImportedData_ProfilesAssignedToCalculationsWithOneImportedModelProfileRemoved_OneProfileRemovedCalculationUpdatedAccordingly()
        {
            // Setup
            const string modelsName = "same model";
            PipingStochasticSoilModel existingModel = CreateSimpleModel(modelsName, "Unaffected Profile", "Removed Profile");

            var failureMechanism = new PipingFailureMechanism();
            PipingStochasticSoilModelCollection targetCollection = failureMechanism.StochasticSoilModels;

            targetCollection.AddRange(new[]
            {
                existingModel
            }, sourceFilePath);

            PipingStochasticSoilProfile firstExistingProfile = existingModel.StochasticSoilProfiles.First();
            PipingStochasticSoilModel   readModel            = CreateSimpleModel(modelsName, firstExistingProfile.SoilProfile.Name);

            var calculationWithNotUpdatedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(0);
            calculationWithNotUpdatedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            var calculationWithDeletedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithDeletedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithDeletedProfile.InputParameters.StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(1);
            calculationWithDeletedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            failureMechanism.CalculationsGroup.Children.Add(calculationWithDeletedProfile);
            failureMechanism.CalculationsGroup.Children.Add(calculationWithNotUpdatedProfile);

            var strategy = new PipingStochasticSoilModelUpdateDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new[]
            {
                readModel
            }, sourceFilePath).ToArray();

            // Assert
            PipingStochasticSoilModel firstSoilModel = targetCollection[0];

            Assert.AreSame(existingModel, firstSoilModel);
            Assert.AreSame(firstExistingProfile, firstSoilModel.StochasticSoilProfiles.ElementAt(0));

            Assert.IsTrue(calculationWithNotUpdatedProfile.HasOutput);
            CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile);
            CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile.InputParameters);

            Assert.IsFalse(calculationWithDeletedProfile.HasOutput);
            Assert.IsNull(calculationWithDeletedProfile.InputParameters.StochasticSoilProfile);
            CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile);
            CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile.InputParameters);
        }
        public void Constructor_WithData_ReturnExpectedValues()
        {
            // Setup
            const string someFilePath = "location/to/a/file";
            var          collection   = new PipingStochasticSoilModelCollection();

            collection.AddRange(Enumerable.Empty <PipingStochasticSoilModel>(), someFilePath);

            // Call
            var properties = new PipingStochasticSoilModelCollectionProperties(collection);

            // Assert
            Assert.IsInstanceOf <ObjectProperties <PipingStochasticSoilModelCollection> >(properties);
            Assert.AreSame(collection, properties.Data);
            Assert.AreEqual(someFilePath, properties.SourcePath);
        }
        public void UpdateModelWithImportedData_CalculationWithOutputAssignedRemovedSoilModelAndProfile_CalculationUpdatedAndCalculationAndInputReturned()
        {
            // Setup
            PipingStochasticSoilModel existingModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();
            var calculation = new SemiProbabilisticPipingCalculationScenario
            {
                InputParameters =
                {
                    StochasticSoilModel   = existingModel,
                    StochasticSoilProfile = existingModel.StochasticSoilProfiles.First()
                },
                Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties())
            };

            var failureMechanism = new PipingFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculation);

            var strategy = new PipingStochasticSoilModelReplaceDataStrategy(failureMechanism);

            var targetCollection = new PipingStochasticSoilModelCollection();

            targetCollection.AddRange(new[]
            {
                existingModel
            }, sourceFilePath);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new List <PipingStochasticSoilModel>(), sourceFilePath).ToArray();

            // Assert
            Assert.IsFalse(calculation.HasOutput);
            Assert.IsNull(calculation.InputParameters.StochasticSoilModel);
            Assert.IsNull(calculation.InputParameters.StochasticSoilProfile);
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                calculation,
                calculation.InputParameters,
                failureMechanism.StochasticSoilModels
            }, affectedObjects);
        }
コード例 #8
0
        public void IsEnabled_SoilModelCollectionSourcePathSet_ReturnTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism    = new PipingFailureMechanism();
            var stochasticSoilModel = new PipingStochasticSoilModelCollection();

            stochasticSoilModel.AddRange(Enumerable.Empty <PipingStochasticSoilModel>(), "some/path");

            var context = new PipingStochasticSoilModelCollectionContext(stochasticSoilModel, failureMechanism, assessmentSection);

            // Call
            bool isEnabled = updateInfo.IsEnabled(context);

            // Assert
            Assert.IsTrue(isEnabled);
            mocks.VerifyAll();
        }
コード例 #9
0
        public void UpdateModelWithImportedData_ProfilesAssignedToCalculationsOneWithRemovedProfile_OnlyCalculationWithRemovedProfileUpdated()
        {
            // Setup
            const string modelsName = "same model";
            PipingStochasticSoilModel existingModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(modelsName, new[]
            {
                CreateStochasticSoilProfile("Removed Profile"),
                CreateStochasticSoilProfile("Unaffected Profile")
            });

            var failureMechanism = new PipingFailureMechanism();
            PipingStochasticSoilModelCollection targetCollection = failureMechanism.StochasticSoilModels;

            targetCollection.AddRange(new[]
            {
                existingModel
            }, sourceFilePath);
            PipingStochasticSoilProfile removedProfile    = existingModel.StochasticSoilProfiles.ElementAt(0);
            PipingStochasticSoilProfile unaffectedProfile = existingModel.StochasticSoilProfiles.ElementAt(1);

            PipingStochasticSoilModel readModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(modelsName, new[]
            {
                CreateStochasticSoilProfile("Unaffected Profile")
            });

            var calculationWithRemovedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithRemovedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithRemovedProfile.InputParameters.StochasticSoilProfile = removedProfile;
            calculationWithRemovedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            var calculationWithNotUpdatedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilProfile = unaffectedProfile;
            calculationWithNotUpdatedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            failureMechanism.CalculationsGroup.Children.Add(calculationWithNotUpdatedProfile);
            failureMechanism.CalculationsGroup.Children.Add(calculationWithRemovedProfile);

            var strategy = new PipingStochasticSoilModelUpdateDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new[]
            {
                readModel
            }, sourceFilePath).ToArray();

            // Assert
            PipingStochasticSoilModel firstSoilModel = targetCollection[0];

            Assert.AreSame(existingModel, firstSoilModel);
            Assert.AreEqual(1, firstSoilModel.StochasticSoilProfiles.Count());
            Assert.AreSame(unaffectedProfile, firstSoilModel.StochasticSoilProfiles.First());

            Assert.IsFalse(calculationWithRemovedProfile.HasOutput);
            Assert.IsNull(calculationWithRemovedProfile.InputParameters.StochasticSoilProfile);

            Assert.IsTrue(calculationWithNotUpdatedProfile.HasOutput);
            Assert.AreSame(unaffectedProfile, calculationWithNotUpdatedProfile.InputParameters.StochasticSoilProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                targetCollection,
                firstSoilModel,
                calculationWithRemovedProfile,
                calculationWithRemovedProfile.InputParameters
            }, affectedObjects);
        }