Quantcast
Channel: Mocking Asp.net-mvc Controller Context - Stack Overflow
Browsing latest articles
Browse All 8 View Live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

Mocking 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

Browsing latest articles
Browse All 8 View Live




Latest Images