public void FindAllCategoriesShouldReturnOnlyCategoriesWhereIsDeletedIsFalse() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"FindAllCategoriesShouldReturnOnlyCategoriesWhereIsDeletedIsFalse_Category_Database") .Options; var dbContext = new ApplicationDbContext(options); var mapper = this.SetUpAutoMapper(); var categoriesService = new CategoriesService(dbContext, mapper); var categoryName = Guid.NewGuid().ToString(); var categoryName1 = Guid.NewGuid().ToString(); var categoryName2 = Guid.NewGuid().ToString(); var model = new CreateCategoryBindingModel { Name = categoryName }; var model1 = new CreateCategoryBindingModel { Name = categoryName1 }; var model2 = new CreateCategoryBindingModel { Name = categoryName2 }; categoriesService.CreateCategory(model); categoriesService.CreateCategory(model1); categoriesService.CreateCategory(model2); categoriesService.RemoveCategory(model); categoriesService.RemoveCategory(model1); var categories = categoriesService.FindAllCategories(); Assert.True(categories.Count == 1); }
public void CreateBrandCategoryViewModelByCategoriesAndBrandsShouldCreateBrandCategoryViewModelByCategoriesAndBrands() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"CreateBrandCategoryViewModelByCategoriesAndBrandsShouldCreateBrandCategoryViewModelByCategoriesAndBrands_Brand_Database") .Options; var dbContext = new ApplicationDbContext(options); var mapper = this.SetUpAutoMapper(); var brandService = new BrandsService(dbContext, mapper); var categoriesService = new CategoriesService(dbContext, mapper); this.SeedDbWithCategories(dbContext); this.SeeDbdWithBrands(dbContext); var brands = brandService.FindAllBrands(); var categories = categoriesService.FindAllCategories(); var model = new CategoryBrandViewModel { Brands = brands, Categories = categories }; Assert.True(model.Brands.Count == 3 && model.Categories.Count == 3); }
public void FindAllCategoriesShouldReturnAllCategories() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"FindAllCategoriesShouldReturnAllCategories_Category_Database") .Options; var dbContext = new ApplicationDbContext(options); var mapper = this.SetUpAutoMapper(); var categoriesService = new CategoriesService(dbContext, mapper); this.SeeDbdWithCategories(dbContext); var categories = categoriesService.FindAllCategories(); Assert.True(categories.Count == 3); }
public void FindAllUserOrdersShouldReturnAllUserOrders() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"FindAllUserOrdersShouldReturnAllUserOrders_Orders_Database") .Options; var dbContext = new ApplicationDbContext(options); var mapper = this.SetUpAutoMapper(); var brandService = new BrandsService(dbContext, mapper); var categoriesService = new CategoriesService(dbContext, mapper); var usersService = new UsersService(dbContext, mapper); var productsService = new ProductsService(dbContext, mapper); var shoppingCartsService = new ShoppingCartsService(dbContext, productsService, usersService, mapper); var ordersService = new OrdersService(dbContext, shoppingCartsService, mapper); var favouritesService = new FavouritesService(dbContext, productsService, usersService, mapper); this.SeeDbdWithBrands(dbContext); this.SeedDbWithCategories(dbContext); var brands = brandService.FindAllBrands(); var categories = categoriesService.FindAllCategories(); var image = new Mock <IFormFile>(); this.SeedDbWithCountries(dbContext); this.SeedDbWithUserAndProduct(dbContext, productsService, mapper.Map <Category>(categories[0]), mapper.Map <Brand>(brands[0]), image.Object); var user = dbContext.Users.FirstOrDefault(x => x.UserName == "1"); var products = productsService.FindAllProducts(); var shoppingCarts = dbContext.ShoppingCarts; var shoppingCartss = dbContext.ShoppingCartProducts; var cart = this.SeedDbShoppingCartWithProducts(dbContext, user.UserName, products[0].Id); var model = this.CreateOrderCreateBindingModel(); var orderId = ordersService.CreateOrder(model, mapper.Map <ApplicationUserDTO>(user)); var orders = ordersService.FindAllUserOrders(mapper.Map <ApplicationUserDTO>(user)); Assert.True(orders.Count == 1); }