public void CreateMealType_Should_Return_Null_If_Dto_Is_Null() { //Arrange var mock = new Mock <IMealTypeRepository>(); var myMealType = new MealTypeDTO { Id = 1, Name = "Starter", Restaurant = new RestoDTO() }; mock.Setup(x => x.Create(myMealType)).Returns( new MealTypeDTO { Id = 1, Name = "Starter", Restaurant = new RestoDTO() } ); MealTypeUC target = new MealTypeUC(mock.Object); //Act var result = target.AddMealType(null); //Assert Assert.IsNull(result); }
public void CreateMealType_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.Create(myMealType)).Returns( new MealTypeDTO { Id = 1, Name = "Starter", Restaurant = new RestoDTO() } ); MealTypeUC target = new MealTypeUC(mock.Object); //Act var result = target.AddMealType(new MealTypeBTO { Id = 1, Name = "Starter", Restaurant = new RestoBTO() }); //Assert mock.Verify(u => u.Create(It.IsAny <MealTypeDTO>()), Times.Once()); }
public IActionResult CreateMealType(MealTypeBTO mealTypeBTO) { int idToReturn = mealTypeBTO.Restaurant.Id; if (!ModelState.IsValid) { return(View(mealTypeBTO)); } var result = mealTypeUC.AddMealType(mealTypeBTO); if (result == null) { return(RedirectToAction("Error", new { errorMessage = "We can't add this meal type, please contact support" })); } return(RedirectToAction("GetAllMealTypesByRestoId", new { Id = idToReturn })); }