Exemplo n.º 1
0
        public void ChildNodeObjects_Always_ReturnsChildrenOfData()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("Name", new[]
            {
                new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile()),
                new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile())
            });

            var failureMechanism = new PipingFailureMechanism();
            var stochasticSoilModelCollectionContext = new PipingStochasticSoilModelCollectionContext(
                failureMechanism.StochasticSoilModels,
                failureMechanism,
                assessmentSection);

            failureMechanism.StochasticSoilModels.AddRange(new[]
            {
                stochasticSoilModel
            }, "path");

            // Call
            object[] objects = info.ChildNodeObjects(stochasticSoilModelCollectionContext);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                stochasticSoilModel
            }, objects);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes a given <see cref="PipingStochasticSoilModel"/> from the <see cref="PipingFailureMechanism"/>
        /// and clears all data that depends on it, either directly or indirectly.
        /// </summary>
        /// <param name="failureMechanism">The failure mechanism containing <paramref name="soilModel"/>.</param>
        /// <param name="soilModel">The soil model residing in <paramref name="failureMechanism"/>
        /// that should be removed.</param>
        /// <returns>All observable objects affected by this method.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="failureMechanism"/>
        /// or <paramref name="soilModel"/> is <c>null</c>.</exception>
        public static IEnumerable <IObservable> RemoveStochasticSoilModel(PipingFailureMechanism failureMechanism,
                                                                          PipingStochasticSoilModel soilModel)
        {
            if (failureMechanism == null)
            {
                throw new ArgumentNullException(nameof(failureMechanism));
            }

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

            var changedObservables = new List <IObservable>();

            IEnumerable <IPipingCalculationScenario <PipingInput> > pipingCalculations =
                failureMechanism.Calculations
                .Cast <IPipingCalculationScenario <PipingInput> >()
                .Where(pcs => ReferenceEquals(pcs.InputParameters.StochasticSoilModel, soilModel));

            foreach (IPipingCalculationScenario <PipingInput> pipingCalculation in pipingCalculations)
            {
                changedObservables.AddRange(RiskeerCommonDataSynchronizationService.ClearCalculationOutput(pipingCalculation));
                changedObservables.AddRange(ClearStochasticSoilModel(pipingCalculation.InputParameters));
            }

            failureMechanism.StochasticSoilModels.Remove(soilModel);
            changedObservables.Add(failureMechanism.StochasticSoilModels);

            return(changedObservables);
        }
Exemplo n.º 3
0
        public void Update_ModelWithAddedProfile_ProfileAdded()
        {
            // Setup
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                CreateStochasticSoilProfile()
            });

            var expectedAddedProfile             = new PipingStochasticSoilProfile(0.2, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                expectedAddedProfile,
                CreateStochasticSoilProfile()
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            Assert.AreEqual(2, otherModel.StochasticSoilProfiles.Count());
            Assert.AreEqual(expectedAddedProfile, otherModel.StochasticSoilProfiles.First());

            CollectionAssert.AreEqual(new[]
            {
                expectedAddedProfile
            }, difference.AddedProfiles);
            CollectionAssert.IsEmpty(difference.UpdatedProfiles);
            CollectionAssert.IsEmpty(difference.RemovedProfiles);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="StochasticSoilModelEntity"/> based on the information of the <see cref="PipingStochasticSoilModel"/>.
        /// </summary>
        /// <param name="model">The model to create a database entity for.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <param name="order">Index at which this instance resides inside its parent container.</param>
        /// <returns>A new <see cref="StochasticSoilModelEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        internal static StochasticSoilModelEntity Create(this PipingStochasticSoilModel model,
                                                         PersistenceRegistry registry,
                                                         int order)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

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

            if (registry.Contains(model))
            {
                return(registry.Get(model));
            }

            var entity = new StochasticSoilModelEntity
            {
                Name = model.Name.DeepClone(),
                StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(model.Geometry),
                Order = order
            };

            AddEntitiesForStochasticSoilProfiles(model, registry, entity);

            registry.Register(entity, model);
            return(entity);
        }
