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()); }
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)); }