Created
April 3, 2012 11:30
-
-
Save potix2/2291165 to your computer and use it in GitHub Desktop.
ASP.NET MVC3のController内でSessionが更新されていることをテストするためのコード(Moq使用)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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