Exemplo n.º 6
0
        public void Constructor_ValidParameters_ExpectedValues()
        {
            // Setup
            const string name     = "name";
            var          geometry = new[]
            {
                new Point2D(1, 1)
            };

            PipingStochasticSoilProfile[] stochasticSoilProfiles =
            {
                CreateStochasticSoilProfile()
            };

            // Call
            var model = new PipingStochasticSoilModel(name, geometry, stochasticSoilProfiles);

            // Assert
            Assert.IsInstanceOf <Observable>(model);
            Assert.IsInstanceOf <IMechanismStochasticSoilModel>(model);

            Assert.AreEqual(name, model.Name);
            Assert.AreSame(geometry, model.Geometry);
            CollectionAssert.AreEqual(stochasticSoilProfiles, model.StochasticSoilProfiles);
            Assert.AreEqual(name, model.ToString());
        }
        public void Read_EntityWithStochasticSoilModelEntityInCollector_CalculationHasAlreadyReadStochasticSoilModel()
        {
            // Setup
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();
            var stochasticSoilModelEntity = new StochasticSoilModelEntity();

            var stochasticSoilProfile       = new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity
            {
                StochasticSoilModelEntity = stochasticSoilModelEntity
            };

            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity,
                EntryPointL           = 1,
                ExitPointL            = 2,
                DampingFactorExitMean = 1,
                ScenarioContribution  = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile);
            collector.Read(stochasticSoilModelEntity, stochasticSoilModel);

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(stochasticSoilProfile, calculation.InputParameters.StochasticSoilProfile);
            Assert.AreSame(stochasticSoilModel, calculation.InputParameters.StochasticSoilModel);
        }
Exemplo n.º 8
0
        public void Update_ModelWithUpdatedProfile_ProfileUpdated()
        {
            // Setup
            const string profileName            = "A";
            var          expectedUpdatedProfile = new PipingStochasticSoilProfile(
                0.2,
                new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile1D));
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                expectedUpdatedProfile
            });
            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                new PipingStochasticSoilProfile(0.2,
                                                new PipingSoilProfile(profileName, -1, CreateLayers(), SoilProfileType.SoilProfile1D))
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            Assert.AreEqual(1, otherModel.StochasticSoilProfiles.Count());
            Assert.AreEqual(expectedUpdatedProfile, otherModel.StochasticSoilProfiles.First());

            CollectionAssert.IsEmpty(difference.AddedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                expectedUpdatedProfile
            }, difference.UpdatedProfiles);
            CollectionAssert.IsEmpty(difference.RemovedProfiles);
        }
        public void ReadAsPipingStochasticSoilModel_SameStochasticSoilModelEntityMultipleTimes_ReturnSameStochasticSoilModel()
        {
            // Setup
            var random   = new Random(21);
            var geometry = new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble())
            };
            var entity = new StochasticSoilModelEntity
            {
                Name = "StochasticSoilModel",
                StochasticSoilModelSegmentPointXml  = new Point2DCollectionXmlSerializer().ToXml(geometry),
                PipingStochasticSoilProfileEntities =
                {
                    PipingStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity()
                }
            };

            var collector = new ReadConversionCollector();

            // Call
            PipingStochasticSoilModel soilModel1 = entity.ReadAsPipingStochasticSoilModel(collector);
            PipingStochasticSoilModel soilModel2 = entity.ReadAsPipingStochasticSoilModel(collector);

            // Assert
            Assert.AreSame(soilModel1, soilModel2);
        }
        /// <summary>
        /// Reads the <see cref="StochasticSoilModelEntity"/> and use the information to construct
        /// a <see cref="PipingStochasticSoilModel"/>.
        /// </summary>
        /// <param name="entity">The <see cref="StochasticSoilModelEntity"/> to create <see cref="PipingStochasticSoilModel"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="PipingStochasticSoilModel"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <see cref="StochasticSoilModelEntity.StochasticSoilModelSegmentPointXml"/>
        /// of <paramref name="entity"/> is empty.</exception>
        public static PipingStochasticSoilModel ReadAsPipingStochasticSoilModel(this StochasticSoilModelEntity entity,
                                                                                ReadConversionCollector collector)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

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

            if (collector.ContainsPipingStochasticSoilModel(entity))
            {
                return(collector.GetPipingStochasticSoilModel(entity));
            }

            Point2D[] geometry = ReadSegmentPoints(entity.StochasticSoilModelSegmentPointXml).ToArray();
            PipingStochasticSoilProfile[] stochasticSoilProfiles = ReadPipingStochasticSoilProfiles(entity, collector).ToArray();
            var model = new PipingStochasticSoilModel(entity.Name, geometry, stochasticSoilProfiles);

            collector.Read(entity, model);

            return(model);
        }
