public IActionResult CreateRestaurant(RestoBTO restoBTO) { var count = restoBTO.Cuisines.Count(x => x.Selected); if (!ModelState.IsValid) { return(View(restoBTO)); } restoBTO.Cuisines = restoBTO.Cuisines.Where(x => x.Selected).ToList(); var restaurantUC = new RestaurantUC(restoRepository); if (restoBTO.UserManagerId == null) { restoBTO.UserManagerId = User.FindFirst(ClaimTypes.NameIdentifier).Value; } var result = restaurantUC.AddRestaurant(restoBTO); if (result == null) { return(RedirectToAction("Error", new { errorMessage = "We can't add this restaurant, please contact support" })); } if (User.IsInRole("Administrators")) { return(RedirectToAction("GetAllRestaurantsAdmin")); } else { return(RedirectToAction("GetRestaurantsByRestaurantManager")); } }
public void CreateRestaurant_Should_Return_Null_If_Dto_Is_Null() { //Arrange var mock = new Mock <IRestoRepository>(); var myResto = new RestoDTO { City = "Bruxelles", Id = 1, Name = "R1" }; mock.Setup(x => x.Create(myResto)).Returns( new RestoDTO { City = "Bruxelles", Id = 1, Name = "R1" } ); RestaurantUC target = new RestaurantUC(mock.Object); //Act var result = target.AddRestaurant(null); //Assert Assert.IsNull(result); }
public void CreateRestaurant_Should_Return_Valid_Data() { //Arrange var mock = new Mock <IRestoRepository>(); var myResto = new RestoDTO { City = "Bruxelles", Id = 1, Name = "R1" }; mock.Setup(x => x.Create(myResto)).Returns( new RestoDTO { City = "Bruxelles", Id = 1, Name = "R1" } ); RestaurantUC target = new RestaurantUC(mock.Object); //Act var result = target.AddRestaurant(new RestoBTO { City = "Bruxelles", Id = 1, Name = "R1" }); //Assert mock.Verify(u => u.Create(It.IsAny <RestoDTO>()), Times.Once()); }