Ejemplo n.º 1
0
        public async Task GetDeclarationShouldReturnDeclarationData()
        {
            var testRequest = new GetDeclarationRequest
            {
                Id = "123456789012345678901234"
            };

            var expectedResponse = new GetDeclarationResponse
            {
                Id             = "123456789012345678901234",
                Name           = "Nerijus",
                PostCode       = "testPostCode",
                DonationAmount = 800,
                GiftAidAmount  = 200
            };

            _donationDeclarationServiceMock.Setup(x => x.Get(new ObjectId("123456789012345678901234")))
            .Returns(new DonationDeclaration
            {
                Id             = new ObjectId("123456789012345678901234"),
                Name           = "Nerijus",
                PostCode       = "testPostCode",
                DonationAmount = 800
            });

            var controller = new GiftAidController(_optionsMonitorMock.Object, _giftAidCalculatorMock.Object, _donationDeclarationServiceMock.Object);

            var response        = controller.GetDonationDeclaration(testRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(expectedResponse.ToString(), responseContext.Value.ToString());
        }
Ejemplo n.º 2
0
        public async Task GetDeclarationShouldReturnIdLengthValidationError()
        {
            var testRequest = new GetDeclarationRequest
            {
                Id = "12345"
            };

            var controller = new GiftAidController(_optionsMonitorMock.Object, _giftAidCalculatorMock.Object, _donationDeclarationServiceMock.Object);

            Assert.Throws <ArgumentException>(() => controller.GetDonationDeclaration(testRequest));
        }
Ejemplo n.º 3
0
        public async Task GetDeclarationShouldReturnNotFoundCodeWhenGivenIdIsInvalid()
        {
            var testRequest = new GetDeclarationRequest
            {
                Id = "123456789012345678901234"
            };

            _donationDeclarationServiceMock.Setup(x => x.Get(new ObjectId("123456789012345678901234")))
            .Returns((DonationDeclaration)null);

            var controller = new GiftAidController(_optionsMonitorMock.Object, _giftAidCalculatorMock.Object, _donationDeclarationServiceMock.Object);

            var response        = controller.GetDonationDeclaration(testRequest);
            var responseContext = response as ObjectResult;

            Assert.AreEqual(404, responseContext.StatusCode);
        }
Ejemplo n.º 4
0
        public IActionResult GetDonationDeclaration([FromQuery] GetDeclarationRequest request)
        {
            var donationDeclaration = _donationDeclarationService.Get(new ObjectId(request.Id));

            if (donationDeclaration == null)
            {
                return(NotFound("Records with id provided were not found"));
            }

            var response = new GetDeclarationResponse
            {
                Id             = donationDeclaration.Id.ToString(),
                Name           = donationDeclaration.Name,
                PostCode       = donationDeclaration.PostCode,
                DonationAmount = donationDeclaration.DonationAmount,
                GiftAidAmount  = _giftAidCalculator.CalculateGiftAid(donationDeclaration.DonationAmount)
            };

            return(Ok(response));
        }