I want to unit test the following ASP.NET MVC controller Index action. What do I replace the actual parameter in the assert below (stubbed with ?).
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class StatusController : Controller
{
public ActionResult Index()
{
return Content("Hello World!");
}
}
}
[TestMethod]
public void TestMethod1()
{
// Arrange
var controller = CreateStatusController();
// Act
var result = controller.Index();
// Assert
Assert.AreEqual( "Hello World!.", ? );
}
use the "as" operator to make a nullable cast. Then simply check for a null result
[TestMethod]
public void TestMethod1()
{
// Arrange
var controller = CreateStatusController();
// Act
var result = controller.Index() as ContentResult;
// Assert
Assert.NotNull(result);
Assert.AreEqual( "Hello World!.", result.Content);
}