public ActionResult <CalculationResponse> CalculateTax([FromBody] CalculationRequest request)
        {
            var taxType  = _postalCodeToTaxTypeMapper.GetTaxRegime(request.PostalCode);
            var response = new CalculationResponse();

            if (taxType == TaxType.Unknown)
            {
                var errorMessage = $"Postal code {request.PostalCode} could not be mapped to a valid tax type.";
                response.ErrorMessage = errorMessage;
                _logger.LogWarning(errorMessage);
            }
            else
            {
                var taxDue = _taxManager.GetCalculator(taxType).GetTaxableAmount(request.TaxableAmount);
                response.AssessedAmount = taxDue;
                response.TaxType        = taxType;
                //i wanted to use Automap to handle this mapping but no time for that and this mapping is only
                //done here anyway
                _taxEventLogger.LogEvent(new Domain.TaxCalculationEvent()
                {
                    AssessedAmount = response.AssessedAmount,
                    PostalCode     = request.PostalCode,
                    TaxRegime      = taxType,
                    TaxableAmount  = request.TaxableAmount,
                    UserId         = request.UserId
                });
            }
            return(response);
        }
Esempio n. 2
0
 public void When_TaxType_Is_Progressive_Return_ProgressiveCalculator()
 {
     Assert.IsInstanceOf(typeof(IProgressiveRateCalculator), _manager.GetCalculator(Domain.Enums.TaxType.Progressive));
 }