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)); }
public void Read_DifferentStochasticSoilProfileEntitiesWithSame2dProfile_ReturnsStochasticSoilProfilesWithSameSoilProfile() { // Setup var random = new Random(21); double probability = random.NextDouble(); var soilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity { Name = "SoilProfile", MacroStabilityInwardsSoilLayerTwoDEntities = { MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() } }; var firstEntity = new MacroStabilityInwardsStochasticSoilProfileEntity { Probability = probability, MacroStabilityInwardsSoilProfileTwoDEntity = soilProfileTwoDEntity }; var secondEntity = new MacroStabilityInwardsStochasticSoilProfileEntity { Probability = 1 - probability, MacroStabilityInwardsSoilProfileTwoDEntity = soilProfileTwoDEntity }; var collector = new ReadConversionCollector(); MacroStabilityInwardsStochasticSoilProfile firstStochasticSoilProfile = firstEntity.Read(collector); // Call MacroStabilityInwardsStochasticSoilProfile secondStochasticSoilProfile = secondEntity.Read(collector); // Assert Assert.AreNotSame(firstStochasticSoilProfile, secondStochasticSoilProfile); Assert.AreSame(firstStochasticSoilProfile.SoilProfile, secondStochasticSoilProfile.SoilProfile); }
public void Read_WithCollectorAnd2dProfile_ReturnsStochasticSoilProfileWithPropertiesSet() { // Setup var random = new Random(21); var entity = new MacroStabilityInwardsStochasticSoilProfileEntity { Probability = random.NextDouble(), MacroStabilityInwardsSoilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity { Name = "SoilProfile", MacroStabilityInwardsSoilLayerTwoDEntities = { MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() } } }; var collector = new ReadConversionCollector(); // Call MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = entity.Read(collector); // Assert Assert.IsNotNull(stochasticSoilProfile); Assert.AreEqual(entity.Probability, stochasticSoilProfile.Probability, 1e-6); IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> profile = stochasticSoilProfile.SoilProfile; Assert.IsInstanceOf <MacroStabilityInwardsSoilProfile2D>(profile); Assert.AreEqual(entity.MacroStabilityInwardsSoilProfileTwoDEntity.Name, profile.Name); }
public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned() { // Given var entity = new MacroStabilityInwardsSoilProfileTwoDEntity { Name = "testName", MacroStabilityInwardsSoilLayerTwoDEntities = { MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity() } }; var collector = new ReadConversionCollector(); MacroStabilityInwardsSoilProfile2D profile = entity.Read(collector); // When MacroStabilityInwardsSoilProfile2D secondProfile = entity.Read(collector); // Then Assert.AreSame(profile, secondProfile); }
public void Read_WithNestedLayers_ReturnsMacroStabilityInwardsSoilLayer2DWithNestedLayers() { // Setup MacroStabilityInwardsSoilLayerTwoDEntity entity = MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity(); entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); // Call MacroStabilityInwardsSoilLayer2D layer = entity.Read(); // Assert Assert.IsNotNull(layer); Assert.AreEqual(entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Count, layer.NestedLayers.Count()); for (var i = 0; i < entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Count; i++) { AssertMacroStabilityInwardsSoilLayer2D(entity.MacroStabilityInwardsSoilLayerTwoDEntity1.ElementAt(i), layer.NestedLayers.ElementAt(i)); } }