Beispiel #1
0
        public void Test_Modify()
        {
            // ARRANGE
            cart = new WMoSS.Entities.Cart
            {
                CartItems = new WMoSS.Entities.CartItem[]
                {
                    new WMoSS.Entities.CartItem
                    {
                        MovieSessionId = 1,
                        TicketQuantity = 1
                    }
                }
            };

            // ACT
            var isModified = cart.Modify(1, new WMoSS.Entities.CartItem
            {
                MovieSessionId = 1,
                TicketQuantity = 2
            });

            // ASSERT
            Assert.True(isModified);
            Assert.Equal(2, cart.CartItems.First().TicketQuantity);
        }
Beispiel #2
0
        public void Test_Modify_ReturnsFalse_WhenCartIsNotModified()
        {
            // ARRANGE
            cart = new WMoSS.Entities.Cart
            {
                CartItems = new WMoSS.Entities.CartItem[]
                {
                    new WMoSS.Entities.CartItem
                    {
                        MovieSessionId = 1,
                        TicketQuantity = 1
                    }
                }
            };

            // ACT
            var isModified = cart.Modify(2, new WMoSS.Entities.CartItem
            {
                MovieSessionId = 2,
                TicketQuantity = 2
            });

            // ASSERT
            Assert.False(isModified);
            Assert.Equal(1, cart.CartItems.First().TicketQuantity);
        }
Beispiel #3
0
        public void Test_WhenModifyCartFailsToModifyCart_ItRendersTheCartPageAgain()
        {
            // ARRANGE
            var cartItem = new WMoSS.Entities.CartItem
            {
                MovieSessionId = 1,
                TicketQuantity = 1
            };
            var cartItem2 = new WMoSS.Entities.CartItem
            {
                MovieSessionId = 2,
                TicketQuantity = 1
            };
            var cart = new WMoSS.Entities.Cart
            {
                CartItems = new WMoSS.Entities.CartItem[] { cartItem }
            };

            var jsonCart = JsonConvert.SerializeObject(cart);

            byte[] jsonCartBytes = System.Text.Encoding.UTF8.GetBytes(jsonCart);
            mockSession.Setup(ms => ms.TryGetValue("cart", out jsonCartBytes)).Returns(true).Verifiable();

            // assume cart item submitted has different movie session id
            // this should pass the ModelState.IsValid but fails on further validation
            CartIndexModel.CartItem = cartItem2;

            // ACT
            var result = CartIndexModel.OnPostModifyCart();

            // ASSERT
            Assert.IsType <PageResult>(result);
        }
Beispiel #4
0
        public void Test_WhenModifyCart_IsSuccessful_RedirectsToCartPage()
        {
            var cartItem = new WMoSS.Entities.CartItem
            {
                MovieSessionId = 1,
                TicketQuantity = 1
            };

            // ARRANGE
            // Extension methods cannot be mocked
            // so serialize the cart into string they convert to byte array
            // Also do not mock the cart and cart items
            var cart = new WMoSS.Entities.Cart
            {
                CartItems = new WMoSS.Entities.CartItem[] { cartItem }
            };
            var jsonCart = JsonConvert.SerializeObject(cart);

            byte[] jsonCartBytes = System.Text.Encoding.UTF8.GetBytes(jsonCart);
            mockSession.Setup(ms => ms.TryGetValue("cart", out jsonCartBytes)).Returns(true).Verifiable();


            CartIndexModel.CartItem = cart.CartItems.FirstOrDefault();

            // ACT
            var result = CartIndexModel.OnPostModifyCart();

            // ASSERT
            var redirect = Assert.IsType <RedirectToPageResult>(result);

            Assert.Equal("/Cart/Index", redirect.PageName);
        }
Beispiel #5
0
        public async Task Test_OnPostAsync_WhenMovieSessionStartsSoon_CheckoutRejectedRedirectedBackToCartMovieSessionInCartIsRemoved()
        {
            using (var db = new ApplicationDbContext(Utilities.TestingDbContextOptions <ApplicationDbContext>()))
            {
                DbInitializer.Initialize(db);

                checkoutIndexModel = new WMoSS.Pages.Checkout.IndexModel(db)
                {
                    PageContext = pageContext,
                    TempData    = tempData,
                    Url         = new UrlHelper(pageContext)
                };

                // ARRANGE
                var movieSession = await db.MovieSessions.FirstOrDefaultAsync(ms => ms.Id == 1);

                movieSession.ScheduledAt = DateTime.Now.AddMinutes(59);
                await db.SaveChangesAsync();

                var cart = new WMoSS.Entities.Cart
                {
                    CartItems = new WMoSS.Entities.CartItem[]
                    {
                        new WMoSS.Entities.CartItem {
                            MovieSessionId = 1, TicketQuantity = 1
                        },
                        new WMoSS.Entities.CartItem {
                            MovieSessionId = 2, TicketQuantity = 1
                        },
                    }.ToList()
                };

                var order = new WMoSS.Entities.Order
                {
                    FullName       = "Sample user",
                    MailingAddress = "123 Club house avenue",
                    EmailAddress   = "*****@*****.**",
                    CardNumber     = "4111111111111111",
                    Expiry         = "10/20",
                    CVV            = "123"
                };

                checkoutIndexModel.Order = order;

                checkoutIndexModel.Cart = cart;
                var    jsonCart      = JsonConvert.SerializeObject(cart);
                byte[] jsonCartBytes = System.Text.Encoding.UTF8.GetBytes(jsonCart);
                mockSession.Setup(ms => ms.TryGetValue("cart", out jsonCartBytes)).Returns(true).Verifiable();

                // ACT
                var result = await checkoutIndexModel.OnPostAsync();

                // ASSERT
                var redirect = Assert.IsType <RedirectToPageResult>(result);
                Assert.Equal("/Cart/Index", redirect.PageName);
                Assert.NotNull(tempData["Danger"]);
            }
        }
