Reputation: 2283
I am getting the proverbial knickers in a twist. For this very simple code:
public ActionResult Add()
{
this.HttpContext.Items["pm-page-title"] = "Some title";
return this.View();
}
How do I go about writing the MSpec test, using fakeiteasy, to verify that a view is returned and more pertinently that the page title is set correctly?
TIA,
David
Upvotes: 0
Views: 552
Reputation: 1038710
// arrange
var sut = new SomeController();
sut.ControllerContext = A.Fake<ControllerContext>();
var fakeContext = A.Fake<HttpContextBase>();
A.CallTo(() => sut.ControllerContext.HttpContext).Returns(fakeContext);
A.CallTo(() => fakeContext.Items).Returns(new Hashtable());
// act
var actual = sut.Add();
// assert
Assert.AreEqual("Some title", (string)fakeContext.Items["pm-page-title"]);
Upvotes: 1