Search code examples
c#unit-testingmockingjustmock

How to Arrange a property of the base class using JustMockLite


I am using the free version of JustMock for writing the unit tests. I have am CustomApiController class which inherits system.web.Http.ApiController class. So from system.web.Http.ApiController class comes a property called Request (which is of System.Net.Http.HttpRequestMessage type. Now in the method for which I am writing my unit test has something like:

if (this.Request.Headers.TryGetValues("HeaderName", out someCollectionOfStrings)

How can I arrange/mock the Request object to return this as true?


Solution

  • This can be solved by creating a new request object and assigned it to our controller request property.

    var request = new HttpRequestMessage(HttpMethod.Get, "http://stackoverflow");
                request.Headers.Add("HeaderName","3443");
    _apiController.Request = request;