public void TestAddInvalidSportObjectReturnsCurrentView() { //Arrange var model = new SportObjectModel { Sport = new Sport { SportId = 1, Name = "testsport" }, SportObject = new SportObject { SportObjectId = 3, Name = "TestOBJECT" } }; var mockManager = new Mock <ISportManager>(); var mockTempData = new Mock <ITempDataDictionary>(); var controller = new SportController(mockManager.Object) { TempData = mockTempData.Object }; controller.ModelState.AddModelError("", ""); mockManager.Setup(x => x.AddSportObject(It.IsAny <Sport>(), It.IsAny <SportObject>())).Throws <Exception>(); //Act var result = (ViewResult)controller.AddObject(model, 1); //Asert Assert.True(result.ViewName == "AddObject"); }
public void TestAddSportObjectReturnsToIndexAction() { //Arrange var model = new SportObjectModel { Sport = new Sport { SportId = 1, Name = "testsport" }, SportObject = new SportObject { SportObjectId = 1, Name = "TestOBJECT" } }; var mockManager = new Mock <ISportManager>(); var mockTempData = new Mock <ITempDataDictionary>(); var controller = new SportController(mockManager.Object) { TempData = mockTempData.Object }; mockManager.Setup(x => x.AddSportObject(It.IsAny <Sport>(), It.IsAny <SportObject>())).Throws <Exception>(); //Act var result = controller.AddObject(model, 1); //Assert Assert.IsType(typeof(RedirectToActionResult), result); }