public void GivenTankWaterStub_ReturnsTankWaterDto() { // Arrange var tankWater = new TankWaterStub { WaterId = Guid.NewGuid(), Stage = WaterCycleStage.BuildingAnaerobic, Levels = new List <TankWaterLevelStub> { new TankWaterLevelStub { Metric = Metric.Units, Quantity = 23 } } }; // Act var result = tankWater.ToDto(); // Assert Assert.Multiple(() => { Assert.That(result.WaterId, Is.EqualTo(tankWater.WaterId)); Assert.That(result.Stage, Is.EqualTo(tankWater.Stage)); var tankWaterLevel = tankWater.Levels.FirstOrDefault(); var resultingTankWaterLevel = result.Levels.FirstOrDefault(); Assert.That(resultingTankWaterLevel, Is.Not.Null); Assert.That(resultingTankWaterLevel.Metric, Is.EqualTo(tankWaterLevel.Metric)); Assert.That(resultingTankWaterLevel.Quantity, Is.EqualTo(tankWaterLevel.Quantity)); }); }
public static TankWaterListDto ToDto(this TankWaterStub tankWater) { return(new TankWaterListDto { WaterId = tankWater.WaterId, Levels = tankWater.Levels? .Select(tankWaterLevel => tankWaterLevel.ToDto()) .ToList(), Stage = tankWater.Stage }); }