Exemplo n.º 11
0
        public void Update_ModelWithRemovedProfileSameNameOtherType_ProfileRemoved()
        {
            // Setup
            const string profileName            = "A";
            var          soilProfile            = new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile1D);
            var          expectedRemovedProfile = new PipingStochasticSoilProfile(0.2, soilProfile);
            var          newProfile             = new PipingStochasticSoilProfile(
                0.2,
                new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile2D));
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                CreateStochasticSoilProfile(),
                expectedRemovedProfile
            });

            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                CreateStochasticSoilProfile(),
                newProfile
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                newProfile
            }, difference.AddedProfiles);
            CollectionAssert.IsEmpty(difference.UpdatedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                expectedRemovedProfile
            }, difference.RemovedProfiles);
        }
Exemplo n.º 12
0
        public void ContextMenuStrip_Always_CallsBuilder()
        {
            // Setup
            PipingStochasticSoilModel model = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();

            var mocks = new MockRepository();

            var menuBuilder = mocks.StrictMock <IContextMenuBuilder>();

            using (mocks.Ordered())
            {
                menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder);
                menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder);
                menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
                menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder);
                menuBuilder.Expect(mb => mb.Build()).Return(null);
            }

            using (var treeViewControl = new TreeViewControl())
            {
                var gui = mocks.Stub <IGui>();
                gui.Stub(g => g.Get(model, treeViewControl)).Return(menuBuilder);
                mocks.ReplayAll();

                plugin.Gui = gui;

                // Call
                info.ContextMenuStrip(model, null, treeViewControl);
            }

            // Assert
            mocks.VerifyAll();
        }
        public void UpdateModelWithImportedData_WithCurrentModelAndImportedModel_ModelReplaced()
        {
            // Setup
            PipingStochasticSoilModel existingModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("existing");

            var pipingFailureMechanism = new PipingFailureMechanism();

            pipingFailureMechanism.StochasticSoilModels.AddRange(new[]
            {
                existingModel
            }, sourceFilePath);
            var strategy = new PipingStochasticSoilModelReplaceDataStrategy(pipingFailureMechanism);
            PipingStochasticSoilModel readModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("read");

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

            // Assert
            Assert.AreSame(readModel, pipingFailureMechanism.StochasticSoilModels[0]);
            CollectionAssert.AreEqual(new[]
            {
                pipingFailureMechanism.StochasticSoilModels
            }, affectedObjects);
        }
Exemplo n.º 14
0
        public void Create_StochasticSoilProfileSet_EntityHasStochasticSoilProfileEntity()
        {
            // Setup
            PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
            var stochasticSoilProfile     = new PipingStochasticSoilProfile(0.6, soilProfile);

            PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A", new[]
            {
                stochasticSoilProfile
            });

            var registry = new PersistenceRegistry();
            StochasticSoilModelEntity soilModelEntity = soilModel.Create(registry, 0);

            var calculation = new ProbabilisticPipingCalculationScenario
            {
                InputParameters =
                {
                    StochasticSoilModel   = soilModel,
                    StochasticSoilProfile = stochasticSoilProfile
                }
            };

            // Call
            ProbabilisticPipingCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            PipingStochasticSoilProfileEntity expectedStochasticSoilProfileEntity = soilModelEntity.PipingStochasticSoilProfileEntities.First();

            Assert.AreSame(expectedStochasticSoilProfileEntity, entity.PipingStochasticSoilProfileEntity);
            Assert.IsTrue(registry.Contains(soilModel));
        }
Exemplo n.º 15
0
        public void GivenViewWithStochasticSoilModels_WhenStochasticSoilModelsUpdatedAndNotified_ThenMapDataUpdated()
        {
            // Given
            var failureMechanism = new PipingFailureMechanism();

            PipingFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub());

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("", new[]
            {
                new Point2D(1, 2),
                new Point2D(1, 2)
            });

            var stochasticSoilModelMapData = (MapLineData)map.Data.Collection.ElementAt(stochasticSoilModelsIndex);

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
            observers[stochasticSoilModelsIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            // When
            failureMechanism.StochasticSoilModels.AddRange(new[]
            {
                stochasticSoilModel
            }, "path");
            failureMechanism.StochasticSoilModels.NotifyObservers();

            // Then
            AssertStochasticSoilModelsMapData(failureMechanism.StochasticSoilModels, stochasticSoilModelMapData);
            mocks.VerifyAll();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Assigns the stochastic soil model.
        /// </summary>
        /// <param name="calculationConfiguration">The calculation read from the imported file.</param>
        /// <param name="pipingCalculation">The calculation to configure.</param>
        /// <returns><c>false</c> when
        /// <list type="bullet">
        /// <item>the <paramref name="calculationConfiguration"/> has a <see cref="PipingStochasticSoilModel"/> set
        /// which is not available in the failure mechanism.</item>
        /// <item>The <see cref="PipingStochasticSoilModel"/> does not intersect with the <see cref="PipingSurfaceLine"/>
        /// when this is set.</item>
        /// </list>
        /// <c>true</c> otherwise.</returns>
        private bool TrySetStochasticSoilModel(PipingCalculationConfiguration calculationConfiguration,
                                               IPipingCalculationScenario <PipingInput> pipingCalculation)
        {
            if (calculationConfiguration.StochasticSoilModelName != null)
            {
                PipingStochasticSoilModel soilModel = failureMechanism.StochasticSoilModels
                                                      .FirstOrDefault(ssm => ssm.Name == calculationConfiguration.StochasticSoilModelName);

                if (soilModel == null)
                {
                    Log.LogCalculationConversionError(string.Format(
                                                          Resources.PipingCalculationConfigurationImporter_ReadStochasticSoilModel_Stochastische_soil_model_0_does_not_exist,
                                                          calculationConfiguration.StochasticSoilModelName),
                                                      pipingCalculation.Name);
                    return(false);
                }

                if (pipingCalculation.InputParameters.SurfaceLine != null &&
                    !soilModel.IntersectsWithSurfaceLineGeometry(pipingCalculation.InputParameters.SurfaceLine))
                {
                    Log.LogCalculationConversionError(string.Format(
                                                          Resources.PipingCalculationConfigurationImporter_ReadStochasticSoilModel_Stochastische_soil_model_0_does_not_intersect_with_surfaceLine_1,
                                                          calculationConfiguration.StochasticSoilModelName,
                                                          calculationConfiguration.SurfaceLineName),
                                                      pipingCalculation.Name);
                    return(false);
                }

                pipingCalculation.InputParameters.StochasticSoilModel = soilModel;
            }

            return(true);
        }
Exemplo n.º 17
0
        public void Update_ModelWithUpdatedProperties_PropertiesUpdated()
        {
            // Setup
            var model = new PipingStochasticSoilModel("name", new[]
            {
                new Point2D(1, 2),
                new Point2D(4, 5)
            }, new[]
            {
                CreateStochasticSoilProfile()
            });

            const string expectedName     = "otherName";
            var          expectedGeometry = new[]
            {
                new Point2D(4, 2)
            };

            var otherModel = new PipingStochasticSoilModel(expectedName, expectedGeometry, new[]
            {
                CreateStochasticSoilProfile()
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            Assert.AreEqual(expectedName, model.Name);
            CollectionAssert.AreEqual(expectedGeometry, model.Geometry);

            CollectionAssert.IsEmpty(difference.AddedProfiles);
            CollectionAssert.IsEmpty(difference.UpdatedProfiles);
            CollectionAssert.IsEmpty(difference.RemovedProfiles);
        }
Exemplo n.º 18
0
        public void Update_ModelsWithAddedProfilesWithSameNames_ThrowsInvalidOperationException()
        {
            // Setup
            const string profileName             = "Name of the profile";
            var          addedProfile            = new PipingStochasticSoilProfile(0.2, PipingSoilProfileTestFactory.CreatePipingSoilProfile(profileName));
            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                addedProfile
            });

            PipingSoilProfile soilProfile        = PipingSoilProfileTestFactory.CreatePipingSoilProfile(profileName);
            var existingStochasticSoilProfileOne = new PipingStochasticSoilProfile(0.2, soilProfile);
            var existingStochasticSoilProfileTwo = new PipingStochasticSoilProfile(0.3, soilProfile);
            PipingStochasticSoilModel model      = CreateValidModel(new[]
            {
                existingStochasticSoilProfileOne,
                existingStochasticSoilProfileTwo
            });

            // Call
            TestDelegate call = () => model.Update(otherModel);

            // Assert
            Assert.Throws <InvalidOperationException>(call);

            Assert.AreEqual(1, otherModel.StochasticSoilProfiles.Count());
            Assert.AreEqual(addedProfile, otherModel.StochasticSoilProfiles.First());

            Assert.AreEqual(2, model.StochasticSoilProfiles.Count());
            CollectionAssert.AreEqual(new[]
            {
                existingStochasticSoilProfileOne,
                existingStochasticSoilProfileTwo
            }, model.StochasticSoilProfiles);
        }
        public void ReadAsPipingStochasticSoilModel_WithValidEntity_ReturnsNewStochasticSoilModelWithPropertiesSet()
        {
            // Setup
            var random   = new Random(21);
            var geometry = new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble()),
                new Point2D(random.NextDouble(), random.NextDouble())
            };

            var entity = new StochasticSoilModelEntity
            {
                Name = "StochasticSoilModel",
                StochasticSoilModelSegmentPointXml  = new Point2DCollectionXmlSerializer().ToXml(geometry),
                PipingStochasticSoilProfileEntities =
                {
                    new PipingStochasticSoilProfileEntity
                    {
                        PipingSoilProfileEntity = new PipingSoilProfileEntity
                        {
                            PipingSoilLayerEntities =
                            {
                                new PipingSoilLayerEntity()
                            },
                            Name = "A"
                        },
                        Order = 1
                    },
                    new PipingStochasticSoilProfileEntity
                    {
                        PipingSoilProfileEntity = new PipingSoilProfileEntity
                        {
                            PipingSoilLayerEntities =
                            {
                                new PipingSoilLayerEntity()
                            },
                            Name = "B"
                        },
                        Order = 0
                    }
                }
            };
            var collector = new ReadConversionCollector();

            // Call
            PipingStochasticSoilModel model = entity.ReadAsPipingStochasticSoilModel(collector);

            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(entity.Name, model.Name);
            CollectionAssert.AreEqual(geometry, model.Geometry);

            Assert.AreEqual(entity.PipingStochasticSoilProfileEntities.Count, model.StochasticSoilProfiles.Count());
            CollectionAssert.AreEqual(new[]
            {
                "B",
                "A"
            }, model.StochasticSoilProfiles.Select(ssp => ssp.SoilProfile.Name));
        }
