Ejemplo n.º 1
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var listService = new CheckoutListService(_context, HttpContext.Request.Cookies);

            SetupTraceInfo();
            return(View(listService.GetCheckoutInfoFromCookie()));
        }
        public void TestCheckoutListOneBookDatabaseOneBook()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseDummyBooks(1);
            }
            //two line items: BookId:1 NumBooks:1
            var mockCookieRequests = new MockHttpCookieAccess(BasketCookie.BasketCookieName, $"{Guid.NewGuid()},1,1");

            //ATTEMPT
            using (var context = new EfCoreContext(options))
            {
                var service = new CheckoutListService(context, mockCookieRequests.CookiesIn);
                var list    = service.GetCheckoutList();

                //VERIFY
                list.Count.ShouldEqual(1);
                list.First().BookId.ShouldEqual(1);
                list.First().BookPrice.ShouldEqual(1);
            }
        }
        public void TestCheckoutListTwoBooksSqLite()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabaseDummyBooks(10);

                //two line items: BookId:1 NumBooks:2, BookId:2 NumBooks:3
                var mockCookieRequests = new MockHttpCookieAccess(BasketCookie.BasketCookieName, $"{Guid.NewGuid()},1,2,2,3");

                //ATTEMPT

                var service = new CheckoutListService(context, mockCookieRequests.CookiesIn);
                var list    = service.GetCheckoutList();

                //VERIFY
                for (int i = 0; i < list.Count(); i++)
                {
                    list[i].BookId.ShouldEqual(i + 1);
                    list[i].NumBooks.ShouldEqual((short)(i + 2));
                    list[i].BookPrice.ShouldEqual((i + 1));
                }
            }
        }
Ejemplo n.º 4
0
        public void TestCheckoutListTwoBooksSqLite()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();


            using (var context = inMemDb.GetContextWithSetup())
            {
                context.SeedDatabaseDummyBooks(10);

                //two line items: BookId:1 NumBooks:2, BookId:2 NumBooks:3
                var mockCookieRequests = new MockHttpCookieAccess(CheckoutCookie.CheckoutCookieName, $"{Guid.NewGuid()},1,2,2,3");

                //ATTEMPT

                var service = new CheckoutListService(context, mockCookieRequests.CookiesIn);
                var list    = service.GetCheckoutList();

                //VERIFY
                for (int i = 0; i < list.Count(); i++)
                {
                    list[i].BookId.ShouldEqual(i + 1);
                    list[i].NumBooks.ShouldEqual((short)(i + 2));
                    list[i].BookPrice.ShouldEqual((i + 1));
                }
            }
        }
Ejemplo n.º 5
0
        public IActionResult Index()
        {
            var service = new CheckoutListService(dataContext, HttpContext.Request.Cookies);

            SetupTraceInfo();
            return(View(service.GetCheckoutList()));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PlaceOrder(bool acceptTAndCs, [FromServices] IPlaceOrderBizLogic bizLogic)
        {
            var service   = new PlaceOrderService(HttpContext.Request.Cookies, HttpContext.Response.Cookies, bizLogic);
            var bizStatus = await service.PlaceOrderAndClearBasketAsync(acceptTAndCs);

            if (bizStatus.IsValid)
            {
                return(RedirectToAction("ConfirmOrder", "Orders", new { orderId = bizStatus.Result }));
            }

            //Otherwise errors, so copy over and redisplay
            bizStatus.CopyErrorsToModelState(ModelState);
            var listService = new CheckoutListService(_context, HttpContext.Request.Cookies);

            SetupTraceInfo();
            return(View(listService.GetCheckoutList()));
        }
        public void TestCheckoutListBookWithPromotion()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

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

            //I select the last book, which has a promotion
            var mockCookieRequests = new MockHttpCookieAccess(BasketCookie.BasketCookieName, $"{Guid.NewGuid()},4,1");

            //ATTEMPT

            var service = new CheckoutListService(context, mockCookieRequests.CookiesIn);
            var list    = service.GetCheckoutList();

            //VERIFY
            list.Count.ShouldEqual(1);
            list.First().BookPrice.ShouldEqual(219);
        }
Ejemplo n.º 8
0
        public IActionResult PlaceOrder(bool acceptTAndCs)
        {
            var service = new PlaceOrderService(HttpContext.Request.Cookies, HttpContext.Response.Cookies, dataContext);
            var orderId = service.PlaceOrder(acceptTAndCs);

            if (service.Errors.Count == 0)
            {
                return(RedirectToAction("ConfirmOrder", "Orders", new { orderId }));
            }

            foreach (var error in service.Errors)
            {
                var memberNames = error.MemberNames.ToList();
                ModelState.AddModelError(memberNames.Any() ? memberNames.First() : "", error.ErrorMessage);
            }

            var listService = new CheckoutListService(dataContext, HttpContext.Request.Cookies);

            SetupTraceInfo();
            return(View(listService.GetCheckoutList()));
        }
Ejemplo n.º 9
0
        public IActionResult PlaceOrder(bool acceptTAndCs)
        {
            var service = new PlaceOrderService(HttpContext.Request.Cookies, HttpContext.Response.Cookies, _context);
            var orderId = service.PlaceOrder(acceptTAndCs);

            if (!service.Errors.Any())
            {
                return(RedirectToAction("ConfirmOrder", "Orders", new { orderId }));
            }

            //Otherwise errors, so copy over and redisplay
            foreach (var error in service.Errors)
            {
                var properties = error.MemberNames.ToList();
                ModelState.AddModelError(properties.Any() ? properties.First() : "", error.ErrorMessage);
            }
            var listService = new CheckoutListService(_context, HttpContext.Request.Cookies);

            SetupTraceInfo();
            return(View(listService.GetCheckoutList()));
        }
Ejemplo n.º 10
0
        public void TestCheckoutListBookWithPromotion()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

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

                //I select the last book, which has a promotion
                var mockCookieRequests = new MockHttpCookieAccess(CheckoutCookie.CheckoutCookieName, $"{Guid.NewGuid()},4,1");

                //ATTEMPT

                var service = new CheckoutListService(context, mockCookieRequests.CookiesIn);
                var list    = service.GetCheckoutList();

                //VERIFY
                list.Count.ShouldEqual(1);
                list.First().BookPrice.ShouldEqual(219);
            }
        }
Ejemplo n.º 11
0
        //----------------------------------------------------
        //private methods

        private CheckoutDto FormCheckoutDtoFromCookie(HttpContext httpContext)
        {
            var listService = new CheckoutListService(_context, HttpContext.Request.Cookies);

            return(listService.GetCheckoutInfoFromCookie());
        }