Answer by Maksym Kozlenko for Mocking Asp.net-mvc Controller Context
Here is a sample unit test class using MsTest and Moq which mocks HttpRequest and HttpResponse objects. (.NET 4.0, ASP.NET MVC 3.0 )Controller action get value from request and sets http header in...
View ArticleAnswer by Gabe Moothart for Mocking Asp.net-mvc Controller Context
The procedure for this seems to have changed slightly in MVC2 (I'm using RC1). Phil Haack's solution doesn't work for me if the action requires a specific method ([HttpPost], [HttpGet]). Spelunking...
View ArticleAnswer by RoyOsherove for Mocking Asp.net-mvc Controller Context
Or you can do this with Typemock Isolator with no need to send in a fake controller at all:Isolate.WhenCalled(()=>HttpContext.Request.HttpMethod).WillReturn("Get");
View ArticleAnswer by ruslan rusu for Mocking Asp.net-mvc Controller Context
i've finished with this specpublic abstract class Specification <C> where C: Controller{ protected C controller; HttpContextBase mockHttpContext; HttpRequestBase mockRequest; protected Exception...
View ArticleAnswer by Dane O'Connor for Mocking Asp.net-mvc Controller Context
Here's a snippet from Jason's link. Its the same as Phil's method but uses rhino. Note: mockHttpContext.Request is stubbed to return mockRequest before mockRequest's internals are stubbed out. I...
View ArticleAnswer by Matt Hinze for Mocking Asp.net-mvc Controller Context
I find that long mocking procedure to be too much friction.The best way we have found - using ASP.NET MVC on a real project - is to abstract the HttpContext to an IWebContext interface that simply...
View ArticleAnswer by Haacked for Mocking Asp.net-mvc Controller Context
Using MoQ it looks something like this:var request = new Mock<HttpRequestBase>();request.Expect(r => r.HttpMethod).Returns("GET");var mockHttpContext = new...
View ArticleMocking Asp.net-mvc Controller Context
So the controller context depends on some asp.net internals. What are some ways to cleanly mock these up for unit tests? Seems like its very easy to clog up tests with tons of setup when I only need,...
View Article