public void ReturnPaymentDetails_GivenPaymentExits_WhenCallingGetPayment()
        {
            // Arrange
            var paymentId = "ExistentPaymentId";
            var paymentServiceResponse = new CompletedPaymentDto()
            {
                CardNumber   = "4658582263620043",
                ExpiryDate   = "0824",
                Amount       = 10m,
                CurrencyCode = "GBP",
                Ccv          = "001",
                PaymentId    = "AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE",
                IsSuccessful = true
            };

            A.CallTo(() => _fakePaymentService.RetrievePayment(paymentId)).Returns(paymentServiceResponse);
            var expectedPaymentResponse = new ProcessedPaymentResponseV1()
            {
                CardNumber   = "4658582263620043",
                ExpiryDate   = "0824",
                Amount       = 10m,
                CurrencyCode = "GBP",
                Ccv          = "001",
                PaymentId    = "AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE",
                IsSuccessful = true
            };

            // Act
            var actualResponse = _sut.GetPayment(paymentId);

            // Assert
            actualResponse.Result.Should().BeOfType <OkObjectResult>();
            ((ObjectResult)actualResponse.Result).Value.Should().BeEquivalentTo(expectedPaymentResponse);
        }
        public async Task Get_payment_success()
        {
            //Arrange
            var fakePaymentId   = "1";
            var fakePaymentdesc = "1";
            var fakePaymentdto  = GetPaymentFakeDTOs(fakePaymentId);
            var fakePayment     = GetPaymentFake(fakePaymentId);


            _PaymentRepositoryMock.Setup(x => x.GetPaymentAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(fakePayment));

            _mapperMock.Setup(x => x.Map <PaymentDTOs>(It.IsAny <API.Model.Payment>()))
            .Returns((API.Model.Payment source) =>
            {
                return(fakePaymentdto);
            });

            //Act
            var paymentController = new PaymentController(
                _PaymentRepositoryMock.Object,
                _mapperMock.Object);

            var actionResult = await paymentController.GetPayment(fakePaymentdesc, fakePaymentId);

            //Assert
            Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.Equal((((ObjectResult)actionResult.Result).Value as PaymentDTOs).Description, fakePayment.PartitionKey);
        }
        public void GetPaymentReturnsOkWithFilledPaymentOnRequest()
        {
            var expectedPaymentDto = new PaymentDto
            {
                Amount   = 1,
                Currency = "GBP",
                Card     = new CardDto
                {
                    CardNumber  = "1234123412341234",
                    Cvv         = 123,
                    ExpiryMonth = 12,
                    ExpiryYear  = 20
                },
                Id           = new Guid("24b542a8-4825-4089-ace6-6c0ef8bd56a8"),
                IsSuccessful = true
            };

            var controller = new PaymentController(Mocks.Mock.For.PaymentPaymentControllerTests.RequestMapper,
                                                   Mocks.Mock.For.PaymentPaymentControllerTests.ResponseMapper,
                                                   Mocks.Mock.For.PaymentPaymentControllerTests.PaymentDtoMapper,
                                                   Mocks.Mock.For.PaymentPaymentControllerTests.PaymentService);

            var response = controller.GetPayment(new Guid("24b542a8-4825-4089-ace6-6c0ef8bd56a8"));

            response.Should().NotBeNull();
            response.Result.Should().NotBeNull();
            response.Result.GetType().Should().Be(typeof(OkObjectResult));
            var httpResult = (OkObjectResult)response.Result;

            httpResult.StatusCode.HasValue.Should().BeTrue();
            httpResult.StatusCode.Should().Be(200);
            ((OkObjectResult)response.Result).Value.GetType().Should().Be(typeof(PaymentDto));
            ((PaymentDto)((OkObjectResult)response.Result).Value).Should().BeEquivalentTo(expectedPaymentDto);
        }
