public DataAccessFacade()
 {
     customerController = new CustomerController();
     saleController = new SaleController();
     paymentRuleCatalogController = new PaymentRuleCatalogController();
     paymentContractController = new PaymentContractController();
     paymentRuleController = new PaymentRuleController();
     bookingController = new BookingController();
     paymentController = new PaymentController();
     supplierController = new SupplierController();
 }
        public async Task ProcessPayment_Rejected_RecordFailure()
        {
            var log   = new Mock <ILogger <PaymentController> >();
            var bank  = new Mock <IBankProvider>();
            var store = new Mock <IPaymentRequestStore>();

            bank.Setup(x => x.ProcessPaymentAsync(It.IsAny <CardDetails>(), It.IsAny <TransactionDetails>()))
            .Returns(Task.FromResult(new PaymentResponse
            {
                Successful = false
            }));
            store.Setup(s => s.LogPaymentRequest(It.IsAny <PaymentRequestLog>()));

            var controller  = new PaymentController(log.Object, bank.Object, store.Object);
            var transaction = new TransactionDetails
            {
                Amount   = 3m,
                Currency = "AUS"
            };
            var response = await controller.ProcessPayment(new PaymentDetails
            {
                CardDetails = new CardDetails
                {
                    CardholderName = "bob",
                    CardNumber     = "1234567890123454",
                    Expires        = DateTime.Now.AddMonths(5),
                    CSC            = "876"
                },
                TransactionDetails = transaction
            });

            store.Verify(s => s.LogPaymentRequest(It.Is <PaymentRequestLog>(log =>
                                                                            log.Id != null &&
                                                                            !log.PaymentResponse.Successful &&
                                                                            log.TransactionDetails == transaction && // TODO: Should check values
                                                                            log.MaskedCardDetails.MaskedCardNumber == "************3454"
                                                                            )), Times.Once);
            store.VerifyNoOtherCalls();
        }
        public async Task ProcessPayment_ValidAccepted_OkSuccess()
        {
            var log   = new Mock <ILogger <PaymentController> >();
            var bank  = new Mock <IBankProvider>();
            var store = new Mock <IPaymentRequestStore>();

            var id = Guid.NewGuid();

            bank.Setup(x => x.ProcessPaymentAsync(It.IsAny <CardDetails>(), It.IsAny <TransactionDetails>()))
            .Returns(Task.FromResult(new PaymentResponse
            {
                Successful    = true,
                TransactionId = id
            }));

            var controller = new PaymentController(log.Object, bank.Object, store.Object);
            var response   = await controller.ProcessPayment(new PaymentDetails
            {
                CardDetails = new CardDetails
                {
                    CardholderName = "平安",
                    CardNumber     = "1234567890123456",
                    Expires        = DateTime.Now.AddMonths(5),
                    CSC            = "123"
                },
                TransactionDetails = new TransactionDetails
                {
                    Amount   = 123m,
                    Currency = "HKD"
                }
            });

            Assert.IsInstanceOf <OkObjectResult>(response);
            var content = ((OkObjectResult)response).Value as ProcessPaymentResult;

            Assert.IsNotNull(content.PaymentId);
            Assert.IsTrue(content.Success);
            Assert.AreEqual(id, content.TransactionId);
        }
예제 #4
0
        public async Task Add_InvalidObjectPassed_ReturnsBadRequest()
        {
            //Arrange
            var missingCardHolder = new PaymentModel
            {
                Amount           = 200.00M,
                CreditCardNumber = "123456789034566",
                ExpirationDate   = Convert.ToDateTime("2021/12/11"),
                SecurityCode     = ""
            };
            var mock = new Mock <IProcessPayment>();

            mock.Setup(p => p.MakePayment(missingCardHolder));
            PaymentController paymentController = new PaymentController(mock.Object);

            paymentController.ModelState.AddModelError("CardHolder", "Required");
            // Act
            var badResponse = await paymentController.ProcessPayment(missingCardHolder);

            // Assert
            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                Response.Redirect("UpdatePaymentType.aspx?id=" + index);
            }

            if (e.CommandName == "Delete_Payment")
            {
                int      index   = Convert.ToInt32(e.CommandArgument);
                Response respond = PaymentController.DeletePaymentType(index);
                if (respond.successStatus == false)
                {
                    alert.Text = respond.message;
                }
                else
                {
                    Response.Redirect("ViewPaymentType.aspx");
                }
            }
        }
예제 #6
0
        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"));
        }