Beispiel #6
0
        public async Task Test_OrderTicketsArePopulated_AfterSuccessfulCheckout()
        {
            using (var db = new ApplicationDbContext(Utilities.TestingDbContextOptions <ApplicationDbContext>()))
            {
                DbInitializer.Initialize(db);

                checkoutIndexModel = new WMoSS.Pages.Checkout.IndexModel(db)
                {
                    PageContext = pageContext,
                    TempData    = tempData,
                    Url         = new UrlHelper(pageContext)
                };

                // ARRANGE
                var cart = new WMoSS.Entities.Cart
                {
                    CartItems = new WMoSS.Entities.CartItem[]
                    {
                        new WMoSS.Entities.CartItem
                        {
                            MovieSessionId = 1,
                            TicketQuantity = 1,
                        }
                    }.ToList()
                };

                var order = new WMoSS.Entities.Order
                {
                    FullName       = "Sample user",
                    MailingAddress = "123 Club house avenue",
                    EmailAddress   = "*****@*****.**",
                    CardNumber     = "4111111111111111",
                    Expiry         = "10/20",
                    CVV            = "123"
                };

                checkoutIndexModel.Order = order;

                checkoutIndexModel.Cart = cart;
                var    jsonCart      = JsonConvert.SerializeObject(cart);
                byte[] jsonCartBytes = System.Text.Encoding.UTF8.GetBytes(jsonCart);
                mockSession.Setup(ms => ms.TryGetValue("cart", out jsonCartBytes)).Returns(true).Verifiable();

                // ACT
                var result = await checkoutIndexModel.OnPostAsync();

                // ASSERT
                Assert.IsType <RedirectToPageResult>(result);
                var expectedNumTickets = cart.CartItems.Sum(ci => ci.TicketQuantity);
                Assert.Equal(expectedNumTickets, checkoutIndexModel.Order.Tickets.Count());
            }
        }
Beispiel #7
0
        public async Task Test_OnPost_WithINVALIDModelState_RendersTheFormAgain()
        {
            // ARRANGE
            var cart = new WMoSS.Entities.Cart
            {
                CartItems = new WMoSS.Entities.CartItem[]
                {
                    new WMoSS.Entities.CartItem
                    {
                        MovieSessionId = 1,
                        TicketQuantity = 1,
                    }
                }.ToList()
            };

            var order = new WMoSS.Entities.Order
            {
                FullName       = "", // INVALID
                MailingAddress = "123 Club house avenue",
                EmailAddress   = "*****@*****.**",
                CardNumber     = "4111111111111111",
                Expiry         = "10/20",
                CVV            = "123"
            };

            checkoutIndexModel.Order = order;

            checkoutIndexModel.Cart = cart;
            var jsonCart = JsonConvert.SerializeObject(cart);

            byte[] jsonCartBytes = System.Text.Encoding.UTF8.GetBytes(jsonCart);
            mockSession.Setup(ms => ms.TryGetValue("cart", out jsonCartBytes)).Returns(true).Verifiable();

            // check for validation errors
            SimulateValidation(order, checkoutIndexModel);

            // ACT
            var result = await checkoutIndexModel.OnPostAsync();

            // ASSERT
            Assert.IsType <PageResult>(result);
            Assert.NotNull(tempData["Danger"]);
        }
Beispiel #8
0
        public void Test_Remove()
        {
            // ARRANGE
            cart = new WMoSS.Entities.Cart
            {
                CartItems = (new WMoSS.Entities.CartItem[]
                {
                    new WMoSS.Entities.CartItem
                    {
                        MovieSessionId = 1,
                        TicketQuantity = 1
                    }
                }).ToList()
            };

            // ACT
            var isRemoved = cart.Remove(1);

            // ASSERT
            Assert.True(isRemoved);
            Assert.Equal(0, cart.CartItems.Count);
        }
Beispiel #9
0
        public void Test_Remove_ReturnsFalse_When_MovieSessionNotFound()
        {
            // ARRANGE
            cart = new WMoSS.Entities.Cart
            {
                CartItems = new WMoSS.Entities.CartItem[]
                {
                    new WMoSS.Entities.CartItem
                    {
                        MovieSessionId = 1,
                        TicketQuantity = 1
                    }
                }.ToList()
            };

            // ACT
            var isRemoved = cart.Remove(2);

            // ASSERT
            Assert.False(isRemoved);
            Assert.Equal(1, cart.CartItems.Count);
        }
Beispiel #10
0
 public CartTests()
 {
     cart        = new WMoSS.Entities.Cart();
     mockSession = new Mock <ISession>();
 }