示例#1
0
        public async Task <TaxCalculationResponse> Calculate(GetCalculationModel request)
        {
            if (request == null)
            {
                throw new NullReferenceException();
            }

            if (string.IsNullOrEmpty(request.ClientId))
            {
                throw new ArgumentNullException(nameof(request.ClientId));
            }

            if (string.IsNullOrEmpty(request.ToCountry))
            {
                throw new ArgumentNullException(nameof(request.ToCountry));
            }

            if (string.IsNullOrEmpty(request.ToState))
            {
                throw new ArgumentNullException(nameof(request.ToState));
            }

            if (string.IsNullOrEmpty(request.ToZip) && request.ToCountry == "US" || string.IsNullOrEmpty(request.ToZip) && request.ToCountry == "CA")
            {
                throw new ArgumentNullException(nameof(request.ToZip));
            }

            var mapped = mapper.Map <TaxCalculationRequest>(request);

            var response = await taxRepository.Post <TaxCalculationRequest, TaxCalculationResponse>(mapped);

            return(response);
        }
示例#2
0
        public void Calculate_ToCountry_CA_Valid_Response_Expected()
        {
            var taxService = new TaxService(taxRepoMock.Object, mapperMock.Object);

            var request = new GetCalculationModel
            {
                ClientId  = "1",
                ToCountry = "US",
                ToState   = "ToState",
                ToZip     = "30203"
            };

            taxRepoMock.Setup(x => x.Get <TaxCalculationRequest, TaxCalculationResponse>(It.IsAny <TaxCalculationRequest>())).ReturnsAsync(() =>
            {
                return(new TaxCalculationResponse
                {
                    Tax = new Tax
                    {
                        Rate = 30
                    }
                });
            });

            var result = taxService.Calculate(request);

            Assert.NotNull(result);
        }
示例#3
0
        public void Calculate_Empty_ClientId_Expected_Argument_Null_Exception()
        {
            var taxService = new TaxService(taxRepoMock.Object, mapperMock.Object);

            var request = new GetCalculationModel
            {
                ClientId = string.Empty
            };

            Assert.That(() => taxService.Calculate(request), Throws.ArgumentNullException);
        }
示例#4
0
        public void Calculate_Null_ToCountry_Expected_Argument_Null_Exception()
        {
            var taxService = new TaxService(taxRepoMock.Object, mapperMock.Object);

            var request = new GetCalculationModel
            {
                ClientId  = "1",
                ToCountry = null
            };

            Assert.That(() => taxService.Calculate(request), Throws.ArgumentNullException);
        }
示例#5
0
        public void Calculate_Empty_ToZip_And_ToCountry_Is_CA_Expected_Argument_Null_Exception()
        {
            var taxService = new TaxService(taxRepoMock.Object, mapperMock.Object);

            var request = new GetCalculationModel
            {
                ClientId  = "1",
                ToCountry = "CA",
                ToState   = "ToState",
                ToZip     = string.Empty
            };

            Assert.That(() => taxService.Calculate(request), Throws.ArgumentNullException);
        }