Beispiel #1
0
        public void Get_NoValue()
        {
            // Act - Null
            var actionsResult = _paymentsController.Get(null).GetAwaiter().GetResult();
            var result        = actionsResult.Result as BadRequestObjectResult;

            // Assert
            Assert.IsNotNull(result, "The result should be as expected");
        }
        public async Task Get_Should_Call_The_GetPaymentAsync_Method()
        {
            // Arrange
            var transactionId = Guid.NewGuid();

            // Act
            await _paymentsController.Get(transactionId, default(CancellationToken));

            // Assert
            _paymentsServiceMock.Verify(p => p.GetPaymentAsync(transactionId, It.IsAny <CancellationToken>()));
        }
Beispiel #3
0
        public void PostAndGetPayment_ShouldAcceptAndRetrieve()
        {
            CardDto card = GenerateRandomCard();

            PaymentRequestDto paymentRequest = new PaymentRequestDto();

            paymentRequest.MerchantId = 1;
            paymentRequest.Amount     = 25.99;
            paymentRequest.Currency   = "CAD";
            paymentRequest.Card       = card;

            var postResult = _paymentsController.Post(paymentRequest);

            Assert.IsType <OkObjectResult>(postResult.Result);
            OkObjectResult objectResult = postResult.Result as OkObjectResult;

            Assert.IsType <PaymentResponseDto>(objectResult.Value);
            PaymentResponseDto paymentResponse = objectResult.Value as PaymentResponseDto;

            Assert.True(paymentResponse.Id > 0);
            Assert.NotNull(paymentResponse.Status);

            int paymentId = paymentResponse.Id;
            var getResult = _paymentsController.Get(paymentId);

            Assert.IsType <OkObjectResult>(getResult.Result);
            OkObjectResult getObjectResult = getResult.Result as OkObjectResult;

            Assert.IsType <PaymentInformationDto>(getObjectResult.Value);
            PaymentInformationDto paymentInformation = getObjectResult.Value as PaymentInformationDto;

            Assert.Equal(paymentRequest.Amount, paymentInformation.Amount);
            Assert.Equal(paymentRequest.Currency, paymentInformation.Currency);
        }
        public async Task Get_PaymentReturns_ReturnsOkResult()
        {
            var mockPaymentRepo        = new Mock <IPaymentRepository>();
            var mockLogger             = new Mock <ILogger <PaymentsController> >();
            var mockMapper             = new Mock <IMapper>();
            var mockBankRequestService = new Mock <IBankRequestService>();
            var mockEncryptionService  = new Mock <IEncryptionService>();

            var mapperResponse = new GetPaymentResponse
            {
                Name          = "Fred Bloggs",
                CardNumber    = "4111111111111111",
                Id            = Guid.NewGuid(),
                PaymentStatus = "Completed"
            };

            mockPaymentRepo.Setup(x => x.GetPaymentAsync(It.IsAny <Guid>())).ReturnsAsync(() => new Payment());
            mockMapper.Setup(x => x.Map <GetPaymentResponse>(It.IsAny <Payment>())).Returns(mapperResponse);
            mockEncryptionService.Setup(x => x.Decrypt(It.IsAny <byte[]>())).Returns("4111111111111111");

            var paymentsController = new PaymentsController(mockPaymentRepo.Object, mockBankRequestService.Object, mockEncryptionService.Object, mockMapper.Object, mockLogger.Object);

            var response = await paymentsController.Get(Guid.NewGuid());

            var okResponse         = Assert.IsType <OkObjectResult>(response);
            var getPaymentResponse = Assert.IsType <GetPaymentResponse>(okResponse.Value);

            Assert.Equal(mapperResponse.CardNumber.MaskCard(), getPaymentResponse.CardNumber);
            Assert.Equal(mapperResponse.Name, getPaymentResponse.Name);
            Assert.Equal(mapperResponse.Id, getPaymentResponse.Id);
            Assert.Equal(mapperResponse.PaymentStatus, getPaymentResponse.PaymentStatus);
        }
        public async Task AndTheOrgIdIsIncorrect_ThenReturnBadRequest()
        {
            var nonGuidId = "testtesttest";
            var sut       = new PaymentsController(null);

            var result = await sut.Get(nonGuidId);

            result.Should().BeOfType <BadRequestObjectResult>();
        }
        public async Task AndThereAreNoPaymentsForThisOrganisation_ThenReturn404()
        {
            var nonExistingOrgId   = Guid.NewGuid();
            var paymentServiceMock = new Mock <IPaymentService>();
            var sut = new PaymentsController(paymentServiceMock.Object);

            var result = await sut.Get(nonExistingOrgId.ToString());

            result.Should().BeOfType <NotFoundResult>();
        }
