mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 22:49:45 +02:00
@@ -175,5 +175,13 @@ public interface IRespondWithAProvider
|
||||
/// lookup data "1"
|
||||
/// </example>
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WithData(object data);
|
||||
|
||||
/// <summary>
|
||||
/// Define the probability when this request should be matched. Value is between 0 and 1.
|
||||
/// </summary>
|
||||
/// <param name="probability">The probability when this request should be matched. Value is between 0 and 1.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WithProbability(double probability);
|
||||
}
|
||||
@@ -18,6 +18,12 @@ namespace WireMock.Server;
|
||||
/// </summary>
|
||||
internal class RespondWithAProvider : IRespondWithAProvider
|
||||
{
|
||||
private readonly RegistrationCallback _registrationCallback;
|
||||
private readonly IRequestMatcher _requestMatcher;
|
||||
private readonly WireMockServerSettings _settings;
|
||||
private readonly IDateTimeUtils _dateTimeUtils;
|
||||
private readonly bool _saveToFile;
|
||||
|
||||
private int _priority;
|
||||
private string? _title;
|
||||
private string? _description;
|
||||
@@ -26,13 +32,8 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
private string? _nextState;
|
||||
private string? _scenario;
|
||||
private int _timesInSameState = 1;
|
||||
private readonly RegistrationCallback _registrationCallback;
|
||||
private readonly IRequestMatcher _requestMatcher;
|
||||
private readonly WireMockServerSettings _settings;
|
||||
private readonly IDateTimeUtils _dateTimeUtils;
|
||||
private readonly bool _saveToFile;
|
||||
|
||||
private bool? _useWebhookFireAndForget;
|
||||
private double? _probability;
|
||||
|
||||
public Guid Guid { get; private set; }
|
||||
|
||||
@@ -92,7 +93,8 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
Webhooks,
|
||||
_useWebhookFireAndForget,
|
||||
TimeSettings,
|
||||
Data);
|
||||
Data,
|
||||
_probability);
|
||||
|
||||
_registrationCallback(mapping, _saveToFile);
|
||||
}
|
||||
@@ -285,6 +287,13 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
||||
return this;
|
||||
}
|
||||
|
||||
public IRespondWithAProvider WithProbability(double probability)
|
||||
{
|
||||
_probability = Guard.Condition(probability, p => p is >= 0 and <= 1.0);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private static IWebhook InitWebhook(
|
||||
string url,
|
||||
string method,
|
||||
|
||||
@@ -113,6 +113,11 @@ public partial class WireMockServer
|
||||
respondProvider.WithWebhookFireAndForget(mappingModel.UseWebhooksFireAndForget.Value);
|
||||
}
|
||||
|
||||
if (mappingModel.Probability != null)
|
||||
{
|
||||
respondProvider.WithProbability(mappingModel.Probability.Value);
|
||||
}
|
||||
|
||||
var responseBuilder = InitResponseBuilder(mappingModel.Response);
|
||||
respondProvider.RespondWith(responseBuilder);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user