public void AddShoppingCartProduct_WithExistentShoppingCartProductAndProductQuantityMoreThenOne_ShouldSuccessfullyIncreaseQuantity() { string errorMessagePrefix = "ShoppingCartsService AddShoppingCartProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int productId = context.Products.First().Id; ShoppingCartProduct testShoppingCartProduct = new ShoppingCartProduct { ProductId = productId, ShoppingCartId = user.ShoppingCartId, Quantity = 1 }; context.Add(testShoppingCartProduct); context.SaveChanges(); ShoppingCartProduct shoppingCartProduct = context.ShoppingCartProducts .First(s => s.ShoppingCartId == user.ShoppingCartId && s.ProductId == productId); int expectedCount = shoppingCartProduct.Quantity + 1; bool actualResult = this.shoppingCartsService.AddShoppingCartProduct(productId, user.UserName); int actualCount = shoppingCartProduct.Quantity; Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void CreateOrder_WithoutProductsInShoppingCart_ShouldReturnFalse() { string errorMessagePrefix = "OrdersService CreateOrder() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); ShoppingCartsService shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); this.orderService = new OrdersService(context, new UniShopUsersService(context), shoppingCartsService, new SuppliersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int supplierId = context.Suppliers.First().Id; int addressId = user.Addresses.First().Id; int expectedCount = user.Orders.Count(); bool actualResult = this.orderService.CreateOrder(user.UserName, supplierId, 1, addressId); int actualCount = user.Orders.Count(); Assert.False(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void AddFavoriteProduct_WithExistentSameFavoriteProduct_ShouldReturnFalse() { string errorMessagePrefix = "FavoriteProductsService AddFavoriteProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.favoriteProductsService = new FavoriteProductsService(context, new UniShopUsersService(context)); UniShopUser user = context.Users.First(); int productId = context.Products.First().Id; UniShopUserFavoriteProduct testFavoriteProduct = new UniShopUserFavoriteProduct { UniShopUserId = user.Id, ProductId = productId }; context.Add(testFavoriteProduct); context.SaveChanges(); int expectedCount = user.FavoriteProducts.Count(); bool actualResult = this.favoriteProductsService.AddFavoriteProduct(productId, user.UserName); int actualCount = user.FavoriteProducts.Count(); Assert.False(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void DeliverOrder_WithCorrectData_ShouldChangeOrderStatusToDelivered() { string errorMessagePrefix = "OrdersService DeliverOrder() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); ShoppingCartsService shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); this.orderService = new OrdersService(context, new UniShopUsersService(context), shoppingCartsService, new SuppliersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); Order order = new Order { OrderStatus = OrderStatus.Processed, UniShopUserId = user.Id, }; context.Add(order); context.SaveChanges(); OrderStatus expectedOrderStatus = OrderStatus.Delivered; bool actualResult = this.orderService.DeliverOrder(order.Id); OrderStatus actualOrderStatus = order.OrderStatus; Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedOrderStatus, actualOrderStatus); }
public void GetOrderByIdAndUserId_WithExistentId_ShouldReturnCorrectResults() { string errorMessagePrefix = "OrdersService GetOrderByIdAndUserId() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); ShoppingCartsService shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); this.orderService = new OrdersService(context, new UniShopUsersService(context), shoppingCartsService, new SuppliersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); Order order = new Order { OrderStatus = OrderStatus.Processed, UniShopUserId = user.Id, }; context.Add(order); context.SaveChanges(); OrderServiceModel expectedResults = user.Orders.First().To <OrderServiceModel>(); OrderServiceModel actualResults = this.orderService.GetOrderByIdAndUserId(expectedResults.Id, user.Id); Assert.True(expectedResults.Id == actualResults.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(expectedResults.OrderStatus == actualResults.OrderStatus, errorMessagePrefix + " " + "OrderStatus is not returned properly."); Assert.True(expectedResults.UniShopUserId == actualResults.UniShopUserId, errorMessagePrefix + " " + "UniShopUserId Count is not returned properly."); }
public void AddAddress_WithCorrectData_ShouldSuccessfullyCreate() { string errorMessagePrefix = "AddressesService AddAddress() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.addressesService = new AddressesService(context, new UniShopUsersService(context)); UniShopUser user = context.Users.First(); AddressServiceModel testAddress = new AddressServiceModel { City = "SofiqTestCraete", Street = "TesterCreate", BuildingNumber = "223" }; int expectedCount = user.Addresses.Count() + 1; bool actualResult = this.addressesService.AddAddress(testAddress, user.Id); int actualCount = user.Addresses.Count(); Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void RemoveShoppingCartProduct_WithCorrectData_ShouldSuccessfullyRemove() { string errorMessagePrefix = "ShoppingCartsService RemoveShoppingCartProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int productId = context.Products.First().Id; ShoppingCartProduct testShoppingCartProduct = new ShoppingCartProduct { ProductId = productId, ShoppingCartId = user.ShoppingCartId, Quantity = 2 }; context.Add(testShoppingCartProduct); context.SaveChanges(); int expectedCount = user.ShoppingCart.ShoppingCartProducts.Count() - 1; bool actualResult = this.shoppingCartsService.RemoveShoppingCartProduct(productId, user.UserName); int actualCount = user.ShoppingCart.ShoppingCartProducts.Count(); Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void ReduceQuantity_WithShoppingCartProductQuantityOne_ShouldReturnFalse() { string errorMessagePrefix = "ShoppingCartsService ReduceQuantity() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int productId = context.Products.Where(p => p.Quantity == 0).First().Id; ShoppingCartProduct testShoppingCartProduct = new ShoppingCartProduct { ProductId = productId, ShoppingCartId = user.ShoppingCartId, Quantity = 1 }; context.Add(testShoppingCartProduct); context.SaveChanges(); int expectedCount = testShoppingCartProduct.Quantity; bool actualResult = this.shoppingCartsService.ReduceQuantity(productId, user.UserName); int actualCount = testShoppingCartProduct.Quantity; Assert.False(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = "/Identity/Account/Login"; if (ModelState.IsValid) { var isRoot = !_userManager.Users.Any(); var user = new UniShopUser { UserName = Input.UserName, Email = Input.Email, FullName = Input.FullName, ShoppingCart = new ShoppingCart() }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); if (isRoot) { await _userManager.AddToRoleAsync(user, "Admin"); } else { await _userManager.AddToRoleAsync(user, "User"); } #region Email Func //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Page( // "/Account/ConfirmEmail", // pageHandler: null, // values: new { userId = user.Id, code = code }, // protocol: Request.Scheme); //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", // $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); //await _signInManager.SignInAsync(user, isPersistent: false); #endregion return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public void GetAddressesByUserName_WithNonExistentUser_ShouldReturnEmptyResults() { var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.addressesService = new AddressesService(context, new UniShopUsersService(context)); UniShopUser user = context.Users.Last(); List <AddressServiceModel> actualResults = this.addressesService.GetAddressesByUserName(user.UserName + "Test").ToList(); int expectedResults = 0; Assert.Equal(expectedResults, actualResults.Count()); }
public void GetAddressesByUserName_WithDummyData_ShouldReturnCorrectResults() { var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.addressesService = new AddressesService(context, new UniShopUsersService(context)); UniShopUser user = context.Users.First(); List <AddressServiceModel> actualResults = this.addressesService.GetAddressesByUserName(user.UserName).ToList(); int expectedResults = user.Addresses.Count(); Assert.Equal(expectedResults, actualResults.Count()); }
public void RemoveFavoriteProduct_WithNonExistentProduct_ShouldSuccessfullyCreate() { string errorMessagePrefix = "FavoriteProductsService RemoveFavoriteProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.favoriteProductsService = new FavoriteProductsService(context, new UniShopUsersService(context)); UniShopUser user = context.Users.First(); int productId = context.Products.Last().Id + 1; bool actualResult = this.favoriteProductsService.RemoveFavoriteProduct(productId, user.UserName); Assert.False(actualResult, errorMessagePrefix); }
public void CheckIsInStockShoppingCartProducts_WithNonExistentProductQuantity_ShouldReturnFalse() { string errorMessagePrefix = "ProductsService ReduceProductQuantity() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.productsService = new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context))); Product firstProduct = context.Products.First(); Product secondProduct = context.Products.Last(); UniShopUser user = new UniShopUser { UserName = "******", ShoppingCart = new ShoppingCart { } }; context.Add(user); List <ShoppingCartProduct> testshoppingProducts = new List <ShoppingCartProduct> { new ShoppingCartProduct { ShoppingCart = user.ShoppingCart, Product = firstProduct, Quantity = 1, }, new ShoppingCartProduct { ShoppingCart = user.ShoppingCart, Product = secondProduct, Quantity = 10 } }; context.AddRange(testshoppingProducts); context.SaveChanges(); List <ShoppingCartProductServiceModel> shoppingCartProducts = testshoppingProducts .To <ShoppingCartProductServiceModel>().ToList(); bool actualResult = this.productsService.CheckIsInStockShoppingCartProducts(shoppingCartProducts); Assert.False(actualResult, errorMessagePrefix); }
public void GetAllShoppingCartProducts_WithNonExistentUser_ShouldReturnEmptyResults() { var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); List <ShoppingCartProductServiceModel> actualResults = this.shoppingCartsService .GetAllShoppingCartProducts(user.UserName).ToList(); int expectedResults = 0; Assert.Equal(expectedResults, actualResults.Count()); }
public void RemoveShoppingCartProduct_WithNonExistentShoppingCartProduct_ShouldReturnFalse() { string errorMessagePrefix = "ShoppingCartsService RemoveShoppingCartProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int productId = context.Products.First().Id; bool actualResult = this.shoppingCartsService.RemoveShoppingCartProduct(productId, user.UserName); Assert.False(actualResult, errorMessagePrefix); }
public void AddFavoriteProduct_WithCorrectData_ShouldSuccessfullyCreate() { string errorMessagePrefix = "FavoriteProductsService AddFavoriteProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.favoriteProductsService = new FavoriteProductsService(context, new UniShopUsersService(context)); UniShopUser user = context.Users.First(); int productId = context.Products.First().Id; int expectedCount = user.FavoriteProducts.Count() + 1; bool actualResult = this.favoriteProductsService.AddFavoriteProduct(productId, user.UserName); int actualCount = user.FavoriteProducts.Count(); Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void AddShoppingCartProduct_WithProductQuantityZero_ShouldReturnFalse() { string errorMessagePrefix = "ShoppingCartsService AddShoppingCartProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int productId = context.Products.Where(p => p.Quantity == 0).First().Id; int expectedCount = user.ShoppingCart.ShoppingCartProducts.Count(); bool actualResult = this.shoppingCartsService.AddShoppingCartProduct(productId, user.UserName); int actualCount = user.ShoppingCart.ShoppingCartProducts.Count(); Assert.False(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void GetAllUnprocessedOrders_WithDummyData_ShouldReturnCorrectResults() { var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); ShoppingCartsService shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); this.orderService = new OrdersService(context, new UniShopUsersService(context), shoppingCartsService, new SuppliersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); List <Order> orders = new List <Order> { new Order { OrderStatus = OrderStatus.Unprocessed, UniShopUserId = user.Id, }, new Order { OrderStatus = OrderStatus.Unprocessed, UniShopUserId = user.Id, } }; context.AddRange(orders); context.SaveChanges(); List <OrderServiceModel> actualResults = this.orderService .GetAllUnprocessedOrders().ToList(); int expectedResults = 2; Assert.Equal(expectedResults, actualResults.Count()); }
public void GetOrderByIdAndUserId_WithNonExistentOrder_ShouldReturnNull() { string errorMessagePrefix = "OrdersService GetOrderByIdAndUserId() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); UniShopUser user = context.Users.First(); ShoppingCartsService shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); this.orderService = new OrdersService(context, new UniShopUsersService(context), shoppingCartsService, new SuppliersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); int nonExistentId = 1000; OrderServiceModel actualResults = this.orderService.GetOrderByIdAndUserId(nonExistentId, user.Id); Assert.True(actualResults == null, errorMessagePrefix); }
public void RemoveFavoriteProduct_WithCorrectData_ShouldSuccessfullyCreate() { string errorMessagePrefix = "FavoriteProductsService RemoveFavoriteProduct() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.favoriteProductsService = new FavoriteProductsService(context, new UniShopUsersService(context)); UniShopUser user = context.Users.First(); int firstProductId = context.Products.First().Id; int secondProductId = context.Products.Last().Id; List <UniShopUserFavoriteProduct> testfavoriteProducts = new List <UniShopUserFavoriteProduct> { new UniShopUserFavoriteProduct { UniShopUserId = user.Id, ProductId = firstProductId }, new UniShopUserFavoriteProduct { UniShopUserId = user.Id, ProductId = secondProductId } }; context.AddRange(testfavoriteProducts); context.SaveChanges(); int expectedCount = user.FavoriteProducts.Count() - 1; bool actualResult = this.favoriteProductsService.RemoveFavoriteProduct(firstProductId, user.UserName); int actualCount = user.FavoriteProducts.Count(); Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void GetAllShoppingCartProducts_WithDummyData_ShouldReturnCorrectResults() { var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int firstProductId = context.Products.First().Id; int secondProductId = context.Products.Last().Id; List <ShoppingCartProduct> testshoppingProducts = new List <ShoppingCartProduct> { new ShoppingCartProduct { ShoppingCartId = user.ShoppingCartId, ProductId = firstProductId, Quantity = 1 }, new ShoppingCartProduct { ShoppingCartId = user.ShoppingCartId, ProductId = secondProductId, Quantity = 1 } }; context.AddRange(testshoppingProducts); context.SaveChanges(); List <ShoppingCartProductServiceModel> actualResults = this.shoppingCartsService .GetAllShoppingCartProducts(user.UserName).ToList(); int expectedResults = 2; Assert.Equal(expectedResults, actualResults.Count()); }
public void CreateOrder_WithCorrectData_ShouldSuccessfullyCreate() { string errorMessagePrefix = "OrdersService CreateOrder() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); ShoppingCartsService shoppingCartsService = new ShoppingCartsService(context, new UniShopUsersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); this.orderService = new OrdersService(context, new UniShopUsersService(context), shoppingCartsService, new SuppliersService(context), new ProductsService(context, new ChildCategoriesService(context, new ParentCategoriesService(context)))); UniShopUser user = context.Users.First(); int productId = context.Products.First().Id; int supplierId = context.Suppliers.First().Id; int addressId = user.Addresses.First().Id; ShoppingCartProduct testShoppingCartProduct = new ShoppingCartProduct { ProductId = productId, ShoppingCartId = user.ShoppingCartId, Quantity = 1 }; context.Add(testShoppingCartProduct); context.SaveChanges(); int expectedCount = user.Orders.Count() + 1; bool actualResult = this.orderService.CreateOrder(user.UserName, supplierId, 1, addressId); int actualCount = user.Orders.Count(); Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }