public void ReadAsMacroStabilityInwardsStochasticSoilModel_SameStochasticSoilModelEntityMultipleTimes_ReturnSameStochasticSoilModel() { // Setup var random = new Random(21); string segmentPointsXml = new Point2DCollectionXmlSerializer().ToXml(new[] { new Point2D(random.NextDouble(), random.NextDouble()) }); var entity = new StochasticSoilModelEntity { Name = "StochasticSoilModel", StochasticSoilModelSegmentPointXml = segmentPointsXml, MacroStabilityInwardsStochasticSoilProfileEntities = { MacroStabilityInwardsStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity() } }; var collector = new ReadConversionCollector(); // Call MacroStabilityInwardsStochasticSoilModel soilModel1 = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector); MacroStabilityInwardsStochasticSoilModel soilModel2 = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector); // Assert Assert.AreSame(soilModel1, soilModel2); }
public void Read_EntityWithStochasticSoilModel_ReturnCalculationScenarioWithInputObjectWithStochasticSoilModelPropertiesSet() { // Setup var random = new Random(21); MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(); var stochasticSoilModelEntity = new StochasticSoilModelEntity(); var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(random.NextDouble(), MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D()); var stochasticSoilProfileEntity = new MacroStabilityInwardsStochasticSoilProfileEntity { StochasticSoilModelEntity = stochasticSoilModelEntity }; var collector = new ReadConversionCollector(); collector.Read(stochasticSoilModelEntity, stochasticSoilModel); collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile); MacroStabilityInwardsCalculationEntity entity = CreateValidCalculationEntity(); entity.MacroStabilityInwardsStochasticSoilProfileEntity = stochasticSoilProfileEntity; // Call MacroStabilityInwardsCalculationScenario calculation = entity.Read(collector); // Assert MacroStabilityInwardsInput inputParameters = calculation.InputParameters; Assert.AreSame(stochasticSoilModel, inputParameters.StochasticSoilModel); Assert.AreSame(stochasticSoilProfile, inputParameters.StochasticSoilProfile); }
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); }
/// <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); }
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); }
public void ReadAsMacroStabilityInwardsStochasticSoilModel_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 = "testName", StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(geometry), MacroStabilityInwardsStochasticSoilProfileEntities = { new MacroStabilityInwardsStochasticSoilProfileEntity { MacroStabilityInwardsSoilProfileOneDEntity = new MacroStabilityInwardsSoilProfileOneDEntity { MacroStabilityInwardsSoilLayerOneDEntities = { new MacroStabilityInwardsSoilLayerOneDEntity() }, Name = "A" }, Order = 1 }, new MacroStabilityInwardsStochasticSoilProfileEntity { MacroStabilityInwardsSoilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity { MacroStabilityInwardsSoilLayerTwoDEntities = { MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() }, Name = "B" }, Order = 0 } } }; var collector = new ReadConversionCollector(); // Call MacroStabilityInwardsStochasticSoilModel model = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector); // Assert Assert.IsNotNull(model); Assert.AreEqual(entity.Name, model.Name); CollectionAssert.AreEqual(geometry, model.Geometry); Assert.AreEqual(entity.MacroStabilityInwardsStochasticSoilProfileEntities.Count, model.StochasticSoilProfiles.Count()); CollectionAssert.AreEqual(new[] { "B", "A" }, model.StochasticSoilProfiles.Select(ssp => ssp.SoilProfile.Name)); }
/// <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); }
public void Create_WithStochasticSoilProfiles_ReturnsStochasticSoilModelEntityWithPropertiesSet() { // Setup var stochasticSoilProfiles = new[] { new MacroStabilityInwardsStochasticSoilProfile(0.1, MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D()), new MacroStabilityInwardsStochasticSoilProfile(0.9, MacroStabilityInwardsSoilProfile2DTestFactory.CreateMacroStabilityInwardsSoilProfile2D()) }; MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("Model", stochasticSoilProfiles); var registry = new PersistenceRegistry(); // Call StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); // Assert Assert.IsNotNull(entity); CollectionAssert.IsEmpty(entity.PipingStochasticSoilProfileEntities); Assert.AreEqual(stochasticSoilProfiles.Length, entity.MacroStabilityInwardsStochasticSoilProfileEntities.Count); MacroStabilityInwardsStochasticSoilProfile firstStochasticSoilProfile = stochasticSoilProfiles[0]; MacroStabilityInwardsStochasticSoilProfileEntity firstStochasticSoilProfileEntity = entity.MacroStabilityInwardsStochasticSoilProfileEntities.First(); Assert.AreEqual(firstStochasticSoilProfile.Probability, firstStochasticSoilProfileEntity.Probability); Assert.IsNotNull(firstStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileOneDEntity); Assert.IsNull(firstStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileTwoDEntity); MacroStabilityInwardsStochasticSoilProfile secondStochasticSoilProfile = stochasticSoilProfiles[1]; MacroStabilityInwardsStochasticSoilProfileEntity secondStochasticSoilProfileEntity = entity.MacroStabilityInwardsStochasticSoilProfileEntities.ElementAt(1); Assert.AreEqual(secondStochasticSoilProfile.Probability, secondStochasticSoilProfileEntity.Probability); Assert.IsNull(secondStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileOneDEntity); Assert.IsNotNull(secondStochasticSoilProfileEntity.MacroStabilityInwardsSoilProfileTwoDEntity); }
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)); }
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++)); } }
public void ReadAsPipingStochasticSoilModel_CollectorNull_ThrowsArgumentNullException() { // Setup var entity = new StochasticSoilModelEntity(); // Call TestDelegate test = () => entity.ReadAsPipingStochasticSoilModel(null); // Assert string parameter = Assert.Throws <ArgumentNullException>(test).ParamName; Assert.AreEqual("collector", parameter); }
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); }
public void Read_EntityWithStochasticSoilProfileEntityNotYetInCollector_CalculationWithCreatedStochasticSoilProfileAndRegisteredNewEntities() { // Setup var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity { PipingSoilProfileEntity = new PipingSoilProfileEntity { Name = "SoilProfile", PipingSoilLayerEntities = { new PipingSoilLayerEntity() } } }; var random = new Random(21); var geometry = new[] { new Point2D(random.NextDouble(), random.NextDouble()) }; var stochasticSoilModelEntity = new StochasticSoilModelEntity { Name = "StochasticSoilModel", StochasticSoilModelSegmentPointXml = new Point2DCollectionXmlSerializer().ToXml(geometry), PipingStochasticSoilProfileEntities = { stochasticSoilProfileEntity } }; stochasticSoilProfileEntity.StochasticSoilModelEntity = stochasticSoilModelEntity; var entity = new SemiProbabilisticPipingCalculationEntity { PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity, EntryPointL = 1, ExitPointL = 2, DampingFactorExitMean = 1, ScenarioContribution = 0 }; var collector = new ReadConversionCollector(); // Call entity.Read(collector); // Assert Assert.IsTrue(collector.Contains(stochasticSoilProfileEntity)); Assert.IsTrue(collector.ContainsPipingStochasticSoilModel(stochasticSoilModelEntity)); }
public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityInstanceReturned() { // Given MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(); var registry = new PersistenceRegistry(); StochasticSoilModelEntity firstEntity = stochasticSoilModel.Create(registry, 0); // When StochasticSoilModelEntity secondEntity = stochasticSoilModel.Create(registry, 0); // Then Assert.AreSame(firstEntity, secondEntity); }
public void Create_SameModelCreatedMultipleTimes_ReturnSameEntity() { // Setup PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A"); var registry = new PersistenceRegistry(); // Call StochasticSoilModelEntity entity1 = soilModel.Create(registry, 0); StochasticSoilModelEntity entity2 = soilModel.Create(registry, 0); // Assert Assert.AreSame(entity1, entity2); }
public void ReadAsPipingStochasticSoilModel_StochasticSoilModelSegmentPointXmlEmpty_ThrowsArgumentException() { // Setup var entity = new StochasticSoilModelEntity { Name = "Name", StochasticSoilModelSegmentPointXml = string.Empty }; // Call TestDelegate test = () => entity.ReadAsPipingStochasticSoilModel(new ReadConversionCollector()); // Assert string paramName = Assert.Throws <ArgumentException>(test).ParamName; Assert.AreEqual("xml", paramName); }
public void Create_WithValidProperties_ReturnsStochasticSoilModelEntityWithPropertiesSet() { // Setup var random = new Random(1); int order = random.Next(); MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(nameof(MacroStabilityInwardsStochasticSoilModel)); var registry = new PersistenceRegistry(); // Call StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, order); // Assert Assert.IsNotNull(entity); Assert.AreEqual(stochasticSoilModel.Name, entity.Name); Assert.AreEqual(order, entity.Order); CollectionAssert.IsEmpty(entity.PipingStochasticSoilProfileEntities); }
public void Create_WithGeometryPoints_ReturnsStochasticSoilModelEntityWithPropertiesAndStochasticSoilModelSegmentPointEntitiesSet() { // Setup var random = new Random(31); PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("testName", new[] { new Point2D(random.NextDouble(), random.NextDouble()), new Point2D(random.NextDouble(), random.NextDouble()) }); var registry = new PersistenceRegistry(); // Call StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); // Assert Assert.IsNotNull(entity); string expectedXml = new Point2DCollectionXmlSerializer().ToXml(stochasticSoilModel.Geometry); Assert.AreEqual(expectedXml, entity.StochasticSoilModelSegmentPointXml); }
public void Create_WithStochasticSoilProfiles_ReturnsStochasticSoilModelEntityWithPropertiesAndPipingStochasticSoilProfileEntitiesSet() { // Setup PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("testName", new[] { new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile()) }); var registry = new PersistenceRegistry(); // Call StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0); // Assert Assert.IsNotNull(entity); Assert.AreEqual(stochasticSoilModel.StochasticSoilProfiles.Count(), entity.PipingStochasticSoilProfileEntities.Count); PipingStochasticSoilProfileEntity stochastEntity = entity.PipingStochasticSoilProfileEntities.Single(); Assert.AreEqual(stochasticSoilModel.StochasticSoilProfiles.Single().Probability, stochastEntity.Probability); Assert.IsNotNull(stochastEntity.PipingSoilProfileEntity); CollectionAssert.IsEmpty(entity.MacroStabilityInwardsStochasticSoilProfileEntities); }
private static void AssertStochasticSoilModel(PipingStochasticSoilModel model, StochasticSoilModelEntity entity) { Assert.AreEqual(model.Name, entity.Name); Assert.AreEqual(model.StochasticSoilProfiles.Count(), entity.PipingStochasticSoilProfileEntities.Count); CollectionAssert.IsEmpty(entity.MacroStabilityInwardsStochasticSoilProfileEntities); }
private static IEnumerable <PipingStochasticSoilProfile> ReadPipingStochasticSoilProfiles(this StochasticSoilModelEntity entity, ReadConversionCollector collector) { foreach (PipingStochasticSoilProfileEntity stochasticSoilProfileEntity in entity.PipingStochasticSoilProfileEntities .OrderBy(ssp => ssp.Order)) { yield return(stochasticSoilProfileEntity.Read(collector)); } }
/// <summary> /// Registers a create operation for <paramref name="model"/> and the <paramref name="entity"/> /// that was constructed with the information. /// </summary> /// <param name="entity">The <see cref="StochasticSoilModelEntity"/> to be registered.</param> /// <param name="model">The <see cref="MacroStabilityInwardsStochasticSoilModel"/> to be registered.</param> /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception> internal void Register(StochasticSoilModelEntity entity, MacroStabilityInwardsStochasticSoilModel model) { Register(macroStabilityInwardsStochasticSoilModels, entity, model); }
/// <summary> /// Registers a create operation for <paramref name="model"/> and the <paramref name="entity"/> /// that was constructed with the information. /// </summary> /// <param name="entity">The <see cref="StochasticSoilModelEntity"/> to be registered.</param> /// <param name="model">The <see cref="PipingStochasticSoilModel"/> to be registered.</param> /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception> internal void Register(StochasticSoilModelEntity entity, PipingStochasticSoilModel model) { Register(pipingStochasticSoilModels, entity, model); }
private static IEnumerable <MacroStabilityInwardsStochasticSoilProfile> ReadMacroStabilityInwardsStochasticSoilProfiles(this StochasticSoilModelEntity entity, ReadConversionCollector collector) { foreach (MacroStabilityInwardsStochasticSoilProfileEntity stochasticSoilProfileEntity in entity.MacroStabilityInwardsStochasticSoilProfileEntities .OrderBy(ssp => ssp.Order)) { yield return(stochasticSoilProfileEntity.Read(collector)); } }
private static void AssertStochasticSoilModel(MacroStabilityInwardsStochasticSoilModel model, StochasticSoilModelEntity entity) { Assert.AreEqual(model.Name, entity.Name); Assert.AreEqual(model.StochasticSoilProfiles.Count(), entity.MacroStabilityInwardsStochasticSoilProfileEntities.Count); }