mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-21 07:51:23 +02:00
Scenario : stay on current state for a number of times (#495)
* state * xml comment
This commit is contained in:
@@ -23,12 +23,12 @@ namespace WireMock.Owin
|
||||
{
|
||||
try
|
||||
{
|
||||
string scenario = mapping.Scenario != null && _options.Scenarios.ContainsKey(mapping.Scenario) ? _options.Scenarios[mapping.Scenario].NextState : null;
|
||||
string nextState = GetNextState(mapping);
|
||||
|
||||
mappings.Add(new MappingMatcherResult
|
||||
{
|
||||
Mapping = mapping,
|
||||
RequestMatchResult = mapping.GetRequestMatchResult(request, scenario)
|
||||
RequestMatchResult = mapping.GetRequestMatchResult(request, nextState)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -56,5 +56,18 @@ namespace WireMock.Owin
|
||||
|
||||
return (match, partialMatch);
|
||||
}
|
||||
|
||||
private string GetNextState(IMapping mapping)
|
||||
{
|
||||
// If the mapping does not have a scenario or _options.Scenarios does not contain this scenario from the mapping,
|
||||
// just return null to indicate that there is no next state.
|
||||
if (mapping.Scenario == null || !_options.Scenarios.ContainsKey(mapping.Scenario))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Else just return the next state
|
||||
return _options.Scenarios[mapping.Scenario].NextState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ namespace WireMock.Owin
|
||||
{
|
||||
foreach (var mapping in _options.Mappings.Values.Where(m => m?.Scenario != null))
|
||||
{
|
||||
// Set start
|
||||
// Set scenario start
|
||||
if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState)
|
||||
{
|
||||
_options.Scenarios.TryAdd(mapping.Scenario, new ScenarioState
|
||||
@@ -122,9 +122,7 @@ namespace WireMock.Owin
|
||||
|
||||
if (targetMapping.Scenario != null)
|
||||
{
|
||||
_options.Scenarios[targetMapping.Scenario].NextState = targetMapping.NextState;
|
||||
_options.Scenarios[targetMapping.Scenario].Started = true;
|
||||
_options.Scenarios[targetMapping.Scenario].Finished = targetMapping.NextState == null;
|
||||
UpdateScenarioState(targetMapping);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -157,6 +155,25 @@ namespace WireMock.Owin
|
||||
await CompletedTask;
|
||||
}
|
||||
|
||||
private void UpdateScenarioState(IMapping mapping)
|
||||
{
|
||||
var scenario = _options.Scenarios[mapping.Scenario];
|
||||
|
||||
// Increase the number of times this state has been executed
|
||||
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))
|
||||
{
|
||||
scenario.NextState = mapping.NextState;
|
||||
scenario.Counter = 0;
|
||||
}
|
||||
|
||||
// Else just update Started and Finished
|
||||
scenario.Started = true;
|
||||
scenario.Finished = mapping.NextState == null;
|
||||
}
|
||||
|
||||
private void LogRequest(LogEntry entry, bool addRequest)
|
||||
{
|
||||
_options.Logger.DebugRequestResponse(LogEntryMapper.Map(entry), entry.RequestMessage.Path.StartsWith("/__admin/"));
|
||||
|
||||
Reference in New Issue
Block a user