예제 #7
0
        public void CreatePaymentAsync_Create_Error_Returns_500()
        {
            // Arrange
            var validationProviderMock = _mocks.Create <IValidate <PaymentModel> >();

            validationProviderMock.Setup(m => m.Validate(It.IsAny <PaymentModel>()))
            .Returns <ValidationResult>(null);

            var paymentBLLMock = _mocks.Create <IPaymentBLL>();

            paymentBLLMock.Setup(m => m.CreatePaymentAsync(It.IsAny <PaymentDto>()))
            .Returns(Task.FromResult(false));

            var controller = new PaymentController(paymentBLLMock.Object, validationProviderMock.Object);

            // Act
            var res = controller.CreatePaymentAsync(new PaymentModel()).Result;

            // Assert
            _mocks.Verify();
            Assert.AreEqual(((StatusCodeResult)res.Result).StatusCode, 500);
        }
        public async Task AddPaymentMethod_UserSignedIn_SetsActivePaymentMethodForUser()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new PaymentController(
                fakeMediator,
                mapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            await controller.AddPaymentMethod("some-payment-method-id");

            //Assert
            await fakeMediator
            .Received(1)
            .Send(Arg.Is <SetActivePaymentMethodForUserCommand>(arg =>
                                                                arg.PaymentMethodId == "some-payment-method-id"));
        }
        public async Task GenerateBookSlipTest()
        {
            try
            {
                var     controller = new PaymentController();
                Payment payment    = new Payment {
                    PaymentOptionId = 2, IsPaid = true, Status = 'P', PaidDate = DateTime.Now, PaidAmount = 200
                };
                SlipDeatils slipDeatils = new SlipDeatils {
                    SlipAddress = "aaa", ContactNumber = "2233"
                };
                int moduleId = 2;
                var result   = await controller.GenerateBookSlip(moduleId, payment, slipDeatils);

                Assert.Equal(result.Value, true);
                Assert.NotEqual(result.Value, true);
            }
            catch (Exception ex)
            {
                Assert.NotNull(ex);
            }
        }
예제 #10
0
        public void Setup()
        {
            var builder = new DbContextOptionsBuilder <PaymentContext>();

            builder.UseInMemoryDatabase("Payments");
            var options = builder.Options;

            var expensivePaymentGateway    = new Mock <IExpensivePaymentGateway>();
            var cheapPaymentGateway        = new Mock <ICheapPaymentGateway>();
            var premiumPaymentService      = new Mock <IPremiumPaymentService>();
            var controllerLogger           = new Mock <ILogger <PaymentController> >();
            var paymentServiceLogger       = new Mock <ILogger <PaymentService> >();
            var paymentStatusServiceLogger = new Mock <ILogger <PaymentStatusService> >();

            var paymentContext       = new PaymentContext(options);
            var unitOfwork           = new UnitOfWorkBase <PaymentContext>(paymentContext);
            var paymentStatusService = new PaymentStatusService(unitOfwork, paymentStatusServiceLogger.Object);
            var paymentService       = new PaymentService(paymentStatusService, unitOfwork, paymentServiceLogger.Object,
                                                          expensivePaymentGateway.Object, cheapPaymentGateway.Object, premiumPaymentService.Object);

            PaymentController = new PaymentController(paymentService, controllerLogger.Object);
        }
        public async Task ProcessPayment_PassesCorrectDetailsToBank()
        {
            var log   = new Mock <ILogger <PaymentController> >();
            var bank  = new Mock <IBankProvider>();
            var store = new Mock <IPaymentRequestStore>();

            bank.Setup(x => x.ProcessPaymentAsync(It.IsAny <CardDetails>(), It.IsAny <TransactionDetails>()))
            .Returns(Task.FromResult(new PaymentResponse
            {
                Successful = false
            }));

            var controller = new PaymentController(log.Object, bank.Object, store.Object);

            var card = new CardDetails
            {
                CardholderName = "ひとみ",
                CardNumber     = "1234567890123456",
                Expires        = DateTime.Now.AddMonths(5),
                CSC            = "111"
            };

            var transaction = new TransactionDetails
            {
                Amount   = 0.12m,
                Currency = "EUR"
            };

            var response = await controller.ProcessPayment(new PaymentDetails
            {
                CardDetails        = card,
                TransactionDetails = transaction
            });

            // TODO: This is lazy, should check actual values of the object to ensure they've not changed
            bank.Verify(b => b.ProcessPaymentAsync(card, transaction), Times.Once);
            bank.VerifyNoOtherCalls();
        }
