mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-22 00:37:50 +01:00
.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user