stateful behavior + tests

This commit is contained in:
deeptowncitizen
2017-10-04 15:57:49 -04:00
parent 8827531391
commit ab017beaa6
8 changed files with 193 additions and 3 deletions

View File

@@ -40,5 +40,19 @@ namespace WireMock.Server
/// </summary>
/// <param name="provider">The provider.</param>
void RespondWith(IResponseProvider provider);
/// <summary>
/// Execute this respond only in case the current state is equal to specified one
/// </summary>
/// <param name="state">Any object which identifies the current state</param>
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
IRespondWithAProvider WhenStateIs(object state);
/// <summary>
/// Once this mapping is executed the state will be changed to specified one
/// </summary>
/// <param name="state">Any object which identifies the new state</param>
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
IRespondWithAProvider WillSetStateTo(object state);
}
}

View File

@@ -12,6 +12,9 @@ namespace WireMock.Server
private Guid? _guid;
private string _title;
private object _executionConditionState = null;
private object _nextState = null;
/// <summary>
/// The _registration callback.
/// </summary>
@@ -42,7 +45,19 @@ namespace WireMock.Server
public void RespondWith(IResponseProvider provider)
{
var mappingGuid = _guid ?? Guid.NewGuid();
_registrationCallback(new Mapping(mappingGuid, _title, _requestMatcher, provider, _priority));
_registrationCallback(new Mapping(mappingGuid, _title, _requestMatcher, provider, _priority, _executionConditionState, _nextState));
}
public IRespondWithAProvider WhenStateIs(object state)
{
_executionConditionState = state;
return this;
}
public IRespondWithAProvider WillSetStateTo(object state)
{
_nextState = state;
return this;
}
/// <summary>