NuGet Gallery Feed for HttpServerMockHTTP server mock is a really useful tool for testing, it will help you to mock HTTP requests.https://www.nuget.org/packages/HttpServerMock/2019-03-19T14:42:57Zhttps://api.nuget.org/v3-flatcontainer/httpservermock/0.0.94/iconhttps://www.nuget.org/packages/HttpServerMock/0.0.94HttpServerMock 0.0.942019-03-19T14:38:45Z2019-03-19T14:42:57Zjaimeamestihttps://www.nuget.org/profiles/jaimeamestiHTTP server mock is a really useful tool for testing, it will help you to mock HTTP requests.https://www.nuget.org/packages/HttpServerMock/0.0.92HttpServerMock 0.0.922015-07-29T10:49:45Z2018-12-08T14:25:34Zjaimeamestihttps://www.nuget.org/profiles/jaimeamestiHTTP server mock is a really useful tool for testing, it will help you to mock HTTP requests.
Please have a look at the documentation for details: http://jaimeamesti.github.io/HttpServerMockhttps://www.nuget.org/packages/HttpServerMock/0.0.91HttpServerMock 0.0.912015-05-11T08:13:46Z2018-12-08T14:25:31Zjaimeamestihttps://www.nuget.org/profiles/jaimeamestiHTTP server mock is a really useful tool for testing, it will help you to mock HTTP requests.
SOME EXAMPLES
Delete
using (var hserver = new HttpServerMock(TestServerPort))
{
hserver.SetUpExpectation(HttpMethod.DELETE, "http://localhost:50000/user/23")
.ExpectedRequestHeader("test", "test1")
.Response(
HttpStatusCode.OK,
HttpRequestContentType.Json,
new ResponseTestClass { Name = "response", IsOld = true, Age = 12 });
var restClient = new RestClient(this.serverBaseUrl);
var request = new RestRequest("/user/23");
request.AddJsonBody(new { Name = "test", Id = 23 });
request.AddHeader("test", "test1");
request.Method = Method.DELETE;
var response = restClient.Execute<ResponseTestClass>(request);
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The respond status code is not the expected.");
hserver.VerifyAllRequestExpectationsAndUnexpectedRequests();
}
Post
using (var hserver = new HttpServerMock(TestServerPort))
{
hserver.SetUpPostExpectation("http://localhost:50000/user/23")
.ExpectedNumberOfCalls(1)
.ExpectedContent(new { Name = "test", Id = 23 }, HttpRequestContentType.Json)
.ExpectedRequestHeader("test", "test1")
.Response(HttpStatusCode.OK, HttpRequestContentType.Json, new ResponseTestClass { Name = "response", IsOld = true, Age = 12 });
var restClient = new RestClient(this.serverBaseUrl);
var request = new RestRequest("/user/23");
request.AddJsonBody(new { Name = "test", Id = 23 });
request.AddHeader("test", "test1");
request.Method = Method.POST;
var response = restClient.Execute<ResponseTestClass>(request);
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The respond status code is not the expected.");
Assert.IsNotNull(response.Data, "The response is empty.");
Assert.AreEqual("response", response.Data.Name, "The response data is not the expected.");
Assert.IsTrue(response.Data.IsOld, "The response data is not the expected.");
Assert.AreEqual(12, response.Data.Age, "The response data is not the expected.");
hserver.VerifyAllRequestExpectationsAndUnexpectedRequests();
}
Using Relatives Uris
using (var hserver = new HttpServerMock(TestServerPort))
{
hserver.SetUpGetExpectation("user/23")
.Response(HttpStatusCode.OK);
var restClient = new RestClient(this.serverBaseUrl);
var request = new RestRequest("/user/23") { Method = Method.GET };
var response = restClient.Execute(request);
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The respond status code is not the expected.");
Assert.IsNull(response.ErrorException, "The request contains an exception.");
}
Setting up a default status code
using (var hserver = new HttpServerMock(TestServerPort))
{
hserver.ServerRequestsState.DefaultRespondStatusCode = HttpStatusCode.NotModified;
var restClient = new RestClient(this.serverBaseUrl);
var request = new RestRequest("/user/23");
request.Method = Method.GET;
var response = restClient.Execute<ResponseTestClass>(request);
Assert.AreEqual(HttpStatusCode.NotModified, response.StatusCode, "The respond status code is not the expected.");
}https://www.nuget.org/packages/HttpServerMock/0.0.9HttpServerMock 0.0.92015-05-06T10:02:12Z2018-12-08T14:25:31Zjaimeamestihttps://www.nuget.org/profiles/jaimeamestiHTTP server mock is a really useful tool for testing, it will help you to mock HTTP requests.