public async Task SoftDelete_WithInValidCustomCakeId_ShouldMarkCakeAsDeleted() { //Assert var db = this.SetDb(); var repo = new Repository <CustomCakeImg>(db); var mock = new Mock <ILogger <CustomCakeService> >(); ILogger <CustomCakeService> logger = mock.Object; var productRepo = new Repository <Product>(db); var productService = new CakeService(null, productRepo, this.Mapper); var service = new CustomCakeService(productRepo, repo, this.Mapper, logger); CustomCakeOrderViewModel model = new CustomCakeOrderViewModel { Sponge = "Vanilla", FirstLayerCream = "Whipped", SecondLayerCream = "Whipped", Filling = "No_Filling", SideDecoration = "White_Chocolate_Cigarettes", TopDecoration = "Habana", NumberOfSlices = 6, Img = null, }; var product = service.CreateCustomProduct(model); await productService.AddCakeToDb(product); //Act //Assert await Assert.ThrowsAsync <InvalidOperationException>(async() => await productService.SoftDelete(2)); }
public async Task GetAllCakes_ShouldReturnAllCakesDeletedAndNot() { //Arrange var db = this.SetDb(); var repo = new Repository <Product>(db); var cakeModel1 = new CreateCakeViewModel { Name = "Chocolate Peanut Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136591/Chocolate_and_Peanut_cake.jpg" }; var cakeModel2 = new CreateCakeViewModel { Name = "Chocolate Drip Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_Drip_cake.jpg" }; var cakeService = new CakeService(null, repo, this.Mapper); await cakeService.AddCakeToDb(cakeModel1); await cakeService.AddCakeToDb(cakeModel2); var deleteCake = await repo.GetByIdAsync(1); deleteCake.IsDeleted = true; deleteCake.Category = new Category { Id = 1, Type = Models.Enums.CategoryType.Cake }; var activeCake = await repo.GetByIdAsync(2); activeCake.Category = new Category { Id = 1, Type = Models.Enums.CategoryType.Cake }; await repo.SaveChangesAsync(); //Act var allActiveCakes = cakeService.GetAllCakes(); var expectedCakesCount = 2; var actualCakesCount = allActiveCakes.Count(); //Assert Assert.Equal(expectedCakesCount, actualCakesCount); }
public async Task AddCakeToDb_WithDuplicateCake_ShouldThrow() { //Arrange var db = this.SetDb(); var repo = new Repository <Product>(db); var cakeModel1 = new CreateCakeViewModel { Name = "Chocolate Peanut Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_and_Peanut_cake.jpg" }; var cakeModel2 = new CreateCakeViewModel { Name = "Chocolate Peanut Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_and_Peanut_cake.jpg" }; var cakeService = new CakeService(null, repo, this.Mapper); //Act await cakeService.AddCakeToDb(cakeModel1); //Assert await Assert.ThrowsAsync <InvalidOperationException>(async() => await cakeService.AddCakeToDb(cakeModel2)); }
private async Task SeedProducts(CakeItDbContext db) { var repo = new Repository <Product>(db); var cakeModel1 = new CreateCakeViewModel { Name = "Chocolate Peanut Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136591/Chocolate_and_Peanut_cake.jpg" }; var cakeModel2 = new CreateCakeViewModel { Name = "Chocolate Drip Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_Drip_cake.jpg" }; var cakeService = new CakeService(null, repo, this.Mapper); await cakeService.AddCakeToDb(cakeModel1); await cakeService.AddCakeToDb(cakeModel2); await repo.SaveChangesAsync(); //It works without SaveCanges()??? }
public async Task RemoveFromCart_WithItemCategoryTwo_ShouldReturnEmptyCart() { //Arrange var db = this.SetDb(); var repo = new Repository <CustomCakeImg>(db); var productRepo = new Repository <Product>(db); var productService = new CakeService(null, productRepo, this.Mapper); var customCakeService = new CustomCakeService(productRepo, repo, this.Mapper, null); var wrapper = new TestCartSessionWrapper(); var cartManager = new CartManager(wrapper); var cartService = new CartService(productRepo, cartManager); CustomCakeOrderViewModel model = new CustomCakeOrderViewModel { Sponge = "Vanilla", FirstLayerCream = "Whipped", SecondLayerCream = "Whipped", Filling = "No_Filling", SideDecoration = "White_Chocolate_Cigarettes", TopDecoration = "Habana", NumberOfSlices = 6, Img = null, }; var product = customCakeService.CreateCustomProduct(model); await productService.AddCakeToDb(product); await cartService.AddToCart(1); //Act await cartService.RemoveFromCart(1); //Assert Assert.Empty(cartManager.GetCartItem()); }
public async Task SoftDelete_WithValidCustomCakeId_ShouldMarkCakeAsDeleted() { //Assert var db = this.SetDb(); var repo = new Repository <CustomCakeImg>(db); var mock = new Mock <ILogger <CustomCakeService> >(); ILogger <CustomCakeService> logger = mock.Object; var productRepo = new Repository <Product>(db); var productService = new CakeService(null, productRepo, this.Mapper); var service = new CustomCakeService(productRepo, repo, this.Mapper, logger); CustomCakeOrderViewModel model = new CustomCakeOrderViewModel { Sponge = "Vanilla", FirstLayerCream = "Whipped", SecondLayerCream = "Whipped", Filling = "No_Filling", SideDecoration = "White_Chocolate_Cigarettes", TopDecoration = "Habana", NumberOfSlices = 6, Img = null, }; var product = service.CreateCustomProduct(model); await productService.AddCakeToDb(product); //Act await productService.SoftDelete(1); var expectedIsDeleted = true; var actualIsDeleted = (await productRepo.GetByIdAsync(1)).IsDeleted; //Assert Assert.Equal(expectedIsDeleted, actualIsDeleted); }
public async Task AddCakeToDb_WithValidCake_ShouldReturnTrue() { //Arrange var db = this.SetDb(); var repo = new Repository <Product>(db); var cakeModel = new CreateCakeViewModel { Name = "Chocolate Peanut Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_and_Peanut_cake.jpg" }; var cakeService = new CakeService(null, repo, this.Mapper); //Act await cakeService.AddCakeToDb(cakeModel); //works with and without SaveChanges()???? await repo.SaveChangesAsync(); var actualName = repo.All().LastOrDefault().Name; //Assert Assert.Equal("Chocolate Peanut Cake", actualName); }