public void canCheckoutAndCreateOrder() { IRepository <Customer> customers = new MockContext <Customer>(); IRepository <Product> products = new MockContext <Product>(); products.insert(new Product() { Id = "1", Price = 10.00m }); products.insert(new Product() { Id = "2", Price = 5.00m }); IRepository <Basket> baskets = new MockContext <Basket>(); Basket basket = new Basket(); basket.basketItems.Add(new BasketItem() { productId = "1", quantity = 2, basketId = basket.Id }); basket.basketItems.Add(new BasketItem() { productId = "1", quantity = 1, basketId = basket.Id }); baskets.insert(basket); IBasketService basketService = new BasketService(products, baskets); IRepository <Order> orders = new MockContext <Order>(); IOrderService orderService = new OrderService(orders); customers.insert(new Customer() { Id = "1", email = "*****@*****.**", zipCode = "452005" }); IPrincipal fakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null); var controller = new BasketController(basketService, orderService, customers); var httpContext = new MockHttpContext(); httpContext.User = fakeUser; httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //act Order order = new Order(); controller.checkOut(order); //asert Assert.AreEqual(2, order.orderItems.Count); Assert.AreEqual(0, basket.basketItems.Count); Order orderInRep = orders.find(order.Id); Assert.AreEqual(2, order.orderItems.Count); }