Example #1
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 #2
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());
        }
Example #3
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());
        }
Example #4
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 #5
0
        public void Seup()
        {
            this._giftAidCalculatorServiceMock = new Mock <IGiftAidCalculatorService>();
            this._giftAidValidatorMock         = new Mock <IValidator <decimal> >();
            this._giftAidDonorServiceMock      = new Mock <IGiftAidDonorService>();

            this._controller = new GiftAidController(this._giftAidCalculatorServiceMock.Object, this._giftAidValidatorMock.Object, this._giftAidDonorServiceMock.Object);
        }
        public void Setup()
        {
            _taxRateStorage = Substitute.For <IStoreTaxRate>();
            _repository     = Substitute.For <IRepository>();
            GiftAidCalculator calc = new GiftAidCalculator(_taxRateStorage);

            _sut = new GiftAidController(calc, _repository);
        }
Example #7
0
 public GiftAidControllerUnitTests(Setup setup)
 {
     _serviceProvider   = setup.ServiceProvider;
     _giftAidService    = new GiftAidCalculatorService();
     _donationService   = new DonationServiceFake();
     _giftAidOptions    = _serviceProvider.GetRequiredService <IOptions <GiftAidSetup> >();
     _giftAidController = new GiftAidController(_giftAidOptions, _giftAidService, _donationService);
 }
Example #8
0
        public GiftAidControllerTests()
        {
            _handler = new Mock <IGiftAidHandler>();
            _handler.Setup(c => c.CalculateGiftAid(It.IsAny <double>())).Returns(new GiftAidResponse());
            _handler.Setup(c => c.CreateGiftAidDeclaration(It.IsAny <GiftAidDeclarationRequest>())).Returns(new GiftAidDeclarationResponse());

            _controller = new GiftAidController(_handler.Object);
        }
Example #9
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));
        }
        private void SetupGiftAidController()
        {
            _giftAidCalculators =
                new List <IGiftAidCalculator>()
            {
                new GeneralGiftAidCalculator(), new SwimmingGiftAidCalculator()
            };

            _giftAidOrchestrationService =
                new GiftAidOrchestrationService(_taxRepository.Object, new GiftAidCalculatorFinder(_giftAidCalculators));

            _giftAidController = new GiftAidController(_giftAidOrchestrationService,
                                                       new RequestValidator(_giftAidCalculators, new CountryService(_countryRepository.Object)));
        }
Example #11
0
        public void CalculeGiftAidAmount()
        {
            IGiftAidRepository aidRepository = new GiftAidRepository(_dbContext);
            GiftAidController  controller    = new GiftAidController(aidRepository, _calculationService, _declarationService);

            double donationAmount = 150;
            var    expected       = 1.875;

            var actionResult = controller.Get(donationAmount);
            var okResult     = actionResult as OkObjectResult;
            var actual       = (GiftAidResponse)okResult.Value;

            Assert.IsType <GiftAidResponse>(actual);
            Assert.Equal(expected, actual.GiftAidAmount);
        }
Example #12
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);
        }
        public void Get_ValidAmount_ReturnsGiftAidAmount()
        {
            var request = new CalculateGiftAidRequest
            {
                Amount = 100m
            };

            _giftAidCalculator.Calculate(request.Amount).Returns(20);
            _controller = new GiftAidController(_giftAidCalculator, _giftAidRepository, _postCodeValidator);

            var response        = _controller.Get(request) as JsonResult;
            var giftAidResponse = response.Value as CalculateGiftAidResponse;

            _giftAidCalculator.Received(1).Calculate(request.Amount);

            Assert.That(giftAidResponse.GiftAidAmount, Is.EqualTo(20));
        }
Example #14
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());
        }
Example #15
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);
        }
Example #16
0
        public async Task SaveDonor()
        {
            IGiftAidRepository aidRepository = new GiftAidRepository(_dbContext);
            GiftAidController  controller    = new GiftAidController(aidRepository, _calculationService, _declarationService);

            var donor = new Donor()
            {
                Id             = Guid.NewGuid(),
                DonationAmount = 150,
                Name           = "Pervaiz",
                PostCode       = "LU49FS"
            };

            var expected = 1.875;

            var actionResult = await controller.Post(donor);

            var okResult = actionResult as OkObjectResult;
            var actual   = (GiftAidDeclarationResponse)okResult.Value;

            Assert.IsType <GiftAidDeclarationResponse>(actual);
            Assert.Equal(expected, actual.GiftAidAmount);
        }
        public async Task Post_ValidRequest_ReturnsGiftAidDeclaration()
        {
            var request = new GiftAidDeclarationRequest
            {
                Amount   = 100m,
                Name     = "name",
                PostCode = "postCode"
            };

            _giftAidCalculator.Calculate(request.Amount).Returns(20);
            _controller = new GiftAidController(_giftAidCalculator, _giftAidRepository, _postCodeValidator);

            var response = await _controller.PostAsync(request) as JsonResult;

            var declarationResponse = response.Value as GiftAidDeclaration;

            await _giftAidRepository.Received(1).CreateGiftAidDeclaration(Arg.Is(request));

            _giftAidCalculator.Received(1).Calculate(request.Amount);

            Assert.That(declarationResponse.GiftAidAmount, Is.EqualTo(20));
            Assert.That(declarationResponse.DeclarationId.GetType(), Is.EqualTo(typeof(Guid)));
        }
Example #18
0
 public void Setup()
 {
     controller = new GiftAidController(service);
 }
 public GiftAidControllerMust()
 {
     _giftAidService    = new GiftAidService(TAX_RATE);
     _giftAidController = new GiftAidController(_giftAidService);
 }
 public void Setup()
 {
     _calculator         = Substitute.For <IGiftAidCalculator>();
     _donationRepository = Substitute.For <IDonationRepository>();
     _controller         = new GiftAidController(_calculator, _donationRepository);
 }
Example #21
0
 public void Setup()
 {
     _mockRequestValidator = new Mock <IRequestValidator>();
     _mockGiftAidService   = new Mock <IGiftAidOrchestrationService>();
     _giftAidController    = new GiftAidController(_mockGiftAidService.Object, _mockRequestValidator.Object);
 }