コード例 #1
0
        public IEnumerable <IProductDomainEntity> Create(ITariffCalculationSettings calculationSettings, params TariffType[] types)
        {
            var validateResult = _settingsValidator.Validate(calculationSettings);

            if (!validateResult.IsValid)
            {
                throw new ArgumentException(string.Join($"{Environment.NewLine}", validateResult.Errors));
            }


            var tariffTypeMap =
                new Dictionary <TariffType, ITariffCalculationStrategy>
            {
                { TariffType.Base,
                  new BaseTariffStrategy(
                      calculationSettings.BaseMonthCost,
                      calculationSettings.MonthsInYear,
                      calculationSettings.ConsumptionCosts) },

                { TariffType.Package,
                  new PackageTariffStrategy(
                      calculationSettings.ThresholdConsumption,
                      calculationSettings.BaseCost,
                      calculationSettings.AdditionalConsumptionCosts
                      ) }
            };

            return(types.Select(type => new ProductDomainEntity(type.ToDescriptionString(), tariffTypeMap[type])));
        }
コード例 #2
0
 public ProductService(IProductFactory productFactory, ITariffCalculationSettings calculationSettings)
 {
     _calculationSettings = calculationSettings;
     _productFactory      = productFactory;
 }