public void UpdateMealType_Should_Return_Null_If_No_Result_Found_In_Db() { //Arrange var mock = new Mock <IMealTypeRepository>(); var myMealType = new MealTypeDTO { Id = 1, Name = "Starter", Restaurant = new RestoDTO() }; mock.Setup(x => x.Update(myMealType)); MealTypeUC target = new MealTypeUC(mock.Object); //Act var result = target.UpdateMealType(new MealTypeBTO { Id = 1, Name = "Starter", Restaurant = new RestoBTO() }); //Assert Assert.IsNull(result); }
public void UpdateMealType_Should_Return_Valid_Data() { //Arrange var mock = new Mock <IMealTypeRepository>(); var myMealType = new MealTypeDTO { Id = 1, Name = "Starter", Restaurant = new RestoDTO() }; mock.Setup(x => x.Update(myMealType)).Returns( new MealTypeDTO { Id = 1, Name = "Starter", Restaurant = new RestoDTO() } ); MealTypeUC target = new MealTypeUC(mock.Object); //Act var result = target.UpdateMealType(new MealTypeBTO { Id = 1, Name = "Starter", Restaurant = new RestoBTO() }); //Assert mock.Verify(u => u.Update(It.IsAny <MealTypeDTO>()), Times.Once()); }
public IActionResult EditMealType(MealTypeBTO mealTypeBTO) { if (!ModelState.IsValid) { return(View(mealTypeBTO)); } var result = mealTypeUC.UpdateMealType(mealTypeBTO); int idToReturn = result.RestaurantId; if (result == null) { return(RedirectToAction("Error", new { errorMessage = "We can't update this meal type, please contact support" })); } return(RedirectToAction("GetAllMealTypesByRestoId", new { Id = idToReturn })); }