/SimpleHttpMock

A really simple http mock using self host service.

Primary LanguageC#Apache License 2.0Apache-2.0

SimpleHttpMock Build status

A really simple http mock using self host service.

Using Hamcrest Matchers

  • Matchers.Regex
 var serverBuilder = new MockedHttpServerBuilder();
 serverBuilder
     .WhenGet(Matchers.Regex(@"/(staff)|(user)s"))
     .Respond(HttpStatusCode.InternalServerError);

 using (serverBuilder.Build(BaseAddress))
 {
     var response = Get("http://localhost/users"));
     Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
 }
  • Matchers.WildCard
serverBuilder
    .WhenGet(Matchers.Wildcard(@"/staffs/?"))
    .Respond(HttpStatusCode.Unauthorized);
  • Matchers.Is
serverBuilder
     .WhenGet(Matchers.Is("/staffs"))
     .Respond(HttpStatusCode.OK);

Other methods

serverBuilder
    .When(Matchers.Wildcard(@"/staffs/?"), HttpMethod.Patch)
    .Respond(HttpStatusCode.Unauthorized);