diff --git a/src/WireMock.Net/Server/IRespondWithAProvider.cs b/src/WireMock.Net/Server/IRespondWithAProvider.cs
index a2d67e31..18c09520 100644
--- a/src/WireMock.Net/Server/IRespondWithAProvider.cs
+++ b/src/WireMock.Net/Server/IRespondWithAProvider.cs
@@ -61,6 +61,13 @@ namespace WireMock.Server
/// The .
IRespondWithAProvider InScenario(string scenario);
+ ///
+ /// Sets the the scenario with an integer value.
+ ///
+ /// The scenario.
+ /// The .
+ IRespondWithAProvider InScenario(int scenario);
+
///
/// Execute this respond only in case the current state is equal to specified one.
///
@@ -68,11 +75,25 @@ namespace WireMock.Server
/// The .
IRespondWithAProvider WhenStateIs(string state);
+ ///
+ /// Execute this respond only in case the current state is equal to specified one.
+ ///
+ /// Any object which identifies the current state
+ /// The .
+ IRespondWithAProvider WhenStateIs(int state);
+
///
/// Once this mapping is executed the state will be changed to specified one.
///
/// Any object which identifies the new state
/// The .
IRespondWithAProvider WillSetStateTo(string state);
+
+ ///
+ /// Once this mapping is executed the state will be changed to specified one.
+ ///
+ /// Any object which identifies the new state
+ /// The .
+ IRespondWithAProvider WillSetStateTo(int state);
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Server/RespondWithAProvider.cs b/src/WireMock.Net/Server/RespondWithAProvider.cs
index 02b5bbed..d259a9d4 100644
--- a/src/WireMock.Net/Server/RespondWithAProvider.cs
+++ b/src/WireMock.Net/Server/RespondWithAProvider.cs
@@ -93,7 +93,13 @@ namespace WireMock.Server
return this;
}
- ///
+ ///
+ public IRespondWithAProvider InScenario(int scenario)
+ {
+ return InScenario(scenario.ToString());
+ }
+
+ ///
public IRespondWithAProvider WhenStateIs(string state)
{
if (string.IsNullOrEmpty(_scenario))
@@ -106,7 +112,13 @@ namespace WireMock.Server
return this;
}
- ///
+ ///
+ public IRespondWithAProvider WhenStateIs(int state)
+ {
+ return WhenStateIs(state.ToString());
+ }
+
+ ///
public IRespondWithAProvider WillSetStateTo(string state)
{
if (string.IsNullOrEmpty(_scenario))
@@ -118,5 +130,11 @@ namespace WireMock.Server
return this;
}
+
+ ///
+ public IRespondWithAProvider WillSetStateTo(int state)
+ {
+ return WillSetStateTo(state.ToString());
+ }
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/StatefulBehaviorTests.cs b/test/WireMock.Net.Tests/StatefulBehaviorTests.cs
index 1c50838c..9b511da5 100644
--- a/test/WireMock.Net.Tests/StatefulBehaviorTests.cs
+++ b/test/WireMock.Net.Tests/StatefulBehaviorTests.cs
@@ -61,6 +61,90 @@ namespace WireMock.Net.Tests
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]
public async Task Scenarios_TodoList_Example()
{