示例#1
0
        public IActionResult ConfirmOrder(int orderId)
        {
            var detailService = new DisplayOrdersService(_context);

            SetupTraceInfo();
            return(View(detailService.GetOrderDetail(orderId)));
        }
示例#2
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.");
        }
示例#4
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 TestGetOrderDetailOk()
        {
            //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 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);
        }
示例#6
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);
            }
        }