public IEnumerable <PowerPlantResult> Post(ProductionPlanRequest productionPlanRequest) { // Map DTO to core entity var plan = mapper.MapToProductionPlan(productionPlanRequest); // Execute core logics var result = productionPlanner.Plan(plan); // Create initial results which is combined with result return from core. // This is to make sure power plants that generate no power is also returned in the api response. // The core does not return power plants that do not generate power. var initialResults = productionPlanRequest.PowerPlants.Select(p => new PowerPlantResult() { PowerPlantName = p.Name, Power = 0 }); // Map and return result. return(result.Select(p => mapper.Map <Models.PowerPlantResult>(p)).Union(initialResults)); }
public void GivenAProductionPlanShouldDispatchLoad() { // Arrange var gasPlant = new GasPowerPlant() { Name = "Power Plant #1", Efficiency = 50, GasPrice = 12.5M, MinimumPower = 50, MaximumPower = 150 }; var windPlant = new WindPowerPlant() { Name = "Power Plant #2", Efficiency = 0, WindPercentage = 75, MinimumPower = 0, MaximumPower = 100 }; var turboJetPlant = new TurboJetPowerPlant() { Name = "Power Plant #3", Efficiency = 25, KerosinePrice = 25M, MinimumPower = 100, MaximumPower = 300 }; var expectedLoadForWindPlant = 75; // Based on MaximumPower * WindPercentage var expectedLoadForGasPlant = 75; // (250 - 75 - 100); Cannot be set to the max since the turbo jet has a minimum of 100. var expectedLoadForTurboJetPlant = 100; // Need to match minimum load var productionPlan = new Core.Entities.ProductionPlan() { Load = 250, PowerPlants = new List <PowerPlant> { gasPlant, windPlant, turboJetPlant } }; // Act var powerPlantLoads = new List <PowerPlantLoad>(productionPlanner.Plan(productionPlan)); // Assert Assert.Equal(3, powerPlantLoads.Count); Assert.Same(windPlant, powerPlantLoads[0].PowerPlant); Assert.Equal(expectedLoadForWindPlant, powerPlantLoads[0].Load); Assert.Same(gasPlant, powerPlantLoads[1].PowerPlant); Assert.Equal(expectedLoadForGasPlant, powerPlantLoads[1].Load); Assert.Same(turboJetPlant, powerPlantLoads[2].PowerPlant); Assert.Equal(expectedLoadForTurboJetPlant, powerPlantLoads[2].Load); }