A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/StefH/WireMock.Net/wiki/Using-WireMock-in-UnitTests below:

Using WireMock in UnitTests · wiremock/WireMock.Net Wiki · GitHub

WireMock with your favorite UnitTest framework

Obviously you can use your favorite test framework and use WireMock.Net within your tests. In order to avoid flaky tests you should:

Below a simple example using Nunit and NFluent test assertion library:

[SetUp]
public void StartMockServer()
{
    _server = WireMockServer.Start();
}

[Test]
public async Task Should_respond_to_request()
{
  // Arrange (start WireMock.Net server)
  _server
    .Given(Request.Create().WithPath("/foo").UsingGet())
    .RespondWith(
      Response.Create()
        .WithStatusCode(200)
        .WithBody(@"{ ""msg"": ""Hello world!"" }")
    );

  // Act (use a HttpClient which connects to the URL where WireMock.Net is running)
  var response = await new HttpClient().GetAsync($"{_server.Urls[0]}/foo");
    
  // Assert
  Check.That(response).IsEqualTo(EXPECTED_RESULT);
}

[TearDown]
public void ShutdownServer()
{
    _server.Stop();
}

For some more examples: see https://github.com/bredah/csharp-wiremock


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4