public async Task UpdateCake_WithdDuplicateImageUrl_ShouldNotUpdatedProduct() { //Arange var db = this.SetDb(); await this.SeedProducts(db); var repo = new Repository <Product>(db); var cakeService = new CakeService(null, repo, this.Mapper); var entity = repo.All().SingleOrDefault(p => p.Id == 1); db.Entry(entity).State = EntityState.Detached; var model = this.Mapper.Map <Product, EditAndDeleteViewModel>(entity); model.Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_Drip_cake.jpg"; //Act var result = await cakeService.UpdateCake(model); var actual = await cakeService.GetCakeById(1); string imageExpected = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136591/Chocolate_and_Peanut_cake.jpg"; string imageActual = actual.Image; //Assert Assert.Equal(imageExpected, imageActual); Assert.Equal("Product with such image url already exists.", result); }
public async Task UpdateCake_WithValidData_ShouldSaveUpdatedProductInDb() { //Arange var db = this.SetDb(); await this.SeedProducts(db); var repo = new Repository <Product>(db); var cakeService = new CakeService(null, repo, this.Mapper); var entity = repo.All().SingleOrDefault(p => p.Id == 1); db.Entry(entity).State = EntityState.Detached; entity.Price = 45.00m; //Act var result = await cakeService.UpdateCake(this.Mapper.Map <Product, EditAndDeleteViewModel>(entity)); var actual = await cakeService.GetCakeById(1); decimal price = actual.Price; //Assert Assert.Equal(45, price); }
public async Task UpdateCake_WithdDuplicateName_ShouldNotUpdatedProduct() { //Arange var db = this.SetDb(); await this.SeedProducts(db); var repo = new Repository <Product>(db); var cakeService = new CakeService(null, repo, this.Mapper); var entity = repo.All().SingleOrDefault(p => p.Id == 1); db.Entry(entity).State = EntityState.Detached; var model = this.Mapper.Map <Product, EditAndDeleteViewModel>(entity); model.Name = "Chocolate Drip Cake"; //Act var result = await cakeService.UpdateCake(model); var actual = await cakeService.GetCakeById(1); string name = actual.Name; //Assert Assert.Equal("Chocolate Peanut Cake", name); Assert.Equal("Product with such name already exists.", result); }
public static void Main(string[] args) { CakeFactory cakeFactory = new CakeFactory(); CakeService cakeService = new CakeService(); int num = 0; IList <Cake> cakes = cakeFactory.Cakes; string choice; do { Console.WriteLine("enter your choice:\n1.Add Cake\n2.Delete Cake\n3.Update Cake\n4.Search Cake\n5.Display Cakes\nEnter your choice:"); Console.WriteLine("==========================================================="); Console.WriteLine(); var input = Convert.ToInt32(Console.ReadLine()); if (input == 1) { Cake flavor = cakeService.AddCake(ref num, cakes); cakeFactory.Cakes.Add(flavor); Console.WriteLine("\nCake Added successfully\n"); cakeService.DisplayCakes(cakes); } else if (input == 3) { cakeService.UpdateCake(cakes); } else if (input == 5) { cakeService.DisplayCakes(cakes); } else if (input == 2) { cakeService.DeleteCake(cakes); } else if (input == 4) { cakeService.SearchCake(cakes); } else { Console.WriteLine("select the correct option"); } Console.WriteLine("\n==========================================================="); Console.WriteLine(); Console.WriteLine("if u want to continue press yes"); choice = Console.ReadLine(); } while (string.Compare(choice, "yes", true) == 0); Console.ReadLine(); }