public void AfterCreateReturnToIndex() { // Arrange var list = new List <Players.Models.Match> { match1 }; var mockedService = new Mock <IMatchRepository>(); mockedService.Setup(m => m.GetAllMatches()).Returns(list); MatchController controller = new MatchController(mockedService.Object); // Act var result = controller.Create(match1); var redirectResult = (ActionResult)result; // Assert Assert.IsInstanceOfType(redirectResult, typeof(RedirectToRouteResult)); }
public void CreateMatchWithWrongData() { // Arrange var list = new List <Players.Models.Match> { match1 }; var mockedService = new Mock <IMatchRepository>(); mockedService.Setup(m => m.GetAllMatches()).Returns(list); mockedService.Setup(m => m.FindById(0)).Returns(match1); MatchController controller = new MatchController(mockedService.Object); controller.ModelState.AddModelError("Error", "error"); // Act var result = controller.Create(match2); // Assert var model = ((ViewResult)result).Model as Players.Models.Match; Assert.AreEqual(match2, model); }