This commit is contained in:
Stef Heyenrath
2026-02-21 17:31:19 +01:00
parent 43be85a88a
commit d8353fcd94
3 changed files with 27 additions and 21 deletions

View File

@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
using Stef.Validation;
using WireMock.Server;
// ReSharper disable once CheckNamespace
@@ -10,31 +9,20 @@ namespace WireMock.AwesomeAssertions;
/// Provides assertion methods to verify the number of calls made to a WireMock server.
/// This class is used in the context of AwesomeAssertions.
/// </summary>
public class WireMockANumberOfCallsAssertions
/// <remarks>
/// Initializes a new instance of the <see cref="WireMockANumberOfCallsAssertions"/> class.
/// </remarks>
/// <param name="server">The WireMock server to assert against.</param>
/// <param name="callsCount">The expected number of calls to assert.</param>
/// <param name="chain">The assertion chain</param>
public class WireMockANumberOfCallsAssertions(IWireMockServer server, int callsCount, AssertionChain chain)
{
private readonly IWireMockServer _server;
private readonly int _callsCount;
private readonly AssertionChain _chain;
/// <summary>
/// Initializes a new instance of the <see cref="WireMockANumberOfCallsAssertions"/> class.
/// </summary>
/// <param name="server">The WireMock server to assert against.</param>
/// <param name="callsCount">The expected number of calls to assert.</param>
/// <param name="chain">The assertion chain</param>
public WireMockANumberOfCallsAssertions(IWireMockServer server, int callsCount, AssertionChain chain)
{
_server = Guard.NotNull(server);
_callsCount = callsCount;
_chain = chain;
}
/// <summary>
/// Returns an instance of <see cref="WireMockAssertions"/> which can be used to assert the expected number of calls.
/// </summary>
/// <returns>A <see cref="WireMockAssertions"/> instance for asserting the number of calls to the server.</returns>
public WireMockAssertions Calls()
{
return new WireMockAssertions(_server, _callsCount, _chain);
return new WireMockAssertions(server, callsCount, chain);
}
}

View File

@@ -11,9 +11,10 @@ public partial class WireMockAssertions
{
public const string Any = "*";
private readonly AssertionChain _chain;
public int? CallsCount { get; }
public IReadOnlyList<IRequestMessage> RequestMessages { get; private set; }
private readonly AssertionChain _chain;
public WireMockAssertions(IWireMockServer subject, int? callsCount, AssertionChain chain)
{

View File

@@ -3,6 +3,8 @@
using System.Net.Http.Headers;
using System.Text;
using Stef.Validation;
using WireMock.Admin.Mappings;
using WireMock.Admin.Requests;
using WireMock.Client.Builders;
namespace WireMock.Client.Extensions;
@@ -73,6 +75,21 @@ public static class WireMockAdminApiExtensions
}
}
/// <summary>
/// Find requests based on the criteria (<see cref="RequestModel"/>).
/// </summary>
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
/// <param name="builder">The <see cref="RequestModelBuilder"/> action to fluently build the request model.</param>
/// <param name="cancellationToken">The optional cancellationToken.</param>
public static Task<IList<LogEntryModel>> FindRequestsAsync(this IWireMockAdminApi adminApi, Action<RequestModelBuilder> builder, CancellationToken cancellationToken = default)
{
var modelBuilder = new RequestModelBuilder();
builder(modelBuilder);
var requestModel = modelBuilder.Build();
return adminApi.FindRequestsAsync(requestModel, cancellationToken);
}
private static async Task<bool> IsHealthyAsync(IWireMockAdminApi adminApi, CancellationToken cancellationToken)
{
try