Exemplo n.º 20
0
        public void Update_WithOtherModel_PropertiesUpdated()
        {
            // Setup
            const string equalProfileName   = "nameA";
            var          stochasticProfileA = new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile(equalProfileName));
            var          stochasticProfileB = new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile("nameB"));
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                stochasticProfileA,
                stochasticProfileB
            });

            const string otherName     = "other name";
            var          otherGeometry = new[]
            {
                new Point2D(2, 0),
                new Point2D(3, 0)
            };
            var otherStochasticProfileA = new PipingStochasticSoilProfile(
                0.7, new PipingSoilProfile(equalProfileName, -1, new[]
            {
                new PipingSoilLayer(0)
            }, SoilProfileType.SoilProfile1D));
            var otherStochasticProfileB = new PipingStochasticSoilProfile(0.3, PipingSoilProfileTestFactory.CreatePipingSoilProfile("other profile name"));
            var otherModel = new PipingStochasticSoilModel(otherName, otherGeometry, new[]
            {
                otherStochasticProfileA,
                otherStochasticProfileB
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            Assert.AreEqual(otherName, model.Name);
            Assert.AreSame(otherGeometry, model.Geometry);

            PipingStochasticSoilProfile[] stochasticSoilProfiles = model.StochasticSoilProfiles.ToArray();
            Assert.AreEqual(2, stochasticSoilProfiles.Length);
            Assert.AreSame(stochasticProfileA, stochasticSoilProfiles[0]);
            Assert.AreSame(otherStochasticProfileA.SoilProfile, stochasticSoilProfiles[0].SoilProfile);
            Assert.AreNotSame(stochasticProfileB, stochasticSoilProfiles[1]);
            Assert.AreSame(otherStochasticProfileB.SoilProfile, stochasticSoilProfiles[1].SoilProfile);

            CollectionAssert.AreEqual(new[]
            {
                stochasticProfileA
            }, difference.UpdatedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                stochasticProfileB
            }, difference.RemovedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                otherStochasticProfileB
            }, difference.AddedProfiles);
        }
        public void GenerateCalculationItemsStructure_SurfaceLineIntersectingSoilModelAndGenerateSemiProbabilisticAndProbabilisticFalse_ReturnEmptyCollection()
        {
            // Setup
            var soilProfile1 = new PipingStochasticSoilProfile(
                0.3, new PipingSoilProfile("Profile 1", -10.0, new[]
            {
                new PipingSoilLayer(-5.0),
                new PipingSoilLayer(-2.0),
                new PipingSoilLayer(1.0)
            }, SoilProfileType.SoilProfile1D)
                );
            var soilProfile2 = new PipingStochasticSoilProfile(0.7, new PipingSoilProfile("Profile 2", -8.0, new[]
            {
                new PipingSoilLayer(-4.0),
                new PipingSoilLayer(0.0),
                new PipingSoilLayer(4.0)
            }, SoilProfileType.SoilProfile1D)
                                                               );

            var soilModel = new PipingStochasticSoilModel("A", new[]
            {
                new Point2D(1.0, 0.0),
                new Point2D(5.0, 0.0)
            }, new[]
            {
                soilProfile1,
                soilProfile2
            });

            PipingStochasticSoilModel[] availableSoilModels =
            {
                soilModel
            };

            var surfaceLine = new PipingSurfaceLine("surface line");

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(3.0, 5.0, 0.0),
                new Point3D(3.0, 0.0, 1.0),
                new Point3D(3.0, -5.0, 0.0)
            });

            PipingSurfaceLine[] surfaceLines =
            {
                surfaceLine
            };

            // Call
            IEnumerable <ICalculationBase> result = PipingCalculationConfigurationHelper.GenerateCalculationItemsStructure(
                surfaceLines, false, false,
                availableSoilModels).ToArray();

            // Assert
            CollectionAssert.IsEmpty(result);
        }
            public void Import_StochasticSoilProfileUnknown_LogMessageAndContinueImport()
            {
                // Setup
                string filePath = TestHelper.GetScratchPadPath(nameof(Import_StochasticSoilProfileUnknown_LogMessageAndContinueImport));

                SetCalculationType(Path.Combine(importerPath, "validConfigurationCalculationContainingUnknownSoilProfile.xml"), filePath);

                var calculationGroup = new CalculationGroup();
                var surfaceLine      = new PipingSurfaceLine("Profielschematisatie");

                surfaceLine.SetGeometry(new[]
                {
                    new Point3D(3.0, 5.0, 0.0),
                    new Point3D(3.0, 0.0, 1.0),
                    new Point3D(3.0, -5.0, 0.0)
                });
                PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(
                    "Ondergrondmodel",
                    new[]
                {
                    new Point2D(1.0, 0.0),
                    new Point2D(5.0, 0.0)
                });

                var pipingFailureMechanism = new PipingFailureMechanism();

                pipingFailureMechanism.SurfaceLines.AddRange(new[]
                {
                    surfaceLine
                }, "readerPath");
                pipingFailureMechanism.StochasticSoilModels.AddRange(new[]
                {
                    stochasticSoilModel
                }, "readerPath");

                var importer = new PipingCalculationConfigurationImporter(
                    filePath, calculationGroup, new HydraulicBoundaryLocation[0], pipingFailureMechanism);

                try
                {
                    // Call
                    var successful            = false;
                    void Call() => successful = importer.Import();

                    // Assert
                    const string expectedMessage = "De ondergrondschematisatie 'Ondergrondschematisatie' bestaat niet binnen het stochastische ondergrondmodel 'Ondergrondmodel'. " +
                                                   "Berekening 'Calculation' is overgeslagen.";
                    TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage, 2);
                    Assert.IsTrue(successful);
                    CollectionAssert.IsEmpty(calculationGroup.Children);
                }
                finally
                {
                    File.Delete(filePath);
                }
            }
