public async Task GetCartItems_WhenCalled_ReturnsAllCartItems() { //Arrange var myDbContextMoq = new DbContextMock <ShoppingCartContext>(myDummyOptions); //Create list of CartItems myDbContextMoq.CreateDbSetMock(x => x.CartItems, new[] { new CartItem { ProductId = 1, Price = 3, Quantity = 2 }, new CartItem { ProductId = 2, Price = 2, Quantity = 5 }, new CartItem { ProductId = 3, Price = 21, Quantity = 1 } }); //Act //Pass myDbContextMoq.Object to the CartItemService class CartItemService service = new CartItemService(myDbContextMoq.Object); //Call GetAllCartItems() function var result = await service.GetAllCartItems(); //Assert Assert.NotNull(result); }
public SubcategoryViewModel() { Categories = new ObservableCollection <Category>(); GetCategories(); var uname = Preferences.Get("Username", String.Empty); if (String.IsNullOrEmpty(uname)) { Username = "******"; } else { Username = uname; } UserCartItemsCount = new CartItemService().GetUserCartCount(); ViewCartCommand = new Command(async() => await ViewCartAsync()); LogoutCommand = new Command(async() => await LogoutAsync()); GetCategories(); OrdersHistoryCommand = new Command(async() => await OrdersHistoryAsync()); SearchViewCommand = new Command(async() => await SearchViewAsync()); }
public async Task CreateCartItem_AddsNewProductToCartItemsTable() { //Arrange var myDbContextMoq = new DbContextMock <ShoppingCartContext>(myDummyOptions); //Create list of CartItems that contains only two Products myDbContextMoq.CreateDbSetMock(x => x.CartItems, new[] { new CartItem { ProductId = 1, Price = 3, Quantity = 2 }, new CartItem { ProductId = 2, Price = 2, Quantity = 5 } }); //We want to add third product to our list of CartItems //Since CreateCartItem() method accepts type CartItemDTO we use that type here for our new CartItem CartItemDTO testDataDTO = new CartItemDTO() { ProductId = 3, Price = 21, Quantity = 1 }; CartItemService service = new CartItemService(myDbContextMoq.Object); //Act await service.CreateCartItem(testDataDTO);//call CreateCartItem() function and pass the testDataDTO //Assert //The size of the CartItems list increases to 3 because CreateCartItem() method added testDataDTO Assert.Equal(3, myDbContextMoq.Object.CartItems.Count()); }
public ProductsViewModel() { var uname = Preferences.Get("Username", String.Empty); if (string.IsNullOrEmpty(uname)) { Username = "******"; } else { Username = uname; } UserCartItemsCount = new CartItemService().GetUserCartCount(); Categories = new ObservableCollection <Category>(); LatestItems = new ObservableCollection <FoodItem>(); GetCategoriesAsync(); GetLatestItems(); ViewCartCommand = new Command(async() => await ViewCartAsync()); LogoutCommand = new Command(async() => await LogoutAsync()); OrdersHistoryCommand = new Command(async() => await OrdersHistoryAsync()); SearchViewCommand = new Command(async() => await SearchViewAsync()); }
public async Task UpdateCartItem_EditsTheCartItem_AndAddsTheUpdatedCartItemToCartItemsTable() { //Arrange var myDbContextMoq = new DbContextMock <ShoppingCartContext>(myDummyOptions); //Create list of CartItems that contains only two Products myDbContextMoq.CreateDbSetMock(x => x.CartItems, new[] { new CartItem { ProductId = 1, Price = 3, Quantity = 2 }, new CartItem { ProductId = 2, Price = 2, Quantity = 5 } }); CartItemDTO testDataDTO = new CartItemDTO() { ProductId = 1, Price = 3, Quantity = 4 //we updated the Quantity }; CartItemService service = new CartItemService(myDbContextMoq.Object); //Act //for example we want to update first CartItem await service.UpdateCartItem(testDataDTO); CartItem cartItmeToBeUpdated = myDbContextMoq.Object.CartItems.FirstOrDefault(x => x.ProductId == 1); //Assert //Quantity changed from 2 to 4 Assert.Equal(4, cartItmeToBeUpdated.Quantity); }
public async Task DeleteCartItem_RemovesThatCartItemFromCartItemsTable() { //Arrange var myDbContextMoq = new DbContextMock <ShoppingCartContext>(myDummyOptions); //Create list of CartItems that contains only two Products myDbContextMoq.CreateDbSetMock(x => x.CartItems, new[] { new CartItem { ProductId = 1, Price = 3, Quantity = 2 }, new CartItem { ProductId = 2, Price = 2, Quantity = 5 } }); CartItemService service = new CartItemService(myDbContextMoq.Object); //Act //for example we want to delete first CartItem await service.DeleteCartItem(1);//remove first CartItem //Assert //removing the first CartItem causes that our list size becomes 1 Assert.Equal(1, myDbContextMoq.Object.CartItems.Count()); }
public void GetCartItem_WhenExistingProductIdPassed_ReturnsRightCartItem() { //Arrange var myDbContextMoq = new DbContextMock <ShoppingCartContext>(myDummyOptions); myDbContextMoq.CreateDbSetMock(x => x.CartItems, new[] { new CartItem { ProductId = 1, Price = 3, Quantity = 2 }, new CartItem { ProductId = 2, Price = 2, Quantity = 5 } }); CartItemService service = new CartItemService(myDbContextMoq.Object); //Act var result1 = service.GetCartItem(1); var result2 = service.GetCartItem(2); //Assert Assert.Equal(2, result1.Quantity); Assert.Equal(5, result2.Quantity); }
private async Task LogoutUserAsync() { var cis = new CartItemService(); cis.RemoveItemsFromCart(); Preferences.Remove("Username"); await Application.Current.MainPage.Navigation.PushModalAsync(new LoginView()); }
public LogoutViewModel() { UserCartItemsCount = new CartItemService().GetUserCartCount(); IsCartExists = (UserCartItemsCount > 0) ? true : false; LogoutCommand = new Command(async() => await LogoutUserAsync()); GotoCartCommand = new Command(async() => await GotoCartAsync()); }
public void GetItemPrice_Margherita_Extra_Ingredient_Returns_Correct_Price() { //Arrange var price = 89; var extraIngredientPrice = 10; var item = new CartItem { CartItemId = 1, DishId = 1, Price = price, CartId = Guid.NewGuid(), Quantity = 1, CartItemIngredients = new List <CartItemIngredient> { new CartItemIngredient { CartItemId = 1, IngredientName = "Cheese", IsOriginalIngredient = true, Price = 0 }, new CartItemIngredient { CartItemId = 1, IngredientName = "Tomato Sauce", IsOriginalIngredient = true, Price = 0 }, new CartItemIngredient { CartItemId = 1, IngredientName = "Ham", IsOriginalIngredient = false, Price = extraIngredientPrice } } }; var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("Test") .Options; var dbContext = new ApplicationDbContext(dbOptions); var cartItemService = new CartItemService(dbContext); //Act var result = cartItemService.GetItemPrice(item); //Assert Assert.Equal(result, price + extraIngredientPrice); }
public ProductsViewModel() { var uname = Preferences.Get("Username", String.Empty); if (String.IsNullOrEmpty(uname)) { UserName = "******"; } else { UserName = uname; } UserCartItemsCount = new CartItemService().GetUserCartCount(); Categories = new ObservableCollection <Category>(); ViewCartCommand = new Command(async() => await ViewCartAsync()); LogoutCommand = new Command(async() => await LogoutAsync()); GetCategories(); }
public ActionResult SendOrder() { var cart = ShoppingCart.Instance; var checkout = Request.Form["checkout"]; string Address = Request.Form["address"]; string Email = ""; string Fullname = Request.Form["first_name"] + " " + Request.Form["last_name"]; int OrderID; string OrderID_Insert = CartService.Insert(Address, Email, Fullname, cart.Items.Count(), cart.SubTotal); bool isNumerical = int.TryParse(OrderID_Insert, out OrderID); if (isNumerical) { List <ProductModels> ProductsAdded = new List <ProductModels>(); foreach (CartItem item in cart.Items) { CartItemService.Insert(OrderID, item.ProductItem.Id, item.ProductItem.Name, item.TotalPrice, item.Quantity); ProductModels product = new ProductModels(); product.Id = item.ProductItem.Id; product.Name = item.ProductItem.Name; product.Price = item.ProductItem.Price; product.SaleOff = item.ProductItem.SaleOff; ProductsAdded.Add(product); } if (ProductsAdded.Count() > 0) { foreach (var product in ProductsAdded) { cart.RemoveItem(product); } } } return(RedirectToAction("Index", "Home")); }
public LineItemController(CartItemService cartItemService, OrdersService ordersService, CustomerService customerService) { this.cartItemService = cartItemService; this.ordersService = ordersService; this.customerService = customerService; }
public JsonResult GetPriceListItemsByPriceLists(List <PriceList> priceLists) { var cartItems = CartItemService.QueryPriceListItemsByPriceLists(GetHttpClient(), priceLists); return(Json(cartItems, JsonRequestBehavior.AllowGet)); }
public CartItemController(IConfiguration configuration) { this.connectionString = configuration.GetConnectionString("ConnectionString"); this.cartItemService = new CartItemService(new CartItemRepository(connectionString)); }
public CartController(ApplicationDbContext context, ICartService cartService, CartItemService cartItemService) { _context = context; _cartService = cartService; _cartItemService = cartItemService; }
private void RemoveItemsFromCart() { var cis = new CartItemService(); cis.RemoveItemsFromCart(); }
/******************************/ public JsonResult GetCartItemsByInspection(Guid inspectionId, List <PriceList> priceLists) { var cartItems = CartItemService.QueryCartItemByInspection(GetHttpClient(), inspectionId, priceLists); return(Json(cartItems, JsonRequestBehavior.AllowGet)); }
public CartItemController(CartItemService cartItemService, CustomerService customerService) { this.cartItemService = cartItemService; this.customerService = customerService; }