public void TestAddSportEventGetViewThatContainsListOfSports() { //Arrange var sports = new[] { new Sport { Name = "Voetbal" }, new Sport { Name = "Basketbal" }, new Sport { Name = "Hockey" }, new Sport { Name = "Volleybal" } }; var addSportEventViewModel = new AddSportEventViewModel { Sports = sports, AddReservation = false }; var mockSportManager = new Mock <ISportManager>(); var mockSportEventManager = new Mock <ISportEventManager>(); var controller = new SportEventController(mockSportEventManager.Object, mockSportManager.Object); mockSportManager.Setup(sm => sm.SportsList()).Returns(sports); //Act var result = controller.Add(); var viewModel = (AddSportEventViewModel)result.Model; //Assert Assert.IsType(typeof(ViewResult), result); Assert.Equal(4, viewModel.Sports.Count()); }
public void TestAddModelInvalidSportEventReturnsAddViewWithErrorMessage() { //Arrange var dummySportEvent = new SportEvent { Name = "Voetbaltoernooi", Description = "Potje voetballen voor de starters", MaxAttendees = 5, MinAttendees = 20, SportId = 2, EventStartTime = DateTime.Today.AddHours(11), EventEndTime = DateTime.Today.AddHours(13) }; var addSportEventViewModel = new AddSportEventViewModel { SportEvent = dummySportEvent, AddReservation = false }; var mockSportManager = new Mock <ISportManager>(); var mockSportEventManager = new Mock <ISportEventManager>(); var mockTempData = new Mock <ITempDataDictionary>(); var controller = new SportEventController(mockSportEventManager.Object, mockSportManager.Object) { TempData = mockTempData.Object }; controller.ModelState.AddModelError("key", "error message"); //Act var result = controller.Add(addSportEventViewModel) as ViewResult; //Assert Assert.IsType(typeof(ViewResult), result); }
public void TestAddSportEventReturnsToAddMethodInReservationControllerAction() { //Arrange var dummySportEvent = new SportEvent { Name = "Voetbaltoernooi", Description = "Potje voetballen voor de starters", MaxAttendees = 30, MinAttendees = 22, SportId = 2, EventStartTime = DateTime.Today.AddHours(11), EventEndTime = DateTime.Today.AddHours(13) }; var addSportEventViewModel = new AddSportEventViewModel { SportEvent = dummySportEvent, AddReservation = true }; var mockSportManager = new Mock <ISportManager>(); var mockSportEventManager = new Mock <ISportEventManager>(); var mockTempData = new Mock <ITempDataDictionary>(); var controller = new SportEventController(mockSportEventManager.Object, mockSportManager.Object) { TempData = mockTempData.Object }; mockSportEventManager.Setup(x => x.AddSportEvent(It.IsAny <SportEvent>())).Returns(true); //Act var result = controller.Add(addSportEventViewModel) as RedirectToActionResult; //Assert Assert.IsType(typeof(RedirectToActionResult), result); Assert.Same("Index", result.ActionName); }