Exemple #4
0
        public async Task Return_Error_If_No_Payment_Is_Found()
        {
            var mockqueryHandler = new Mock <IGetPaymentQueryHandler>();

            mockqueryHandler.Setup(x => x.HandleAsync(It.IsAny <GetPaymentQuery>()))
            .ReturnsAsync((GetPaymentQuery query) => new ErrorResult($"There is no payment with id: {query.PaymentId}"));
            var sut       = new PaymentController(mockqueryHandler.Object);
            var paymentId = Guid.NewGuid().ToString();

            var response = await sut.GetPayment(paymentId);

            var httpResponse = response as NotFoundObjectResult;

            httpResponse.Value.Should().Be($"There is no payment with id: {paymentId}");
        }
        public void GetPaymentReturnsBadRequestOnEmptyGuid()
        {
            var controller = new PaymentController(Mocks.Mock.For.PaymentPaymentControllerTests.RequestMapper,
                                                   Mocks.Mock.For.PaymentPaymentControllerTests.ResponseMapper,
                                                   Mocks.Mock.For.PaymentPaymentControllerTests.PaymentDtoMapper,
                                                   Mocks.Mock.For.PaymentPaymentControllerTests.PaymentService);

            var response = controller.GetPayment(Guid.Empty);

            response.Should().NotBeNull();
            response.Result.Should().NotBeNull();
            response.Result.GetType().Should().Be(typeof(BadRequestObjectResult));
            var httpResult = (BadRequestObjectResult)response.Result;

            httpResult.StatusCode.HasValue.Should().BeTrue();
            httpResult.StatusCode.Value.Should().Be(400);
        }
        public void GetPayment_CanGetPayment_OkObjectResult()
        {
            // Arrange
            Guid body = new Guid("af188a89-0d2a-4863-a596-f7844364ac09");

            // Act
            var result = PaymentController.GetPayment(body).Result as OkObjectResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Value);
            Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse");

            var response = result.Value as PaymentResponse;

            Assert.IsNotNull(response.Amount);
            Assert.IsNotNull(response.CurrencyCode);
            Assert.IsNotNull(response.FullName);
            Assert.IsNotNull(response.Id);
            Assert.IsNotNull(response.IsSuccessful);
            Assert.IsNotNull(response.RequestDate);
        }
        public void ReturnMaskedCardNumberToMerchant()
        {
            //Arrange
            var paymentRepo      = new Mock <IPaymentRepository>();
            var profile          = new MerchantPaymentProfile();
            var mapperConfig     = new MapperConfiguration(x => x.AddProfile(profile));
            var paymentPublisher = new Mock <IPaymentPublisher>();

            var mapper = new Mapper(mapperConfig);
            var id     = Guid.NewGuid();

            var payment = new MerchantPayment()
            {
                Id            = id,
                Amount        = 9.99,
                Currency      = "USD",
                MerchantId    = "1",
                PaymentMethod = new PaymentMethod
                {
                    Cvv             = "123",
                    ExpirationMonth = "05",
                    ExpirationYear  = "2021",
                    Number          = "4319487612345678",
                    PaymentMethodId = new Guid(),
                    Type            = "Visa"
                },
                Status = Status.Submitted
            };

            //Act
            paymentRepo.Setup(x => x.GetById(id)).Returns(Task.FromResult(payment));
            var controller = new PaymentController(paymentRepo.Object, mapper, paymentPublisher.Object);

            var result = controller.GetPayment(id);
            var value  = ((OkObjectResult)result.Result).Value as MerchantPaymentResponse;

            //Assert
            Assert.That(value.Number, Is.EqualTo("XXXXXXXXXXXX5678"));
        }
        public void GetPayment_CanGetPayment_BadRequestObjectResult()
        {
            // Arrange
            Guid body = new Guid("682f6880-5415-44a9-a7bf-c8d1f9a6f43e");

            // Act
            var result = PaymentController.GetPayment(body).Result as BadRequestObjectResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Value);
            Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse");

            var response = result.Value as PaymentResponse;

            Assert.IsNull(response.Amount);
            Assert.IsNull(response.CurrencyCode);
            Assert.IsNull(response.FullName);
            Assert.IsNull(response.RequestDate);

            Assert.IsNotNull(response.Id);
            Assert.IsNotNull(response.IsSuccessful);
        }
        public void GetPayment_CanGetPayment_Uknown500Error()
        {
            // Arrange
            Guid body = new Guid("13b702ef-18be-427e-931d-21b866aed500");

            // Act
            var result = PaymentController.GetPayment(body).Result as ObjectResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Value);
            Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse");

            var response = result.Value as PaymentResponse;

            Assert.IsNull(response.Amount);
            Assert.IsNull(response.CurrencyCode);
            Assert.IsNull(response.FullName);
            Assert.IsNull(response.RequestDate);

            Assert.IsNotNull(response.Id);
            Assert.IsNotNull(response.IsSuccessful);
        }
