开发者

How to write the MSpec test for code containing calls to HttpContext using fakeiteasy?

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 r开发者_JS百科eturned and more pertinently that the page title is set correctly?

TIA,

David


// 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"]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