// GET: /<controller>/ public IActionResult Index() { var listService = new DisplayOrdersService(_context); SetupTraceInfo(); return(View(listService.GetUsersOrders(HttpContext.Request.Cookies))); }
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); }
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); } }