public async Task GetTaxAsync_Should_Calculate_The_Correct_Tax_Percentage()
        {
            // arrange
            var taxes = new List <Tax> {
                new Tax {
                    TaxCode = "VAT", TaxName = "Value Added Tax", Percentage = 5.5m
                }
            };

            _mockTaxRepository.GetLocalTaxesAsync("US").Returns(Task.FromResult(taxes));

            // act
            var result = await _service.GetTaxAsync("US", 350, _cxlToken);

            // assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(19.25, result.First().Amount);
            });
        }
Пример #2
0
        public async Task <List <TaxDto> > GetTaxAsync(string countryCode, decimal transferAmount, CancellationToken cxlToken)
        {
            if (string.IsNullOrEmpty(countryCode))
            {
                throw new ArgumentNullException("countryCode");
            }

            if (transferAmount <= 0)
            {
                throw new ArgumentException("Amount must be greater than 0");
            }

            var taxes = (await _taxRepository.GetLocalTaxesAsync(countryCode))
                        ?? new List <Data.Model.Tax>();

            return(taxes
                   .Select(t => new TaxDto
            {
                TaxCode = t.TaxCode,
                TaxName = t.TaxName,
                Amount = transferAmount * t.Percentage * 0.01m
            }).ToList());
        }