public IActionResult CreateDonationDeclaration(CreateDeclarationRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var validationResult = ValidateOperation(request.DonationAmount); if (validationResult.StatusCode != 200) { return(validationResult); } var donationDeclaration = new DonationDeclaration { Name = request.Name, PostCode = request.PostCode, DonationAmount = request.DonationAmount }; var response = new CreateDeclarationResponse { DeclarationId = _donationDeclarationService.Insert(donationDeclaration).ToString(), GiftAidAmount = _giftAidCalculator.CalculateGiftAid(request.DonationAmount) }; return(Ok(response)); }
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()); }