예제 #12
0
        public void ShouldReturnSameTransactionIdForSameDetails()
        {
            var sut = new PaymentController();

            var details1 = new PaymentDetails()
            {
                Amount     = 1,
                CardNumber = 1234123412341234,
                CCV        = 123,
                Timestamp  = DateTime.MaxValue
            };

            var transaction1 = new PaymentDetailsRequest()
            {
                SupplierId = "123456",
                Payment    = details1
            };

            var result1 = sut.Post(transaction1);

            var details2 = new PaymentDetails()
            {
                Amount     = 1,
                CardNumber = 1234123412341234,
                CCV        = 123,
                Timestamp  = DateTime.MaxValue
            };

            var transaction2 = new PaymentDetailsRequest()
            {
                SupplierId = "123456",
                Payment    = details2
            };

            var result2 = sut.Post(transaction2);

            Assert.Equal(result1.TransactionId, result2.TransactionId);
        }
예제 #13
0
        public void ReturnCorrectValuesInResponse()
        {
            //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 paymentRequest = new MerchantPaymentRequest
            {
                Amount        = 9.99,
                Currency      = "USD",
                MerchantId    = "1",
                PaymentMethod = new PaymentMethod
                {
                    Cvv             = "123",
                    ExpirationMonth = "05",
                    ExpirationYear  = "2021",
                    Number          = "4319487612345678",
                    PaymentMethodId = new Guid(),
                    Type            = "Visa"
                }
            };


            var controller = new PaymentController(paymentRepo.Object, mapper, paymentPublisher.Object);

            //Act
            var result = controller.SubmitPayment(paymentRequest);
            var value  = ((CreatedAtActionResult)result.Result).Value as MerchantPaymentResponse; //https://github.com/dotnet/AspNetCore.Docs/issues/12533 - ew.

            //Assert
            Assert.That(value.Amount, Is.EqualTo(9.99));
            Assert.That(value.Currency, Is.EqualTo("USD"));
            Assert.That(value.MerchantId, Is.EqualTo("1"));
        }
        public async Task CheckCard_InvalidModel_BadRequest()
        {
            var log   = new Mock <ILogger <PaymentController> >();
            var bank  = new Mock <IBankProvider>();
            var store = new Mock <IPaymentRequestStore>();

            var controller = new PaymentController(log.Object, bank.Object, store.Object);

            controller.ModelState.AddModelError("an error", "error");

            var response = await controller.CheckCard(new CardDetails
            {
                CardholderName = "Robin Wood",
                CardNumber     = "1234567890123456",
                Expires        = DateTime.Now.AddMonths(5),
                ValidFrom      = DateTime.Now.AddMonths(-1),
                CSC            = "000"
            });

            Assert.IsInstanceOf <BadRequestObjectResult>(response);
            bank.VerifyNoOtherCalls();
            store.VerifyNoOtherCalls();
        }
        public void Delete_Success_ReturnsARedirectToActionResut()
        {
            // Arrange
            var paymentId   = 1;
            var testPayment = new PaymentViewModel()
            {
                Id = paymentId
            };
            var paymentsRepo     = new Mock <IPaymentService>();
            var guestsRepo       = new Mock <IGuestService>();
            var reservationsRepo = new Mock <IReservationService>();

            paymentsRepo.Setup(g => g.DeletePayment(paymentId));
            var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object);

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

            // Assert
            var redirectToActionResult = result as RedirectToActionResult;

            Assert.AreEqual("Index", redirectToActionResult.ActionName);
        }
예제 #16
0
        public async Task Payment_Process_WithBadRequestReturn()
        {
            #region Arrange
            var mockCheap      = new Mock <CheapPayService>();
            var mockExp        = new Mock <ExpPayService>();
            var mockPre        = new Mock <PrePayService>();
            var controller     = new PaymentController(mockRepo.Object, mockCheap.Object, mockExp.Object, mockPre.Object);
            var paymentDetails = new PaymentDetails()
            {
                CreditCardNumber = null,
                CardHolder       = null,
                ExpirationDate   = new DateTime(2021, 01, 01),
                Amount           = 10
            };
            #endregion

            // Act
            var result = await controller.Post(paymentDetails);

            // Assert
            var OkResult = result as BadRequestObjectResult;
            Assert.Equal("Payment processed Failed !!", OkResult.Value);
        }
