Files
WireMock.Net/test/WireMock.Net.Tests/WireMockServerTests.WithProbability.cs
Stef Heyenrath 54edf0bebc Add link to TIOBE Index on main page + fix issues (#1137)
* Add TIOBE + include SonarAnalyzer.CSharp

* .

* cp

* Copyright © WireMock.Net

* more fixes

* fix

* xpath

* if (Matchers == null || !Matchers.Any())

* if (Matchers != null)

* ?

* .

* .
2024-07-18 18:06:04 +02:00

39 lines
1.1 KiB
C#

// Copyright © WireMock.Net
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using Xunit;
namespace WireMock.Net.Tests;
public partial class WireMockServerTests
{
[Fact]
public async Task WireMockServer_WithProbability()
{
// Arrange
var server = WireMockServer.Start();
server
.Given(Request.Create().UsingGet().WithPath("/foo"))
.WithProbability(0.5)
.RespondWith(Response.Create().WithStatusCode(200));
server
.Given(Request.Create().UsingGet().WithPath("/foo"))
.RespondWith(Response.Create().WithStatusCode(500));
// Act
var requestUri = new Uri($"http://localhost:{server.Port}/foo");
var response = await server.CreateClient().GetAsync(requestUri).ConfigureAwait(false);
// Assert
Assert.True(new[] { HttpStatusCode.OK, HttpStatusCode.InternalServerError }.Contains(response.StatusCode));
server.Stop();
}
}