Exemplo n.º 1
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var listService = new DisplayOrdersService(_context);

            SetupTraceInfo();
            return(View(listService.GetUsersOrders(HttpContext.Request.Cookies)));
        }
Exemplo n.º 2
0
        public IActionResult ConfirmOrder(int orderId)
        {
            var detailService = new DisplayOrdersService(_context);

            SetupTraceInfo();
            return(View(detailService.GetOrderDetail(orderId)));
        }
Exemplo n.º 3
0
        public IActionResult ConfirmOrder(int orderId, string message)
        {
            var detailService = new DisplayOrdersService(_context);

            SetupTraceInfo();
            ViewData["Message"] = message ?? "Your order has been updated.";
            return(View(detailService.GetOrderDetail(orderId)));
        }
        public void TestGetOrderDetailNotFound()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using var context = new EfCoreContext(options, new FakeUserIdService(userId));
            context.Database.EnsureCreated();
            var service = new DisplayOrdersService(context);

            //ATTEMPT
            var ex = Assert.Throws <NullReferenceException>(() => service.GetOrderDetail(1));

            //VERIFY
            ex.Message.ShouldEqual("Could not find the order with id of 1.");
        }
Exemplo n.º 5
0
        public void TestGetOrderDetailNotFound()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

            using (var context = inMemDb.GetContextWithSetup())
            {
                var service = new DisplayOrdersService(context);

                //ATTEMPT
                var ex = Assert.Throws <NullReferenceException>(() => service.GetOrderDetail(1));

                //VERIFY
                ex.Message.ShouldEqual("Could not find the order with id of 1.");
            }
        }
        public void TestGetUsersOrdersDifferentUserIdOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            options.StopNextDispose();
            using (var context = new EfCoreContext(options, new FakeUserIdService(userId)))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseFourBooks();

                var order = new Order
                {
                    CustomerId = userId,
                    LineItems  = new List <LineItem>
                    {
                        new LineItem
                        {
                            BookId    = 1,
                            LineNum   = 0,
                            BookPrice = 123,
                            NumBooks  = 456
                        }
                    }
                };
                context.Orders.Add(order);
                context.SaveChanges();
            }

            var differentUserId = Guid.NewGuid();

            using (var context = new EfCoreContext(options, new FakeUserIdService(differentUserId)))
            {
                var service = new DisplayOrdersService(context);

                //ATTEMPT
                var orders = service.GetUsersOrders();

                //VERIFY
                orders.Count.ShouldEqual(0);
            }
        }
        public void TestGetUsersOrdersOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using var context = new EfCoreContext(options, new FakeUserIdService(userId));
            context.Database.EnsureCreated();
            context.SeedDatabaseFourBooks();

            var order = new Order
            {
                CustomerId = userId,
                LineItems  = new List <LineItem>
                {
                    new LineItem
                    {
                        BookId    = 1,
                        LineNum   = 0,
                        BookPrice = 123,
                        NumBooks  = 456
                    }
                }
            };

            context.Orders.Add(order);
            context.SaveChanges();
            var service = new DisplayOrdersService(context);

            //ATTEMPT
            var orders = service.GetUsersOrders();

            //VERIFY
            orders.Count.ShouldEqual(1);
            orders.First().LineItems.ShouldNotBeNull();
            var lineItems = orders.First().LineItems.ToList();

            lineItems.Count.ShouldEqual(1);
            lineItems.First().BookId.ShouldEqual(1);
            lineItems.First().BookPrice.ShouldEqual(123);
            lineItems.First().NumBooks.ShouldEqual((short)456);
        }
Exemplo n.º 8
0
        public void TestGetUsersOrdersOk()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

            using (var context = inMemDb.GetContextWithSetup())
            {
                context.SeedDatabaseFourBooks();
                var userId = Guid.NewGuid();

                var order = new Order
                {
                    CustomerName = userId,
                    LineItems    = new List <LineItem>
                    {
                        new LineItem
                        {
                            BookId    = 1,
                            LineNum   = 0,
                            BookPrice = 123,
                            NumBooks  = 456
                        }
                    }
                };
                context.Orders.Add(order);
                context.SaveChanges();
                var mockCookieRequests = new MockHttpCookieAccess(CheckoutCookie.CheckoutCookieName, $"{userId}");
                var service            = new DisplayOrdersService(context);

                //ATTEMPT
                var orders = service.GetUsersOrders(mockCookieRequests.CookiesIn);

                //VERIFY
                orders.Count.ShouldEqual(1);
                orders.First().LineItems.ShouldNotBeNull();
                var lineItems = orders.First().LineItems.ToList();
                lineItems.Count.ShouldEqual(1);
                lineItems.First().BookId.ShouldEqual(1);
                lineItems.First().BookPrice.ShouldEqual(123);
                lineItems.First().NumBooks.ShouldEqual((short)456);
            }
        }
Exemplo n.º 9
0
        public void TestGetOrderDetailOk()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

            using (var context = inMemDb.GetContextWithSetup())
            {
                context.SeedDatabaseFourBooks();
                var userId = Guid.NewGuid();

                var order = new Order
                {
                    CustomerName = userId,
                    LineItems    = new List <LineItem>
                    {
                        new LineItem
                        {
                            BookId    = 1,
                            LineNum   = 0,
                            BookPrice = 123,
                            NumBooks  = 456
                        }
                    }
                };
                context.Orders.Add(order);
                context.SaveChanges();
                var service = new DisplayOrdersService(context);

                //ATTEMPT
                var dto = service.GetOrderDetail(1);

                //VERIFY
                var lineItems = dto.LineItems.ToList();
                lineItems.Count.ShouldEqual(1);
                lineItems.First().BookId.ShouldEqual(1);
                lineItems.First().BookPrice.ShouldEqual(123);
                lineItems.First().NumBooks.ShouldEqual((short)456);
            }
        }