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); }
public CampaignTester() { _basketService = Tools.GetBasketService(); }
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); }
public void CanCheckoutAndCreateOrder() { IRepository <Product> products = new MockContext <Product>(); IRepository <Customer> customers = new MockContext <Customer>(); products.Insert(new Product() { Id = "1", Price = 10.00m }); products.Insert(new Product() { Id = "2", Price = 11.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); //Fake user email customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "57000" }); 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("wappBasket") { 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);//To check whether the item in repo or not }
public static void OpenGeneralOperations() { Console.WriteLine($"Choose operation (please enter the number):\n " + $"{(int)GeneralOperationsEnum.ListProducts} - Get list of Products\n " + $"{(int)GeneralOperationsEnum.ByProduct} - By the Product\n " + $"{(int)GeneralOperationsEnum.OpenBasket} - Open my Basket\n " + $"{(int)GeneralOperationsEnum.CloseProgram} - Close Program\n" + $"{(int)GeneralOperationsEnum.Discounts} - Get All Discounts\n"); string value = Console.ReadLine(); int operationNumber; int.TryParse(value, out operationNumber); switch (operationNumber) { case (int)GeneralOperationsEnum.ListProducts: Helpers.ShowProductsInMarket(productService.GetProducts()); break; case (int)GeneralOperationsEnum.ByProduct: Helpers.ShowProductsInMarket(productService.GetProducts()); Console.WriteLine("Choose the product (please enter Id product)"); string productId = Console.ReadLine(); Product product = productService.GetProduct(productId); if (product != null) { productService.RemoveProduct(product); basketService.AddProductToBasket(product); } else { Console.WriteLine("Product was not found please try again"); } break; case (int)GeneralOperationsEnum.OpenBasket: List <ProductResponseModel> productsInBasket = basketService.ListProducts(); List <Product> wholeProductsInBasket = basketService.ListWholeProducts(); if (wholeProductsInBasket.Any()) { BasketService basketServiceUpCast = basketService as BasketService; Dictionary <string, double> discounts = basketServiceUpCast.CheckDiscounts(wholeProductsInBasket); double basketSum = wholeProductsInBasket.Sum(x => x.Cost); foreach (var item in productsInBasket) { Console.WriteLine("\nName - {0},\n Count - {1},\n Sub-total-item - {2}", item.ProductName, item.CountProducts, wholeProductsInBasket.Where(x => x.ProductId == item.ProductId).Sum(x => x.Cost)); Console.WriteLine("Any discount applicable - {0}", discounts.FirstOrDefault(x => x.Key == item.ProductId).Value); } Console.WriteLine("Sub-total of the basket - {0}", basketSum); Console.WriteLine("Grant Total Price - {0}", Math.Abs(basketSum - discounts.Values.Sum())); Console.WriteLine(new string('-', 80)); OpenBasketOperations(); } else { Console.WriteLine("Basket is empty"); } break; case (int)GeneralOperationsEnum.CloseProgram: return; case (int)GeneralOperationsEnum.Discounts: foreach (var item in DataDiscount.DiscountDatas) { Console.WriteLine(item.Name); } break; default: Console.WriteLine("Provide operation is incorrect, please try again"); break; } Console.WriteLine(new string('-', 80)); OpenGeneralOperations(); }
public Service1() { service = new BasketService(); }
public void TearDown() { _sut.ResetBasket(); _sut = null; }
public async void ThrowsGivenNullUserId() { var basketService = new BasketService(null, null, null, null); await Assert.ThrowsAsync <ArgumentNullException>(async() => await basketService.TransferBasketAsync("abcdefg", null)); }
public static void Main(string[] args) { IProductRepository productRepository = new ProductRepository(); IGiftVoucherRepository giftVoucherRepository = new GiftVoucherRepository(); IOfferVoucherRepository offerVoucherRepository = new OfferVoucherRepository(); ConsoleSetup(0); // Empty Basket var shoppingBasket = new BLL.ShoppingBasket(); IBasketProcessorFactory basketProcessorFactory = new BasketProcessorFactory(); var basetService = new BasketService(basketProcessorFactory); var basketServiceResponse = basetService.GetBasketTotal(shoppingBasket); Console.WriteLine($"Basket0 - Total : £{basketServiceResponse.BasketTotal}"); Console.WriteLine($"Basket0 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}"); ConsoleSetup(0); // Basket 1: shoppingBasket = new BLL.ShoppingBasket { GiftVouchers = new List <GiftVoucher> { giftVoucherRepository.GetGiftVoucher(1) } }; shoppingBasket.AddtemToBasket(productRepository.GetProduct(1)); shoppingBasket.AddtemToBasket(productRepository.GetProduct(2)); basetService = new BasketService(basketProcessorFactory); basketServiceResponse = basetService.GetBasketTotal(shoppingBasket); Console.WriteLine($"Basket1 - Total : £{basketServiceResponse.BasketTotal}"); ConsoleSetup(0); // Basket 2: shoppingBasket = new BLL.ShoppingBasket { OfferVoucher = offerVoucherRepository.GetOffVoucher(1) }; shoppingBasket.AddtemToBasket(productRepository.GetProduct(3)); shoppingBasket.AddtemToBasket(productRepository.GetProduct(4)); basetService = new BasketService(basketProcessorFactory); basketServiceResponse = basetService.GetBasketTotal(shoppingBasket); Console.WriteLine($"Basket2 - Total : £{basketServiceResponse.BasketTotal}"); Console.WriteLine($"Basket2 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}"); ConsoleSetup(0); // Basket 3: shoppingBasket = new BLL.ShoppingBasket { OfferVoucher = offerVoucherRepository.GetOffVoucher(1) }; shoppingBasket.AddtemToBasket(productRepository.GetProduct(3)); shoppingBasket.AddtemToBasket(productRepository.GetProduct(4)); shoppingBasket.AddtemToBasket(productRepository.GetProduct(5)); //basketProcessorFactory = new BasketProcessorFactory(); basetService = new BasketService(basketProcessorFactory); basketServiceResponse = basetService.GetBasketTotal(shoppingBasket); Console.WriteLine($"Basket3 - Total : £{basketServiceResponse.BasketTotal}"); Console.WriteLine($"Basket3 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}"); ConsoleSetup(0); // Basket 4: shoppingBasket = new BLL.ShoppingBasket { GiftVouchers = new List <GiftVoucher> { giftVoucherRepository.GetGiftVoucher(1) }, OfferVoucher = offerVoucherRepository.GetOffVoucher(2) }; shoppingBasket.AddtemToBasket(productRepository.GetProduct(3)); shoppingBasket.AddtemToBasket(productRepository.GetProduct(4)); basetService = new BasketService(basketProcessorFactory); basketServiceResponse = basetService.GetBasketTotal(shoppingBasket); Console.WriteLine($"Basket4 - Total : £{basketServiceResponse.BasketTotal}"); Console.WriteLine($"Basket4 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}"); ConsoleSetup(0); // Basket 5: shoppingBasket = new BLL.ShoppingBasket { OfferVoucher = offerVoucherRepository.GetOffVoucher(2) }; shoppingBasket.AddtemToBasket(productRepository.GetProduct(3)); shoppingBasket.AddtemToBasket(productRepository.GetProduct(6)); basetService = new BasketService(basketProcessorFactory); basketServiceResponse = basetService.GetBasketTotal(shoppingBasket); Console.WriteLine($"Basket5 - Total : £{basketServiceResponse.BasketTotal}"); Console.WriteLine($"Basket5 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}"); Console.ReadLine(); }
public void Setup() { new SetupDatabase().InitializeDatabase(new ApplicationDbContext()); repoProduct = new ProductRepository(); repoBasket = new BasketRepository(); repoOrderQueue = new OrderQueueRepository(); repoFm = new GenericRepository<Framework>(); repoOs = new GenericRepository<OS>(); repoUser = new UserRepository(); productService = new ProductService(repoFm, repoOs, repoProduct, repoBasket); basketService = new BasketService(repoBasket); userservice = new UserService(repoUser); languageservice = new LanguageService(); controller = new ProductController(productService); catController = new CataloogController(productService, basketService, userservice, languageservice); }
public void CanCheckoutAndCreateOrder() { var customers = new MockContext <Customer>(); 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, BasketId = basket.Id }); basket.BasketItems.Add(new BasketItem() { ProductId = "1", Quantity = 1, BasketId = basket.Id }); baskets.Insert(basket); var basketService = new BasketService(products, baskets); var orders = new MockContext <Order>(); var orderService = new OrderService(orders); customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "4350" }); var 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 System.Web.Routing.RouteData(), controller); // Act var order = new Order(); controller.Checkout(order); // Assert Assert.AreEqual(2, order.OrderItems.Count); Assert.AreEqual(0, basket.BasketItems.Count); var orderInRep = orders.Find(order.Id); Assert.AreEqual(2, orderInRep.OrderItems.Count); }
public ListingController(BasketService basketService, EquipmentService equipmentService, PricingCommandService pricingCommandService) { _basketService = basketService; _equipmentService = equipmentService; _pricingCommandService = pricingCommandService; }
public BasketController(BasketService basketService) { this.basketService = basketService; }
public void SetUp() { // Given BasketRepository and BasketService mockedBasketRepo = new Mock <IBasketRepository>(); basketService = new BasketService(mockedBasketRepo.Object); }
public void CanCheckoutAndCreateOrderTest() { IRepository <Product> product_context = new MockRepository <Product>(); IRepository <Basket> basket_context = new MockRepository <Basket>(); IRepository <Order> order_context = new MockRepository <Order>(); IRepository <Customer> customer_context = new MockRepository <Customer>(); product_context.Insert(new Product() { id = "1", price = 10.00m }); product_context.Insert(new Product() { id = "2", price = 5.00m }); product_context.Insert(new Product() { id = "3", price = 10.00m }); Basket basket = new Basket(); basket.basketItems.Add(new BasketItem() { product_id = "1", quantity = 2, BasketId = basket.id }); basket.basketItems.Add(new BasketItem() { product_id = "2", quantity = 2, BasketId = basket.id }); basket_context.Insert(basket); IBasketService basketService = new BasketService(product_context, basket_context); IOrderService orderService = new OrderService(order_context); customer_context.Insert(new Customer() { id = "1", email = "*****@*****.**" }); IPrincipal fake_user = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null); BasketController basketController = new BasketController(basketService, orderService, customer_context); var httpContext = new MockHttpContext(); httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.id }); httpContext.User = fake_user; basketController.ControllerContext = new ControllerContext(httpContext, new System.Web.Routing.RouteData(), basketController); Order order = new Order(); basketController.Checkout(order); Assert.AreEqual(2, order.orderItems.Count); Assert.AreEqual(0, basket.basketItems.Count); Order order1 = order_context.Find(order.id); Assert.AreEqual(2, order1.orderItems.Count); }
public InvoiceController(BasketService basketService, PricingReadService pricingReadService) { _basketService = basketService; _pricingReadService = pricingReadService; }
public void BasketService_WhenBasketIsEmpty_TotalPriceIsZero() { var basket = new BasketService(mockProductRepository.Object); Assert.Equal(0, basket.GetTotal()); }
public async void ThrowsGivenNullAnonymousId() { var basketService = new BasketService(null, null, null, null); await Assert.ThrowsAsync <ArgumentNullException>(async() => await basketService.TransferBasketAsync(null, "steve")); }
private Basket GetBasketByExternalSession() { var externalSessionId = AuthenticationService.GetExternalSessionId(ExternalBasketCookieName); return(BasketService.GetBasketBySessionId(externalSessionId)); }
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(baskets, products); IRepository <Order> orders = new MockContext <Order>(); IOrderService orderService = new OrderService(orders); customers.Insert(new Customer() { Id = "1", Email = "*****@*****.**", ZipCode = "90210" }); 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 OrderController(OrderService orderService, BasketService basketService) { _orderService = orderService; _basketService = basketService; }