public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned() { // Given var random = new Random(21); var entity = new PipingSoilProfileEntity { Name = "testName", Bottom = random.NextDouble(), SourceType = Convert.ToByte(random.NextEnumValue <SoilProfileType>()), PipingSoilLayerEntities = { new PipingSoilLayerEntity { Top = random.NextDouble() + 1 } } }; var collector = new ReadConversionCollector(); PipingSoilProfile profile = entity.Read(collector); // When PipingSoilProfile secondProfile = entity.Read(collector); // Then Assert.AreSame(profile, secondProfile); }
public void Read_WithNullValues_ReturnsPipingSoilProfileWithNaNValues() { // Setup var entity = new PipingSoilProfileEntity { Name = nameof(PipingSoilProfileEntity), PipingSoilLayerEntities = { new PipingSoilLayerEntity { MaterialName = nameof(PipingSoilLayerEntity) } } }; var collector = new ReadConversionCollector(); // Call PipingSoilProfile profile = entity.Read(collector); // Assert Assert.IsNotNull(profile); Assert.AreEqual(entity.Name, profile.Name); Assert.IsNaN(profile.Bottom); Assert.AreEqual(entity.PipingSoilLayerEntities.Count, profile.Layers.Count()); PipingSoilLayer layer = profile.Layers.ElementAt(0); Assert.AreEqual(entity.PipingSoilLayerEntities.First().MaterialName, layer.MaterialName); }
public void Read_CollectorNull_ThrowsArgumentNullException() { // Setup var entity = new PipingSoilProfileEntity(); // Call TestDelegate test = () => entity.Read(null); // Assert string parameter = Assert.Throws <ArgumentNullException>(test).ParamName; Assert.AreEqual("collector", parameter); }
public void Read_WithCollector_ReturnsNewPipingSoilProfileWithPropertiesSet() { // Setup var random = new Random(21); double bottom = random.NextDouble(); var sourceType = random.NextEnumValue <SoilProfileType>(); var entity = new PipingSoilProfileEntity { Name = "testName", Bottom = bottom, SourceType = Convert.ToByte(sourceType), PipingSoilLayerEntities = { new PipingSoilLayerEntity { Top = bottom + 0.5, MaterialName = "A", Order = 1 }, new PipingSoilLayerEntity { Top = bottom + 1.2, MaterialName = "B", Order = 0 } } }; var collector = new ReadConversionCollector(); // Call PipingSoilProfile profile = entity.Read(collector); // Assert Assert.IsNotNull(profile); Assert.AreEqual(entity.Name, profile.Name); Assert.AreEqual(bottom, profile.Bottom, 1e-6); Assert.AreEqual(sourceType, profile.SoilProfileSourceType); CollectionAssert.AreEqual(new[] { "B", "A" }, profile.Layers.Select(l => l.MaterialName)); }