Skip to content

RoBYCoNTe/HttpContextNSubstitute

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HttpContextNSubstitute

Easy mocking for ASP.NET Core HttpContext.

HttpContextNSubstitute is an implementation of AspNetCore.Http.HttpContext that stores a Mock instance and works as a proxy for the real Mock.

Instalation

Usage

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);

Development

Open the solution src\HttpContextNSubstitute.sln on Visual Studio.

How to build the library?

Open the solution file src\HttpContextNSubstitute.sln with Visual Studio, and Build the Solution (Build -> Build Solution)

or

Execute the following make command.

make build

How to run the unit tests?

Open the solution file src\HttpContextNSubstitute.sln with Visual Studio, and run the unit tests (Test -> Run All Tests)

or

Execute the following make command.

make test

How to pack the library?

Open the solution file src\HttpContextNSubstitute.sln with Visual Studio, and pack the HttpContextNSubstitute (Build -> Pack HttpContextNSubstitute)

make pack

Contributing

Please read contributing for details of the code of conduct, and the process for submitting pull requests to us.

Versioning

Uses SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Tiago Araújo - Initial work - tiagodaraujo
  • Roberto Conte Rosito - NSubstitute implementation - robyconte

See also the list of contributors who participated in this project.

About

Implementation with NSubstitute

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.7%
  • Makefile 0.3%