public async void TestCreate_InvalidRating_ShouldFail() { // Arrange RatingsController controller = new RatingsController(_context); InitializeRating(); rating.GameId = 99; try { // Act var result = await controller.Create(rating.GameId, Convert.ToInt16(rating.Rate)); // Assert Assert.IsType <ViewResult>(result); ViewResult viewResult = (ViewResult)result; Assert.NotNull(viewResult.ViewData.ModelState); Assert.NotEmpty(viewResult.ViewData.ModelState.Keys); foreach (string item in viewResult.ViewData.ModelState.Keys) { Assert.Equal("", item); } } catch (Exception ex) { Assert.Equal("System.NullReferenceException", ex.GetType().ToString()); } }
public void TestRatingsControllerCreateName() { var controller = new RatingsController(); ActionResult result = controller.Create() as ViewResultBase; string r = (result as ViewResult).ViewName; Assert.AreEqual("Create", r); }
public void TestLocalsControllerCreateView() { var controller = new RatingsController(); ActionResult result = controller.Create() as ViewResult; //Assert.AreEqual("Create", result.ViewName); Assert.IsInstanceOfType(result, typeof(ViewResult)); }