Question

I'm using MvcContrib.TestHelper, and initialize my controller like this:

var accountController = new AccountController();

var builder = new TestControllerBuilder();
builder.InitializeController(accountController);

My problem is, that inside my AccountController I have:

Request.Url.GetLeftPart(UriPartial.Authority);

However, this comes back as null. Request is a proxy.

How can I set this up from my unit test?

Was it helpful?

Solution

This has probably already been solved, but what worked for me was to use a mocking framework (like RhinoMocks):

var contextMock = MockRepository.GenerateMock<HttpContextBase>();
contextMock.Expect(x => x.Request).Return(new FakeHttpRequest("SOME_RELATIVE_URL", new Uri("http://to.somewhere.com"), new Uri("http://from.somewhere.com")));

controller.ControllerContext.HttpContext = contextMock;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top