Exemple #10
0
        public async Task GetPayment()
        {
            var mockqueryHandler = new Mock <IGetPaymentQueryHandler>();
            var expectedValue    = new SuccessResult
            {
                CardNumber    = "***************3467",
                Amount        = 100,
                PaymentDate   = DateTime.UtcNow,
                PaymentStatus = PaymentStatus.Success,
                Currency      = "EUR"
            };

            mockqueryHandler.Setup(x => x.HandleAsync(It.IsAny <GetPaymentQuery>()))
            .ReturnsAsync(expectedValue);
            var sut       = new PaymentController(mockqueryHandler.Object);
            var paymentId = Guid.NewGuid().ToString();

            var response = await sut.GetPayment(paymentId);

            var httpResponse = response as OkObjectResult;

            httpResponse.Value.Should().Be(expectedValue);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorLabel.Visible = false;
            if (Session["email"] != null)
            {
                User u = UserController.GetUser(Session["email"].ToString());

                if (u.RoleID == 1)
                {
                    if (Request.QueryString["paymentid"] != null)
                    {
                        paymentid = int.Parse(Request.QueryString["paymentid"]);

                        PaymentType currentProduct = PaymentController.GetPayment(paymentid);
                        if (!IsPostBack)
                        {
                            TypeTex.Text = currentProduct.Type.ToString();
                        }
                    }

                    else
                    {
                        Response.Redirect("ViewPaymentType.aspx");
                    }
                }

                else
                {
                    Page.Visible = false;
                }
            }

            else
            {
                Response.Redirect("LoginForm.aspx");
            }
        }
        public void GetPayment_CanGetPayment_NotFoundObjectResult()
        {
            // Arrange
            Guid body = new Guid("14077807-b564-4b0b-9e7a-6b8dbd26e615");

            // Act
            var result = PaymentController.GetPayment(body).Result as NotFoundObjectResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Value);
            Assert.IsInstanceOf <PaymentResponse>(result.Value, "response is CheckoutPaymentGatewayModelsPaymentResponse");

            var response = result.Value as PaymentResponse;

            Assert.IsNull(response.Amount);
            Assert.IsNull(response.CurrencyCode);
            Assert.IsNull(response.FullName);
            Assert.IsNull(response.RequestDate);

            Assert.IsNotNull(response.Id);
            Assert.IsNotNull(response.IsSuccessful);
            Assert.IsNotNull(response.Message);
        }
Exemple #13
0
        public async Task NormalEmployee()
        {
            var request = new CreateEmployeeRequest()
            {
                PersonalIdentificationNumber = "1234567890",
                UserName = "******",
            };
            var employeeId = await _employeeController.CreateEmployee(request);

            var customerRequest = new CreateCustomerRequest()
            {
                EmployeeId = employeeId,
                PersonalIdentificationNumber = "customer ssn",
                UserName = "******",
                Address  = "address"
            };
            var customerId = await _customerController.CreateCustomer(customerRequest);

            var createInvoiceRequest = new CreateInvoiceRequest()
            {
                EmployeeId   = employeeId,
                CustomerId   = customerId,
                PayInAdvance = false,
                InvoiceItems = new List <InvoiceItemDto>()
                {
                    new InvoiceItemDto()
                    {
                        Price = 10000.0m, Description = "städning"
                    }
                }.ToArray(),
                EndDate            = DateTime.Now,
                StartDate          = DateTime.Now,
                Name               = "invoiceName",
                Vat                = 25m,
                InvoiceDescription = "invoice description"
            };
            var invoiceId = await _invoiceController.CreateInvoice(createInvoiceRequest);

            var assignment = await _assignmentController.GetAssignment(invoiceId);

            Assert.Equal(Status.Created, assignment.CurrentStatus);

            await _invoiceController.SendInvoice(invoiceId);

            var payment = await _paymentController.GetPayment(invoiceId);

            Assert.Equal(PaymentState.WaitingForPayment, payment.CurrentState);

            // simulate payment
            await _paymentController.SimulateReceivePayment(new ReceivePaymentRequest()
            {
                InvoiceId = invoiceId
            });

            payment = await _paymentController.GetPayment(invoiceId);

            Assert.Equal(PaymentState.PaymentReceived, payment.CurrentState);

            var payout = await _payoutController.GetPayout(invoiceId);

            Assert.Equal(5060m, Math.Floor(payout.Amount));

            assignment = await _assignmentController.GetAssignment(invoiceId);

            Assert.Equal(Status.Closed, assignment.CurrentStatus);
        }