Easy mocking for ASP.NET Core HttpContext.
HttpContextMoq is an implementation of AspNetCore.Http.HttpContext
that stores a Mock instance and works as a proxy for the real Mock.
Basic GET request:
var context = new HttpContextMock()
.SetupUrl("http://localhost:8000/path")
.SetupRequestMethod("GET");
POST request (with body):
var data = Encoding.UTF8.GetBytes("{\"Foo\":\"Bar\"");
var context = new HttpContextMock()
.SetupUrl("http://localhost:8000/path")
.SetupRequestMethod("POST")
.SetupRequestContentType("application/json")
.SetupRequestBody(new MemoryStream(data))
.SetupRequestContentLength(data.Length);
Request/Response pair, usefull for testing Action Filters:
var data = Encoding.UTF8.GetBytes("{\"Foo\":\"Bar\"");
var context = new HttpContextMock()
.SetupUrl("http://localhost:8000/path")
.SetupRequestMethod("GET")
.SetupResponseContentType("application/json")
.SetupResponseBody(new MemoryStream(data))
.SetupResponseContentLength(data.Length);
Open the solution src\HttpContextMoq.sln
on Visual Studio.
Open the solution file src\HttpContextMoq.sln
with Visual Studio, and Build the Solution (Build -> Build Solution)
or
Execute the following make command.
make build
Open the solution file src\HttpContextMoq.sln
with Visual Studio, and run the unit tests (Test -> Run All Tests)
or
Execute the following make command.
make test
Open the solution file src\HttpContextMoq.sln
with Visual Studio, and pack the HttpContextMoq (Build -> Pack HttpContextMoq)
make pack
Please read contributing for details of the code of conduct, and the process for submitting pull requests to us.
Uses SemVer for versioning. For the versions available, see the tags on this repository.
- Tiago Araújo - Initial work - tiagodaraujo
See also the list of contributors who participated in this project.