Пример #1
0
        public async Task ShouldCreateDonationSuccessfully()
        {
            var testCreateDonationDeclarationRequest = new CreateDeclarationRequest
            {
                PostCode       = "testPostCode",
                DonationAmount = 800,
                Name           = "TestName"
            };

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

            _donationDeclarationServiceMock.Setup(x => x.Insert(It.IsAny <DonationDeclaration>())).Returns("12345");

            var expectedResponse = new CreateDeclarationResponse
            {
                DeclarationId = "12345",
                GiftAidAmount = 200
            };

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

            Assert.AreEqual(expectedResponse.ToString(), responseContext.Value.ToString());
        }
Пример #2
0
        public async Task CreateDonationShouldReturnBadRequestWhenAmountIsNotValid()
        {
            var testCreateDonationDeclarationRequest = new CreateDeclarationRequest
            {
                PostCode       = "testPostCode",
                DonationAmount = 2,
                Name           = "TestName"
            };

            _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.CreateDonationDeclaration(testCreateDonationDeclarationRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(expectedResponse.StatusCode, responseContext.StatusCode);
            Assert.AreEqual(expectedResponse.Value.ToString(), responseContext.Value.ToString());
        }
Пример #3
0
        public async Task CreateDonationShouldReturnBadRequestSinceRequestBodyIsIncomplete()
        {
            var testCreateDonationDeclarationRequest = new CreateDeclarationRequest
            {
                PostCode       = "testPostCode",
                DonationAmount = 2
            };

            _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.CreateDonationDeclaration(testCreateDonationDeclarationRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(400, responseContext.StatusCode);
        }
Пример #4
0
        public async Task CreateDonationShouldReturnInternalServerErrorWhenConfigurationIsNotValid()
        {
            var testCreateDonationDeclarationRequest = new CreateDeclarationRequest
            {
                PostCode       = "testPostCode",
                DonationAmount = 2,
                Name           = "TestName"
            };

            _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.CreateDonationDeclaration(testCreateDonationDeclarationRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(expectedResponse.StatusCode, responseContext.StatusCode);
            Assert.AreEqual(expectedResponse.Value.ToString(), responseContext.Value.ToString());
        }