mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-18 08:07:09 +01:00
Add TimesInSameState to MappingModel (#1345)
* Add TimesInSameState to MappingModel * fix tests
This commit is contained in:
@@ -56,6 +56,11 @@ public class MappingModel
|
||||
/// In case the value is null state will not be changed.
|
||||
/// </summary>
|
||||
public string? SetStateTo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of times this match should be matched before the state will be changed to the specified one.
|
||||
/// </summary>
|
||||
public int? TimesInSameState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The request model.
|
||||
@@ -86,7 +91,7 @@ public class MappingModel
|
||||
/// Fire and forget for webhooks.
|
||||
/// </summary>
|
||||
public bool? UseWebhooksFireAndForget { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Data Object which can be used when WithTransformer is used.
|
||||
/// e.g. lookup a path in this object using
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface IMapping
|
||||
/// <summary>
|
||||
/// The number of times this match should be matched before the state will be changed to the next state.
|
||||
/// </summary>
|
||||
int? StateTimes { get; }
|
||||
int? TimesInSameState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The RequestMatcher.
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Mapping : IMapping
|
||||
public string? NextState { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public int? StateTimes { get; }
|
||||
public int? TimesInSameState { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRequestMatcher RequestMatcher { get; }
|
||||
@@ -137,7 +137,7 @@ public class Mapping : IMapping
|
||||
Scenario = scenario;
|
||||
ExecutionConditionState = executionConditionState;
|
||||
NextState = nextState;
|
||||
StateTimes = stateTimes;
|
||||
TimesInSameState = stateTimes;
|
||||
Webhooks = webhooks;
|
||||
UseWebhooksFireAndForget = useWebhooksFireAndForget;
|
||||
TimeSettings = timeSettings;
|
||||
|
||||
@@ -299,7 +299,7 @@ namespace WireMock.Owin
|
||||
scenario.Counter++;
|
||||
|
||||
// Only if the number of times this state is executed equals the required StateTimes, proceed to next state and reset the counter to 0
|
||||
if (scenario.Counter == (mapping.StateTimes ?? 1))
|
||||
if (scenario.Counter == (mapping.TimesInSameState ?? 1))
|
||||
{
|
||||
scenario.NextState = mapping.NextState;
|
||||
scenario.Counter = 0;
|
||||
|
||||
@@ -267,6 +267,7 @@ internal class MappingConverter(MatcherMapper mapper)
|
||||
Scenario = mapping.Scenario,
|
||||
WhenStateIs = mapping.ExecutionConditionState,
|
||||
SetStateTo = mapping.NextState,
|
||||
TimesInSameState = !string.IsNullOrWhiteSpace(mapping.NextState) ? mapping.TimesInSameState : null,
|
||||
Data = mapping.Data,
|
||||
Probability = mapping.Probability,
|
||||
Request = new RequestModel
|
||||
|
||||
@@ -97,7 +97,7 @@ public partial class WireMockServer
|
||||
|
||||
if (!string.IsNullOrEmpty(mappingModel.SetStateTo))
|
||||
{
|
||||
respondProvider = respondProvider.WillSetStateTo(mappingModel.SetStateTo!);
|
||||
respondProvider = respondProvider.WillSetStateTo(mappingModel.SetStateTo!, mappingModel.TimesInSameState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user