Skip to content

Instantly share code, notes, and snippets.

@potix2
Created April 3, 2012 11:30
Show Gist options
  • Save potix2/2291165 to your computer and use it in GitHub Desktop.
Save potix2/2291165 to your computer and use it in GitHub Desktop.
ASP.NET MVC3のController内でSessionが更新されていることをテストするためのコード(Moq使用)
//SEE: http://stackoverflow.com/questions/2916348/using-moq-to-set-indexers-in-c-sharp
[TestMethod]
public void IndexTest()
{
var mockHttpContext = new Mock<HttpContextBase>();
var mockSession = new Mock<HttpSessionStateBase>();
mockHttpContext.Setup(context => context.Session).Returns(mockSession.Object);
AppHttpContext.Current = () => mockHttpContext.Object;
var controller = new HomeController();
controller.Index();
mockSession.VerifySet(session => session["Message"] = "Hello, World!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment