I am using nuit with moq to test my controllers.
I am using a session class that has an interface, and the HttpContext is injected into the constructor using ninject. like this
public class SessionService : ISession
{
public HttpContext Context { get; set; }
public SessionService(HttpContext context)
{
this.Context = context;
}
}
public interface ISession
{
HttpContext Context { get; set; }
}
public HomeController(ISession session)
{
_session = session;
}
I think in order to check the controller, I first mock the HttpContext, and then pass this object to the constructor of the wearing ISession. I still have it
[Test]
public void index_returns_view()
{
var mockHttpContext = new Mock<HttpContext>();
var mockContext = new Mock<ISession>(mockHttpContext);
var c = new HomeController(mockContext.Object);
var v = c.Index() as ViewResult;
Assert.AreEqual(v.ViewName, "Index", "Index View name incorrect");
}
which builds but nunit returns the following error when running the test
System.NotSupportedException: The type for bullying must be an interface or an abstract or unsealed class.
Thanks for the help.
Jules source
share