Exemplo n.º 23
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 GetStochasticSoilModelsForSurfaceLine_SurfaceLineIntersectingSoilModel_ReturnSoilModel()
        {
            // Setup
            var soilProfile1 = new PipingStochasticSoilProfile(
                0.3, new PipingSoilProfile("Profile 1", -10.0, new[]
            {
                new PipingSoilLayer(-5.0),
                new PipingSoilLayer(-2.0),
                new PipingSoilLayer(1.0)
            }, SoilProfileType.SoilProfile1D));
            var soilProfile2 = new PipingStochasticSoilProfile(
                0.7, new PipingSoilProfile("Profile 2", -8.0, new[]
            {
                new PipingSoilLayer(-4.0),
                new PipingSoilLayer(0.0),
                new PipingSoilLayer(4.0)
            }, SoilProfileType.SoilProfile1D));

            var soilModel = new PipingStochasticSoilModel("A", new[]
            {
                new Point2D(1.0, 0.0),
                new Point2D(5.0, 0.0)
            }, new[]
            {
                soilProfile1,
                soilProfile2
            });

            PipingStochasticSoilModel[] availableSoilModels =
            {
                soilModel
            };

            var surfaceLine = new PipingSurfaceLine("surface line");

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(3.0, 5.0, 0.0),
                new Point3D(3.0, 0.0, 1.0),
                new Point3D(3.0, -5.0, 0.0)
            });

            // Call
            IEnumerable <PipingStochasticSoilModel> result = PipingCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine(
                surfaceLine,
                availableSoilModels);

            // Assert
            PipingStochasticSoilModel[] expected =
            {
                soilModel
            };
            CollectionAssert.AreEquivalent(expected, result);
        }