예제 #17
0
        public void PostCardPaymentTest2()
        {
            Mock <ITicketRepository> TicketRepo = new Mock <ITicketRepository>();
            Mock <IOrderRepository>  OrderRepo  = new Mock <IOrderRepository>();
            var test = new PaymentController(TicketRepo.Object, OrderRepo.Object);

            test.TempData["hallMovieViewModel"] = new HallMovieViewModel()
            {
                order = new Order()
            };
            CardPaymentViewModel model = new CardPaymentViewModel()
            {
                CardNumber     = "1928374657483920",
                ExpiryMonth    = 3,
                ExpiryYear     = 2000,
                SecurityNumber = "123"
            };

            model.checkExpired(model.ExpiryMonth, model.ExpiryYear);
            var result = test.CardPayment(model).ViewName;

            Assert.AreEqual(result, "CardPayment");
        }
        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);
        }
예제 #20
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);
        }
        public PaymentControllerTests()
        {
            _fixture            = new Fixture();
            _mockPaymentService = new Mock <IPaymentService>();
            _mockClientFactory  = new Mock <IBankClientFactory>();
            _mockLogger         = new Mock <ILogger <PaymentController> >();
            _sut = new PaymentController(_mockPaymentService.Object, _mockClientFactory.Object, _mockLogger.Object);

            var claims = new List <Claim>()
            {
                new Claim(ClaimTypes.Name, "testuser")
            };
            var identity        = new ClaimsIdentity(claims, "Test");
            var claimsPrincipal = new ClaimsPrincipal(identity);
            var context         = new ControllerContext
            {
                HttpContext = new DefaultHttpContext {
                    User = claimsPrincipal
                }
            };

            _sut.ControllerContext = context;
        }
        public void Create_ReturnsTrue__GivenValidModel()
        {
            // Arrange
            var mockRepo    = new Mock <IPaymentRepository>();
            var mockLogRepo = new Mock <ILogger <PaymentController> >();
            var controller  = new PaymentController(mockRepo.Object, mockLogRepo.Object);
            var newPayment  = new Payment()
            {
                BSB         = "112789",
                AccountNo   = "123456789",
                AccountName = "Jerry",
                Reference   = "Books",
                Amount      = 100
            };

            mockRepo.Setup(repo => repo.AddNewPayment(newPayment)).Returns(true);
            // Act
            bool result = controller.Post(newPayment);

            // Assert
            mockRepo.Verify(repo => repo.AddNewPayment(newPayment));
            Assert.True(result);
        }
예제 #23
0
        public given_controller()
        {
            var routes = new RouteCollection();
            routes.MapRoute("PaymentAccept", "accept", new { controller = "Payment", action = "ThirdPartyProcessorPaymentAccepted" });
            routes.MapRoute("PaymentReject", "reject", new { controller = "Payment", action = "ThirdPartyProcessorPaymentRejected" });
            routes.MapRoute("Pay", "payment", new { controller = "ThirdPartyProcessorPayment", action = "Pay" });

            var requestMock = new Mock<HttpRequestBase>(MockBehavior.Strict);
            requestMock.SetupGet(x => x.ApplicationPath).Returns("/");
            requestMock.SetupGet(x => x.Url).Returns(new Uri("http://localhost/request", UriKind.Absolute));
            requestMock.SetupGet(x => x.ServerVariables).Returns(new NameValueCollection());

            var responseMock = new Mock<HttpResponseBase>(MockBehavior.Strict);
            responseMock.Setup(x => x.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s);

            var context = Mock.Of<HttpContextBase>(c => c.Request == requestMock.Object && c.Response == responseMock.Object);

            this.commandBusMock = new Mock<ICommandBus>();
            this.paymentDaoMock = new Mock<IPaymentDao>();
            this.sut = new PaymentController(this.commandBusMock.Object, this.paymentDaoMock.Object);
            this.sut.ControllerContext = new ControllerContext(context, new RouteData(), this.sut);
            this.sut.Url = new UrlHelper(new RequestContext(context, new RouteData()), routes);
        }
예제 #24
0
        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");
            }
        }
