Example #1
0
        public async Task ShouldReturnBadRequestWhenAmountIsNotValid()
        {
            var getGiftAidAmountRequest = new GiftAidRequest
            {
                Amount = 10
            };

            _optionsMonitorMock.Setup(o => o.CurrentValue).Returns(new AppSettings
            {
                TaxRatePercentage     = "20",
                MinimumDonationAmount = "20",
                MaximumDonationAmount = "50"
            });

            var expectedResponse = new ObjectResult("Donation amount can not be smaller than 20 and can not be larger than 50");

            expectedResponse.StatusCode = 400;

            var controller      = new GiftAidController(_optionsMonitorMock.Object, _giftAidCalculatorMock.Object, _donationDeclarationServiceMock.Object);
            var response        = controller.GetGiftAidAmount(getGiftAidAmountRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(expectedResponse.StatusCode, responseContext.StatusCode);
            Assert.AreEqual(expectedResponse.Value.ToString(), responseContext.Value.ToString());
        }
Example #2
0
        public async Task ShouldReturnValidCalculateGiftAidResponse()
        {
            var getGiftAidAmountRequest = new GiftAidRequest
            {
                Amount = 30
            };

            var expectedResponse = new GiftAidResponse
            {
                DonationAmount = 30,
                GiftAidAmount  = 7.5m
            };

            _optionsMonitorMock.Setup(o => o.CurrentValue).Returns(new AppSettings
            {
                TaxRatePercentage     = "20",
                MinimumDonationAmount = "20",
                MaximumDonationAmount = "50"
            });

            var controller      = new GiftAidController(_optionsMonitorMock.Object, _giftAidCalculatorMock.Object, _donationDeclarationServiceMock.Object);
            var response        = controller.GetGiftAidAmount(getGiftAidAmountRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(200, responseContext.StatusCode);
            Assert.AreEqual(expectedResponse.ToString(), responseContext.Value.ToString());
        }
Example #3
0
        public async Task ShouldReturnInternalServerErrorWhenConfigurationIsNotValid()
        {
            var getGiftAidAmountRequest = new GiftAidRequest
            {
                Amount = 10
            };

            _optionsMonitorMock.Setup(o => o.CurrentValue).Returns(new AppSettings());

            var expectedResponse = new ObjectResult("Internal Server Error: Definition of one or more configuration settings of the application are invalid.");

            expectedResponse.StatusCode = 500;

            var controller      = new GiftAidController(_optionsMonitorMock.Object, _giftAidCalculatorMock.Object, _donationDeclarationServiceMock.Object);
            var response        = controller.GetGiftAidAmount(getGiftAidAmountRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(expectedResponse.StatusCode, responseContext.StatusCode);
            Assert.AreEqual(expectedResponse.Value.ToString(), responseContext.Value.ToString());
        }
        public async Task Return_donation_in_response(decimal donationAmount)
        {
            var controllerResponse = _giftAidController.GetGiftAidAmount(donationAmount).Value;

            Assert.Equal(donationAmount, controllerResponse.DonationAmount);
        }