Beispiel #7
0
        public void GetPayment__when__should__return_Success()
        {
            var payment = new Payment()
            {
                Id            = Guid.NewGuid().ToString(),
                CardNumber    = "1234-5678-1234-4567",
                CardHolder    = "Owner",
                ExecutionDate = DateTime.UtcNow,
            };

            paymentsProcessor.Setup(p => p.GetPayment(It.IsAny <string>())).Returns(payment);

            // act
            var response = controller.Get(payment.Id);

            response.Should().NotBeNull();
            var paymentResponse = response.Value.As <PaymentResponse>();

            paymentResponse.Id.Should().Be(payment.Id);
            paymentResponse.CardNumber.Should().Be(payment.CardNumber);
            paymentResponse.ExecutionDate.Should().BeSameDateAs(payment.ExecutionDate);
        }
        public async Task AndThereArePayments_ThenReturnThem()
        {
            var nonExistingOrgId   = Guid.NewGuid();
            var paymentServiceMock = new Mock <IPaymentService>();

            paymentServiceMock.Setup(x => x.GetPayments(nonExistingOrgId)).ReturnsAsync(new [] { new Payment() });

            var sut = new PaymentsController(paymentServiceMock.Object);

            var result = await sut.Get(nonExistingOrgId.ToString());

            result.Should().BeOfType <OkObjectResult>();
        }
        public void GetPaymentByIdReturns404()
        {
            // Arrange
            var mockPaymentService = new Mock <IPaymentService>();
            var paymentId          = Guid.NewGuid();

            mockPaymentService.Setup(x => x.GetPaymentById(paymentId)).Returns((Payment)null);
            var controller = new PaymentsController(AutoMapperSingleton.Mapper, new Mock <IPaymentProcessor>().Object, mockPaymentService.Object);

            // Act
            var result = controller.Get(paymentId);

            // Assert
            result.Result.Should().BeOfType <Microsoft.AspNetCore.Mvc.NotFoundResult>();
        }
        public async Task Get_NullPayment_ReturnsNotFound()
        {
            var mockPaymentRepo        = new Mock <IPaymentRepository>();
            var mockLogger             = new Mock <ILogger <PaymentsController> >();
            var mockMapper             = new Mock <IMapper>();
            var mockBankRequestService = new Mock <IBankRequestService>();
            var mockEncryptionService  = new Mock <IEncryptionService>();

            mockPaymentRepo.Setup(x => x.GetPaymentAsync(It.IsAny <Guid>())).ReturnsAsync(() => null);

            var paymentsController = new PaymentsController(mockPaymentRepo.Object, mockBankRequestService.Object, mockEncryptionService.Object, mockMapper.Object, mockLogger.Object);

            var response = await paymentsController.Get(Guid.NewGuid());

            Assert.IsType <NotFoundResult>(response);
        }
        public async Task AndThereIsExeption_ThenReturn500()
        {
            var paymentServiceMock = new Mock <IPaymentService>();

            paymentServiceMock.Setup(x => x.GetPayments(It.IsAny <Guid>())).ThrowsAsync(new Exception());

            var sut = new PaymentsController(paymentServiceMock.Object);

            var result = await sut.Get(Guid.NewGuid().ToString());

            result.Should().BeOfType <StatusCodeResult>();

            var castedResult = (StatusCodeResult)result;

            castedResult.StatusCode.Should().Be(500);
        }
        public async Task Get_Should_Throw_Exception_If_The_Payment_Is_Not_Found()
        {
            // Arrange
            var paymentsServiceMock = new Mock <IPaymentsService>();

            paymentsServiceMock.Setup(p => p.GetPaymentAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Payment>(null));

            var paymentsController = new PaymentsController(_loggerMock.Object, paymentsServiceMock.Object, _bankServiceMock.Object);

            // Act
            async Task HandleRequest() => await paymentsController.Get(Guid.NewGuid(), default(CancellationToken));

            // Assert
            await Assert.ThrowsAsync <ResourceNotFoundException>(HandleRequest);
        }
Beispiel #13
0
        public async void Get_Count_MoreThen_0()
        {
            //Arrange
            string connectionString = @"Data Source=VLAD191100\VLAD191100;Database=HyperWalletTest;User ID=vlad191100;Password=Vlad18201111;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            DbContextOptionsBuilder <Context> options = new DbContextOptionsBuilder <Context>();

            options.UseSqlServer(connectionString);
            Context            context    = new Context(options.Options);
            PaymentsController controller = new PaymentsController(context);

            //Act
            List <Payment> list = await controller.Get();

            //Assert
            Assert.True(list.Count > 0);
        }
        public void GetPaymentByIdReturnsData(Payment mockPayment)
        {
            // Arrange
            var mockPaymentService = new Mock <IPaymentService>();
            var paymentId          = Guid.NewGuid();

            mockPayment.TransactionId = paymentId;

            mockPaymentService.Setup(x => x.GetPaymentById(paymentId)).Returns(mockPayment);
            var controller = new PaymentsController(AutoMapperSingleton.Mapper, new Mock <IPaymentProcessor>().Object, mockPaymentService.Object);

            // Act
            var result = controller.Get(paymentId);

            // Assert
            result.Value.Should().BeEquivalentTo(mockPayment);
        }
Beispiel #15
0
        public async void Get_WithToken_NotNull()
        {
            //Arrange
            string connectionString = @"Data Source=VLAD191100\VLAD191100;Database=HyperWalletTest;User ID=vlad191100;Password=Vlad18201111;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            DbContextOptionsBuilder <Context> options = new DbContextOptionsBuilder <Context>();

            options.UseSqlServer(connectionString);
            Context            context    = new Context(options.Options);
            PaymentsController controller = new PaymentsController(context);
            string             id         = "1458303177";

            //Act
            Payment user = await controller.Get(id);

            //Assert
            Assert.True(user != null);
        }
        public void Get_Payments_Returns_Correct_Length_Of_Items()
        {
            var result = _paymentsController.Get() as OkNegotiatedContentResult <IEnumerable <Payment> >;

            Assert.Equal(_payments.Get().Count(), result.Content.Count());
        }