예제 #25
0
        public void StatusIsSetToADefaultStateOfSubmittedWhenRequestIsMadeByMerchant()
        {
            //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 paymentRequest = new MerchantPaymentRequest
            {
                Amount        = 9.99,
                Currency      = "USD",
                MerchantId    = "1",
                PaymentMethod = new PaymentMethod
                {
                    Cvv             = "123",
                    ExpirationMonth = "05",
                    ExpirationYear  = "2021",
                    Number          = "4319487612345678",
                    PaymentMethodId = new Guid(),
                    Type            = "Visa"
                }
            };


            var controller = new PaymentController(paymentRepo.Object, mapper, paymentPublisher.Object);

            //Act
            var result = controller.SubmitPayment(paymentRequest);
            var value  = ((CreatedAtActionResult)result.Result).Value as MerchantPaymentResponse;

            //Assert
            Assert.That(value.Status, Is.EqualTo(Status.Submitted));
            Assert.That(value.Status, Is.Not.EqualTo(Status.Declined));
        }
        public async Task ShouldPassPost()
        {
            var sut = new PaymentController(new Mock <ILogger <PaymentController> >().Object, _bankProcessor, _merchantRepository, _paymentRepository);

            var payment = new Payment
            {
                MerchantId = "bd2347d5-98b3-4d4e-8773-4eb4b33ca0d6",
                MerchantTransactionReference = "TestReference2",
                PaymentMethod  = 0,
                Amount         = 22.99M,
                Currency       = Currency.GBP,
                PaymentDetails = new PaymentDetails
                {
                    CardNumber  = "1234567812345678",
                    Name        = "Test Name",
                    ExpiryMonth = "12",
                    ExpiryYear  = "2030",
                    CVV         = "123",
                    Scheme      = CardScheme.Mastercard,
                    Type        = CardType.Credit,
                    Address     = new Address
                    {
                        Number   = 1,
                        Street   = "Test Road",
                        City     = "Test City",
                        County   = "Test County",
                        PostCode = "TE5 7PC"
                    }
                }
            };

            var response = await sut.Post(payment);

            var responseType = response.GetType();

            Assert.IsTrue(responseType.Name == "OkObjectResult");
        }
        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);
        }
예제 #28
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            Button currentButton = (Button)sender;
            int    selectedIndex = 0;

            int.TryParse(currentButton.ID.Substring(0, currentButton.ID.Length - 3), out selectedIndex);

            int paymentID = 0;

            paymentID = int.Parse(((Label)PaymentTable.Rows[selectedIndex].Cells[1].Controls[0]).Text);

            Response response = PaymentController.DeletePayment(paymentID);

            if (response.successStatus)
            {
                Response.Redirect(Request.RawUrl);
            }

            else
            {
                ErrorLabel.Visible = true;
                ErrorLabel.Text    = response.message;
            }
        }
예제 #29
0
        public void TestGetPayment()
        {
            // Arrange
            var dbContext  = _paymentDbContext;
            var repository = new PaymentRepository(dbContext);
            var controller = new PaymentController(repository);

            var guid    = new Guid();
            var payment = new Payment
            {
                Id                = guid,
                CardNumber        = "4111 1111 1111 1111",
                CardHolderName    = "John Doe",
                ExpiryYear        = 2020,
                ExpiryMonth       = 11,
                Amount            = 2000,
                Currency          = "USD",
                Cvv               = "123",
                BankSuccess       = true,
                BankTransactionId = new Guid().ToString()
            };

            _paymentDbContext.Payments.Add(payment);


            // Act
            var response = controller.Get(guid.ToString());
            var value    = response.Value;

            _paymentDbContext.Payments.RemoveRange(_paymentDbContext.Payments);

            // Assert
            Assert.False(value == null);
            Assert.False(value.Id == null);
            Assert.False(value.BankSuccess == false);
        }
        public async Task Return_NotFound_When_Null()
        {
            // Arrange
            var httpContext = new DefaultHttpContext();

            var controller = new PaymentController(NullLogger <PaymentController> .Instance, _paymentServiceMock.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext
                }
            };

            // Act
            var result = await controller.GetDetailsAsync(null, "paymentId1") as NotFoundObjectResult;

            var response = result.Value as DetailsResponse;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(response);
            Assert.AreEqual((int)HttpStatusCode.NotFound, result.StatusCode);
            Assert.IsFalse(response.Success);
        }
        public void Edit_PaymentExists_ReturnsAViewResultWithPayment()
        {
            // Arrange
            var paymentId   = 1;
            var testPayment = new PaymentViewModel()
            {
                Id = paymentId
            };
            var paymentsRepo     = new Mock <IPaymentService>();
            var guestsRepo       = new Mock <IGuestService>();
            var reservationsRepo = new Mock <IReservationService>();

            paymentsRepo.Setup(g => g.ReadSingle(paymentId)).Returns(testPayment);
            var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object);

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

            // Assert
            var viewResult = result as ViewResult;
            var model      = viewResult.ViewData.Model as PaymentViewModel;

            Assert.AreEqual(paymentId, model.Id);
        }