static void Main(string[] args)
        {
            ITariffFactory            tariffFactory      = new TariffFactory();
            ITariffCalculationFactory calculationFactory =
                new TariffCalculationFactory();

            Tariff[] tariffs = Console.ReadLine()
                               .Split(',')
                               .Select(TariffName.Create)
                               .Select(tariffFactory.Create)
                               .ToArray();
            Consumption[] consumptions = Console.ReadLine()
                                         .Split(',')
                                         .Select(value => value.ToConsumption())
                                         .ToArray();

            TariffCalculationResultCollection resultCollection =
                new TariffCalculationResultCollection();

            foreach (Tariff tariff in tariffs)
            {
                foreach (Consumption consumption in consumptions)
                {
                    ITariffCalculation calculation = calculationFactory
                                                     .Create(tariff, consumption);
                    ConsumptionCost tariffCost = tariff.Calculate(
                        consumption, calculation);
                    resultCollection.Add(tariff.Name, tariffCost);
                }
            }

            resultCollection.Render(new ConsoleTariffCalculationResultRenderer());
        }
Esempio n. 2
0
 public ConsumptionCost Calculate(Consumption consumption,
                                  ITariffCalculation calculation)
 {
     return(calculation.Calculate(consumption));
 }