예제 #1
0
        public void FactoryPatternTest()
        {
            var _TurkeyPenaltyCalculationService = factoryPatternResolver.Resolve(CountryEnum.TR);

            Assert.NotNull(_TurkeyPenaltyCalculationService);
            Assert.IsType <TurkeyPenaltyCalculationService>(_TurkeyPenaltyCalculationService);


            var _UnitedArabEmiratesPenaltyCalculationService = factoryPatternResolver.Resolve(CountryEnum.AE);

            Assert.NotNull(_UnitedArabEmiratesPenaltyCalculationService);
            Assert.IsType <UnitedArabEmiratesPenaltyCalculationService>(_UnitedArabEmiratesPenaltyCalculationService);
        }
        public PenaltyOutputModel Process(PenaltyInputModel inputViewModel)
        {
            if (inputViewModel == null)
            {
                throw new Exception($"{typeof(PenaltyInputModel).FullName} can not be null!");
            }
            try
            {
                var _countryEnum = (CountryEnum)System.Enum.Parse(typeof(CountryEnum), inputViewModel.Country.Currency);

                var _penaltyCalculationService = _factoryPatternResolver.Resolve(_countryEnum);

                var businessDays = _penaltyCalculationService.GetBusinessDays(inputViewModel);

                var result = _penaltyCalculationService.Calculate(businessDays, inputViewModel.Country.Currency);

                return(new PenaltyOutputModel {
                    BusinessDays = businessDays, TotalPrice = result.TotalPrice, CurrencySymbol = result.Currency
                });
            }
            catch
            {
            }
            return(new PenaltyOutputModel());
        }