mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 15:10:17 +02:00
Support int values for states and scenario naming (#376)
* Support int values for states and scenario naming * fix remove added dependency
This commit is contained in:
committed by
Stef Heyenrath
parent
9b323ab388
commit
0ff23a3d15
@@ -61,6 +61,13 @@ namespace WireMock.Server
|
|||||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
IRespondWithAProvider InScenario(string scenario);
|
IRespondWithAProvider InScenario(string scenario);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the the scenario with an integer value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="scenario">The scenario.</param>
|
||||||
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
|
IRespondWithAProvider InScenario(int scenario);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Execute this respond only in case the current state is equal to specified one.
|
/// Execute this respond only in case the current state is equal to specified one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -68,11 +75,25 @@ namespace WireMock.Server
|
|||||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
IRespondWithAProvider WhenStateIs(string state);
|
IRespondWithAProvider WhenStateIs(string state);
|
||||||
|
|
||||||
|
/// <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(int state);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Once this mapping is executed the state will be changed to specified one.
|
/// Once this mapping is executed the state will be changed to specified one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="state">Any object which identifies the new state</param>
|
/// <param name="state">Any object which identifies the new state</param>
|
||||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
IRespondWithAProvider WillSetStateTo(string state);
|
IRespondWithAProvider WillSetStateTo(string 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(int state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,13 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WhenStateIs"/>
|
/// <see cref="IRespondWithAProvider.InScenario(int)"/>
|
||||||
|
public IRespondWithAProvider InScenario(int scenario)
|
||||||
|
{
|
||||||
|
return InScenario(scenario.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <see cref="IRespondWithAProvider.WhenStateIs(string)"/>
|
||||||
public IRespondWithAProvider WhenStateIs(string state)
|
public IRespondWithAProvider WhenStateIs(string state)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_scenario))
|
if (string.IsNullOrEmpty(_scenario))
|
||||||
@@ -106,7 +112,13 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WillSetStateTo"/>
|
/// <see cref="IRespondWithAProvider.WhenStateIs(int)"/>
|
||||||
|
public IRespondWithAProvider WhenStateIs(int state)
|
||||||
|
{
|
||||||
|
return WhenStateIs(state.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <see cref="IRespondWithAProvider.WillSetStateTo(string)"/>
|
||||||
public IRespondWithAProvider WillSetStateTo(string state)
|
public IRespondWithAProvider WillSetStateTo(string state)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_scenario))
|
if (string.IsNullOrEmpty(_scenario))
|
||||||
@@ -118,5 +130,11 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <see cref="IRespondWithAProvider.WillSetStateTo(int)"/>
|
||||||
|
public IRespondWithAProvider WillSetStateTo(int state)
|
||||||
|
{
|
||||||
|
return WillSetStateTo(state.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,90 @@ namespace WireMock.Net.Tests
|
|||||||
Check.That(responseWithState).Equals("Test state msg");
|
Check.That(responseWithState).Equals("Test state msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Scenarios_Should_Respect_Int_Valued_Scenarios_and_States()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
string path = $"/foo_{Guid.NewGuid()}";
|
||||||
|
var server = FluentMockServer.Start();
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario(1)
|
||||||
|
.WillSetStateTo(2)
|
||||||
|
.RespondWith(Response.Create().WithBody("Scenario 1, Setting State 2"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario(1)
|
||||||
|
.WhenStateIs(2)
|
||||||
|
.RespondWith(Response.Create().WithBody("Scenario 1, State 2"));
|
||||||
|
|
||||||
|
// when
|
||||||
|
var responseIntScenario = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
var responseWithIntState = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(responseIntScenario).Equals("Scenario 1, Setting State 2");
|
||||||
|
Check.That(responseWithIntState).Equals("Scenario 1, State 2");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Scenarios_Should_Respect_Mixed_String_Scenario_and_Int_State()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
string path = $"/foo_{Guid.NewGuid()}";
|
||||||
|
var server = FluentMockServer.Start();
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario("state string")
|
||||||
|
.WillSetStateTo(1)
|
||||||
|
.RespondWith(Response.Create().WithBody("string state, Setting State 2"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario("state string")
|
||||||
|
.WhenStateIs(1)
|
||||||
|
.RespondWith(Response.Create().WithBody("string state, State 2"));
|
||||||
|
|
||||||
|
// when
|
||||||
|
var responseIntScenario = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
var responseWithIntState = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(responseIntScenario).Equals("string state, Setting State 2");
|
||||||
|
Check.That(responseWithIntState).Equals("string state, State 2");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Scenarios_Should_Respect_Mixed_Int_Scenario_and_String_Scenario_and_String_State()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
string path = $"/foo_{Guid.NewGuid()}";
|
||||||
|
var server = FluentMockServer.Start();
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario(1)
|
||||||
|
.WillSetStateTo("Next State")
|
||||||
|
.RespondWith(Response.Create().WithBody("int state, Setting State 2"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario("1")
|
||||||
|
.WhenStateIs("Next State")
|
||||||
|
.RespondWith(Response.Create().WithBody("string state, State 2"));
|
||||||
|
|
||||||
|
// when
|
||||||
|
var responseIntScenario = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
var responseWithIntState = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(responseIntScenario).Equals("int state, Setting State 2");
|
||||||
|
Check.That(responseWithIntState).Equals("string state, State 2");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Scenarios_TodoList_Example()
|
public async Task Scenarios_TodoList_Example()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user