public IActionResult CreateCuisine(CuisineBTO cuisineBTO) { if (!ModelState.IsValid) { return(View(cuisineBTO)); } var result = cuisineUC.AddCuisine(cuisineBTO); if (result == null) { return(RedirectToAction("Error", new { errorMessage = "We can't add this cuisine, please contact support" })); } return(RedirectToAction("GetAllCuisines")); }
public void CreateCuisine_Should_Return_Null_If_Dto_Is_Null() { //Arrange var mock = new Mock <ICuisineRepository>(); var myCuisine = new CuisineDTO { Id = 1, Name = "Japonais" }; mock.Setup(x => x.Create(myCuisine)).Returns( new CuisineDTO { Id = 1, Name = "Japonais" } ); CuisineUC target = new CuisineUC(mock.Object); //Act var result = target.AddCuisine(null); //Assert Assert.IsNull(result); }
public void CreateCuisine_Should_Return_Valid_Data() { //Arrange var mock = new Mock <ICuisineRepository>(); var myCuisine = new CuisineDTO { Id = 1, Name = "Japonais" }; mock.Setup(x => x.Create(myCuisine)).Returns( new CuisineDTO { Id = 1, Name = "Japonais" } ); CuisineUC target = new CuisineUC(mock.Object); //Act var result = target.AddCuisine(new CuisineBTO { Id = 1, Name = "Japonais" }); //Assert mock.Verify(u => u.Create(It.IsAny <CuisineDTO>()), Times.Once()); }