Exemplo n.º 25
0
        public void StochasticSoilModel_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged()
        {
            // Setup
            PipingStochasticSoilModel newModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();
            var newValue = new DataGridViewComboBoxItemWrapper <PipingStochasticSoilModel>(newModel);

            var calculation = new TestPipingCalculationScenario();

            // Call & Assert
            SetPropertyAndVerifyNotificationsAndOutputForCalculation(row => row.StochasticSoilModel = newValue, calculation);
        }
Exemplo n.º 26
0
        private static void AddEntitiesForStochasticSoilProfiles(PipingStochasticSoilModel model,
                                                                 PersistenceRegistry registry,
                                                                 StochasticSoilModelEntity entity)
        {
            var i = 0;

            foreach (PipingStochasticSoilProfile stochasticSoilProfile in model.StochasticSoilProfiles)
            {
                entity.PipingStochasticSoilProfileEntities.Add(stochasticSoilProfile.Create(registry, i++));
            }
        }
Exemplo n.º 27
0
        public void Text_Always_ReturnsTextFromStochasticSoilModel()
        {
            // Setup
            const string name = "test test 123";
            PipingStochasticSoilModel model = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(name);

            // Call
            string text = info.Text(model);

            // Assert
            Assert.AreEqual(name, text);
        }
        public void CreateInstance_WithStochasticSoilModel_NewPropertiesWithInputAsData()
        {
            // Setup
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();

            // Call
            IObjectProperties objectProperties = info.CreateInstance(stochasticSoilModel);

            // Assert
            Assert.IsInstanceOf <PipingStochasticSoilModelProperties>(objectProperties);
            Assert.AreSame(stochasticSoilModel, objectProperties.Data);
        }
        public void RemoveStochasticSoilModel_PipingFailureMechanismNull_ThrowsArgumentNullException()
        {
            // Setup
            PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();

            // Call
            void Call() => PipingDataSynchronizationService.RemoveStochasticSoilModel(null, soilModel);

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

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            const string name = "testName";
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel(name);
            var registry = new PersistenceRegistry();

            // Call
            StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0);

            // Assert
            TestHelper.AssertAreEqualButNotSame(name, entity.Name);
        }