public void CanCheckoutAndCreateOrder() { IRepository <Product> products = new MockContext <Product>(); IRepository <Order> orders = new MockContext <Order>(); IRepository <Customer> customers = new MockContext <Customer>(); MockContext <Basket> baskets = new MockContext <Basket>(); products.Insert(new Product() { Id = "1", Price = 10.00m }); products.Insert(new Product() { Id = "2", Price = 5.00m }); Basket basket = new Basket(); basket.BasketItems.Add(new BasketItem() { ProductId = "1", Quantity = 2, BasketId = basket.Id }); basket.BasketItems.Add(new BasketItem() { ProductId = "2", Quantity = 1, BasketId = basket.Id }); baskets.Insert(basket); IBasketService basketService = new BasketService(products, baskets); IOrderService orderService = new OrderService(orders); customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "43220" }); 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", basket.Id)); controller.ControllerContext = new ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //Act Order order = new Order(); controller.Checkout(order); //Assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); Order orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
public void CanCheckoutAndCreateOrder() { 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); var controller = new BasketController(basketService, orderService); var httpContext = new MockHttpContext(); httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //Act Order order = new Order(); controller.Checkout(order); //assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); Order orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
public void CanCheckoutAndCreateOrder() { //Setup IRepository <Basket> baskets = new MockContext <Basket>(); IRepository <Product> products = new MockContext <Product>(); IRepository <Order> orders = new MockContext <Order>(); IRepository <Customer> customers = new MockContext <Customer>(); products.Insert(new Product() { Id = "1", Price = 10.00m }); products.Insert(new Product() { Id = "2", Price = 5.00m }); Basket basket = new Basket(); basket.BasketItems.Add(new BasketItem { ProductId = "1", Quantity = 2 }); basket.BasketItems.Add(new BasketItem { ProductId = "2", Quantity = 1 }); baskets.Insert(basket); IBasketService basketService = new BasketService(products, baskets); IOrderService orderService = new OrderService(orders); customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "LE3 9RW" }); 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 HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller); Order order = new Order(); controller.Checkout(order); Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); Order orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
public void CanCheckoutAndCreateOrder() { var products = new MockContext <Product>(); products.Insert(new Product() { Id = "1", Price = 10.00m }); products.Insert(new Product() { Id = "2", Price = 5.00m }); var baskets = new MockContext <Basket>(); var basket = new Basket(); basket.BasketItems.Add(new BasketItem() { ProductId = "1", Quantity = 2 }); basket.BasketItems.Add(new BasketItem() { ProductId = "2", Quantity = 1 }); baskets.Insert(basket); var basketService = new BasketService(products, baskets); var orders = new MockContext <Order>(); var orderService = new OrderService(orders); var customers = new MockContext <Customer>(); var controller = new BasketController(basketService, orderService, customers); var httpContext = new MockHttpContext(); httpContext.Request.Cookies.Add(new HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller); var order = new Order(); var result = controller.Checkout(order); Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); var orderInRepository = orders.Find(order.Id); Assert.AreEqual(2, orderInRepository.OrderItems.Count); }
public void CanCheckOutAndCreateOrder() { //Setup IRepository <Basket> baskets = new MockContext <Basket>(); IRepository <Product> products = new MockContext <Product>(); IRepository <Order> orders = new MockContext <Order>(); IRepository <Customer> customer = new MockContext <Customer>(); // creacion de productos products.Insert(new Product("1", "Cosa1", 5)); products.Insert(new Product("2", "Cosa2", 10)); products.Insert(new Product("3", "Cosa3", 15)); // creacion de un cliente customer.Insert(new Customer("1", "Tony", "Stark", "*****@*****.**", "something", "Los Angeles", "California", "00000")); IPrincipal FakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null); // insercion de productos en la cesta Basket basket = new Basket(); basket.BasketItems.Add(new BasketItem("1", "1", 2)); basket.BasketItems.Add(new BasketItem("1", "2", 1)); baskets.Insert(basket); IBasketService basketService = new BasketService(products, baskets); IOrderService orderService = new OrderService(orders); var controller = new BasketController(basketService, orderService, customer); var httpContext = new HttpMockContext(); httpContext.User = FakeUser; httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); // creacion de un contexto para crear y leer cookies controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); // añadir el contexto al controlador //Act Order order = new Order(); controller.Checkout(order); //Assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); Order orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
public void CanCheckoutAndCreateOrder() { IRepository <Product> products = new MockContext <Product>();//Creates a mock product repo products.Insert(new Product() { Id = "1", Price = 10.00m }); //Creates a dummy product to be added to be tested only need Id and Price BC those are the only things considered for calc 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 = "2", Quantity = 1, BasketId = basket.Id }); baskets.Insert(basket); IBasketService basketService = new BasketService(products, baskets); IRepository <Customer> customers = new MockContext <Customer>(); IRepository <Order> orders = new MockContext <Order>(); IOrderService orderService = new OrderService(orders); customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "15767" }); 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 ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //Act Order order = new Order(); controller.Checkout(order); //Assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); Order orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
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 = 2.00m }); IRepository <Cart> carts = new MockContext <Cart>(); Cart cart = new Cart(); cart.CartItems.Add(new CartItem() { ProductId = "1", Quantity = 2, CartId = cart.Id }); cart.CartItems.Add(new CartItem() { ProductId = "2", Quantity = 1, CartId = cart.Id }); carts.Insert(cart); ICartService cartService = new CartService(products, carts); IRepository <Order> orders = new MockContext <Order>(); IOrderService orderService = new OrderService(orders); customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "123" }); IPrincipal FakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "forms"), null); var controller = new CartController(cartService, orderService, customers); var httpContext = new MockHttpContext(); httpContext.User = FakeUser; httpContext.Request.Cookies.Add(new HttpCookie("eCommercecart") { Value = cart.Id }); controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller); //Act Order order = new Order(); controller.Checkout(order); //Assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, cart.CartItems.Count); Order orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
public void CanCheckoutAndCreateOrder() { // setup 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 = 50.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); // this is the repository added for this test customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "90210" }); // added fake user to the context IPrincipal FakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null); var controller = new BasketController(basketService, orderService, customers); // dependency injection var httpContext = new MockHttpContext(); httpContext.User = FakeUser; httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller); // Act Order order = new Order(); controller.Checkout(order); // Assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); Order orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
public void CanCheckoutAndCreateOrder() { IRepository <Product> products = new MockContext <Product>(); // created a mock Product repository products.Insert(new Product() { Id = "1", Price = 10.00m }); // added products with an Id and Price so we can check the Id and calculations products.Insert(new Product() { Id = "2", Price = 5.00m }); IRepository <Basket> baskets = new MockContext <Basket>(); // mock Basket repo Basket basket = new Basket(); // created two basket items basket.BasketItems.Add(new BasketItem() { ProductId = "1", Quantity = 2, BasketId = basket.Id }); basket.BasketItems.Add(new BasketItem() { ProductId = "2", 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); // created an order service with our two items and IRepository <Customer> customers = new MockContext <Customer>(); customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", Zipcode = "66021" }); IPrincipal FakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null); var controller = new BasketController(basketService, orderService, customers); // passed it thru the controller var httpContext = new MockHttpContext(); httpContext.User = FakeUser; httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //Act Order order = new Order(); controller.Checkout(order); // expects order to be checked in //Assert Assert.AreEqual(2, order.OrderItems.Count); // makes sure we have two items in our order Assert.AreEqual(0, basket.BasketItems.Count); // makes sure basket items are empty Order orderInRepo = orders.Find(order.Id); // retrieve the order from the repo Assert.AreEqual(2, orderInRepo.OrderItems.Count); // makes sure we have two orders in our repo }
public void CanCheckoutAndCreateOrder() { // Arrange IRepository <Product> productContext = new MockContext <Product>(); productContext.Insert(new Product() { Id = "1", Price = 10.00m, Name = "Product1" }); productContext.Insert(new Product() { Id = "2", Price = 5.00m }); IRepository <Basket> basketContext = 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 = "2", Quantity = 1, BasketId = basket.Id }); basketContext.Insert(basket); IRepository <BasketItem> basketItemsContext = new MockContext <BasketItem>(); IRepository <Order> orderContext = new MockContext <Order>(); IRepository <Customer> customerContext = new MockContext <Customer>(); customerContext.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "12345" }); IPrincipal FakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null); IBasketService basketService = new BasketService(productContext, basketContext, basketItemsContext); IOrderService orderService = new OrderService(orderContext); BasketController controller = new BasketController(basketService, orderService, customerContext); MockHttpContext httpContext = new MockHttpContext(); httpContext.User = FakeUser; httpContext.Response.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); // Assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); Order orderInRep = orderContext.Find(order.Id); Assert.AreEqual(10.00m, orderInRep.OrderItems.ToList().FirstOrDefault().Price); Assert.AreEqual(2, orderInRep.OrderItems.ToList().FirstOrDefault().Quantity); Assert.AreEqual("Product1", orderInRep.OrderItems.ToList().FirstOrDefault().ProductName); }