Ejemplo n.º 1
0
        public void PaymentPost_InvalidModelOfPaymentViewModel()
        {
            using (var homeController = new HomeController(MockData.MoqLogger(), MockData.MoqShopContext(),
                                                           MockData.MoqEmailSender(), MockData.MoqMyLogger()))
            {
                var pvm = new PaymentViewModel
                {
                    SuccessfulPayment = false,
                    CardName          = "Jan Nowak",
                    CardNumber        = "3714 4963 539 8431",
                    CardExp           = "12.2023",
                    CardCVV           = 123,
                    OrderId           = 3,
                    TotalPrice        = 0.00
                };

                homeController.ModelState.AddModelError(string.Empty, "Test Error");

                Assert.False(homeController.ModelState.IsValid, "Model state has remained valid.");

                // Test for BadRequest being returned
                var result = homeController.PaymentPost(pvm) as ViewResult;
                var model  = result?.Model;

                Assert.Equal("Payment", result?.ViewName);
                Assert.True(model.IsSameOrEqualTo(pvm));
            }
        }
Ejemplo n.º 2
0
        public void PaymentPost_ValidModelOfPaymentViewModel()
        {
            var context = MockData.MoqShopContext();

            using (var homeController = new HomeController(MockData.MoqLogger(), context,
                                                           MockData.MoqEmailSender(), MockData.MoqMyLogger()))
            {
                var pvm1 = MockData.GetMoqPaymentViewModel(3, 499.99);
                var pvm2 = MockData.GetMoqPaymentViewModel(1, 500.00);;
                // Order does not exists
                var pvm3 = MockData.GetMoqPaymentViewModel(25, 230.45);

                var result1 = homeController.PaymentPost(pvm1) as RedirectToActionResult;
                var result2 = homeController.PaymentPost(pvm2) as RedirectToActionResult;
                var result3 = homeController.PaymentPost(pvm3) as RedirectToActionResult;

                var orderPayment1 = context?.Orders?.FirstOrDefault(o => o.OrderId == pvm1.OrderId)?.Payment;
                var orderPayment2 = context?.Orders?.FirstOrDefault(o => o.OrderId == pvm2.OrderId)?.Payment;
                var orderPayment3 = context?.Orders?.FirstOrDefault(o => o.OrderId == pvm3.OrderId)?.Payment;

                Assert.Equal("OrderConfirmation", result1?.ActionName);
                Assert.Equal("True", result1?.RouteValues["success"]?.ToString());
                Assert.Equal("499.99", result1?.RouteValues["price"]?.ToString());
                Assert.Equal("3", result1?.RouteValues["id"]?.ToString());
                Assert.Equal(orderPayment1, pvm1.SuccessfulPayment);

                Assert.Equal("OrderConfirmation", result2?.ActionName);
                Assert.Equal("False", result2?.RouteValues["success"]?.ToString());
                Assert.Equal("500", result2?.RouteValues["price"]?.ToString());
                Assert.Equal("1", result2?.RouteValues["id"]?.ToString());
                Assert.Equal(orderPayment2, pvm2.SuccessfulPayment);

                Assert.Equal("OrderConfirmation", result3?.ActionName);
                Assert.Equal("True", result3?.RouteValues["success"]?.ToString());
                Assert.Equal("230.45", result3?.RouteValues["price"]?.ToString());
                Assert.Equal("25", result3?.RouteValues["id"]?.ToString());
                Assert.Null(orderPayment3);

                Assert.Equal("OrderConfirmation", result1?.ActionName);
                Assert.Equal("OrderConfirmation", result2?.ActionName);
                Assert.Equal("OrderConfirmation", result3?.ActionName);
            }
        }