public void CalculateAnnualCosts(double consumption) { if (consumption < 0) { throw new ArgumentException("Argument should not be less than zero", nameof(consumption)); } IAnnualCostsCalculationStrategy annualCostsCalculationStrategy; switch (Name) { case TariffConstants.BasicTariffName: annualCostsCalculationStrategy = new BasicAnnualCostsCalculationStrategy(); break; case TariffConstants.PackagedTariffName: annualCostsCalculationStrategy = new PackagedAnnualCostsCalculationStrategy(); break; default: throw new Exception("Unexpected name of tariff"); } AnnualCosts = annualCostsCalculationStrategy.GetAnnualCosts(consumption); }
public void GetAnnualCostsShouldThrowArgumentExceptionWhenConsumptionLessThanZero() { // Arrange var packagedAnnualCostsCalculationStrategy = new PackagedAnnualCostsCalculationStrategy(); double consumption = -900; // Act packagedAnnualCostsCalculationStrategy.GetAnnualCosts(consumption); }
public void GetAnnualCostsShouldReturn1010() { // Arrange var packagedAnnualCostsCalculationStrategy = new PackagedAnnualCostsCalculationStrategy(); double consumption = 4700; // Act var result = packagedAnnualCostsCalculationStrategy.GetAnnualCosts(consumption); // Assert Assert.AreEqual(1010.00m, result); }