public void CanConvertFuelDtoToModel() { //setup FuelConverter fuelConverter = new FuelConverter(); FuelDto dto = new FuelDto { Fuels = new Dictionary <string, float> { { "gas(euro/MWh)", 13.4f }, { "kerosine(euro/MWh)", 50.8f }, { "co2(euro/ton)", 20f }, { "wind(%)", 60f } } }; var models = fuelConverter.ToModel(dto); var gas = models.Single(f => f.GetType() == typeof(GasFuel)); float gasPrice = gas.PricePerMwh; float co2PriceGaz = gas.Co2PricePerTon; Assert.AreEqual(gasPrice, 13.4f); Assert.AreEqual(co2PriceGaz, 20f); Fuel kerosine = models.Single(f => f.GetType() == typeof(KerosineFuel)); float kerosinePrice = kerosine.PricePerMwh; float co2Kerosine = kerosine.Co2PricePerTon; Assert.AreEqual(kerosinePrice, 50.8f); Assert.AreEqual(co2Kerosine, 20f); Fuel wind = models.Single(f => f.GetType() == typeof(WindFuel)); float windPrice = wind.PricePerMwh; float co2Wind = wind.Co2PricePerTon; float windPerCentage = ((WindFuel)wind).WindPower; Assert.AreEqual(windPrice, 0f); Assert.AreEqual(co2Wind, 20f); Assert.AreEqual(windPerCentage, 60f); }
public void CanComputeSamePriceButDiffrentPminLowPlan() { /**** * setup * */ IPowerPlantConverter converter = new PowerPlantConverter(); IFuelConverter fuelconverter = new FuelConverter(); IPayLoadConverter payLoadConverter = new PayLoadConverter(converter, fuelconverter); var service = new PowerPlantService(converter, payLoadConverter); //fuel Dictionnary var fuelsDict = new Dictionary <string, float> { { "gas(euro/MWh)", 13.4f }, { "kerosine(euro/MWh)", 50.8f }, { "co2(euro/ton)", 20f }, { "wind(%)", 60f } }; var pw1 = new PowerPlantInputDto { Name = "gasfirebig1", Type = "gasfired", Efficiency = 0.53f, Pmax = 460, Pmin = 100 }; var pw2 = new PowerPlantInputDto { Name = "gasfirebig2", Type = "gasfired", Efficiency = 0.53f, Pmax = 460, Pmin = 100 }; var pw3 = new PowerPlantInputDto { Name = "gasfiredsomewhatsmaller", Type = "gasfired", Efficiency = 0.53f, Pmax = 210, Pmin = 40 }; var pw4 = new PowerPlantInputDto { Name = "tj1", Type = "turbojet", Efficiency = 0.3f, Pmax = 16, Pmin = 0, }; var pw5 = new PowerPlantInputDto { Name = "windpark1", Type = "windturbine", Efficiency = 1f, Pmax = 150, Pmin = 0 }; var pw6 = new PowerPlantInputDto { Name = "windpark2", Type = "windturbine", Efficiency = 1f, Pmax = 36, Pmin = 0 }; var powerPlants = new List <PowerPlantInputDto> { pw1, pw2, pw3, pw4, pw5, pw6 }.ToArray(); //3 the payload var payload = new PayLoadDto { Load = 190, Fuels = fuelsDict, PowerPlants = powerPlants }; //act var result = service.Compute(payload); var exceptedResult = new[] { new PowerPlantInputDto { Name = "windpark1", Power = 90 }, new PowerPlantInputDto { Name = "windpark2", Power = 21.6f }, new PowerPlantInputDto { Name = "gasfirebig1", Power = 0 }, new PowerPlantInputDto { Name = "gasfirebig2", Power = 0 }, new PowerPlantInputDto { Name = "gasfiredsomewhatsmaller", Power = 78.4f }, new PowerPlantInputDto { Name = "tj1", Power = 0 } }; var hashet = new HashSet <PowerPlantInputDto>(result); Assert.IsTrue(hashet.SetEquals(exceptedResult)); }