mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 23:20:11 +02:00
scenario and state (mapping json model)
This commit is contained in:
@@ -27,7 +27,7 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
|
|
||||||
server.SetBasicAuthentication("a", "b");
|
server.SetBasicAuthentication("a", "b");
|
||||||
|
|
||||||
server.AllowPartialMapping();
|
// server.AllowPartialMapping();
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath("/oauth2/access").UsingPost().WithBody("grant_type=password;username=u;password=p"))
|
.Given(Request.Create().WithPath("/oauth2/access").UsingPost().WithBody("grant_type=password;username=u;password=p"))
|
||||||
@@ -95,19 +95,55 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
.Given(Request.Create().WithPath("/partial").UsingPost().WithBody(new SimMetricsMatcher(new[] { "cat", "dog" })))
|
.Given(Request.Create().WithPath("/partial").UsingPost().WithBody(new SimMetricsMatcher(new[] { "cat", "dog" })))
|
||||||
.RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200"));
|
.RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200"));
|
||||||
|
|
||||||
http://localhost:8080/any/any?start=1000&stop=1&stop=2
|
// http://localhost:8080/any/any?start=1000&stop=1&stop=2
|
||||||
|
//server
|
||||||
|
// .Given(Request.Create().WithPath("/*").UsingGet())
|
||||||
|
// .WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||||
|
// .AtPriority(server.Mappings.Count() + 1)
|
||||||
|
// .RespondWith(Response.Create()
|
||||||
|
// .WithStatusCode(200)
|
||||||
|
// .WithHeader("Content-Type", "application/json")
|
||||||
|
// .WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
||||||
|
// .WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
||||||
|
// .WithTransformer()
|
||||||
|
// .WithDelay(TimeSpan.FromMilliseconds(100))
|
||||||
|
// );
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath("/*").UsingGet())
|
.Given(Request.Create()
|
||||||
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
.WithPath("/state1")
|
||||||
.AtPriority(server.Mappings.Count() + 1)
|
.UsingGet())
|
||||||
|
.InScenario("s1")
|
||||||
|
.WillSetStateTo("Test state 1")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
.WithBody("No state msg 1"));
|
||||||
.WithHeader("Content-Type", "application/json")
|
|
||||||
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
server
|
||||||
.WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
.Given(Request.Create()
|
||||||
.WithTransformer()
|
.WithPath("/foostate1")
|
||||||
.WithDelay(TimeSpan.FromMilliseconds(100))
|
.UsingGet())
|
||||||
);
|
.InScenario("s1")
|
||||||
|
.WhenStateIs("Test state 1")
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithBody("Test state msg 1"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.WithPath("/state2")
|
||||||
|
.UsingGet())
|
||||||
|
.InScenario("s2")
|
||||||
|
.WillSetStateTo("Test state 2")
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithBody("No state msg 2"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.WithPath("/foostate2")
|
||||||
|
.UsingGet())
|
||||||
|
.InScenario("s2")
|
||||||
|
.WhenStateIs("Test state 2")
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithBody("Test state msg 2"));
|
||||||
|
|
||||||
System.Console.WriteLine("Press any key to stop the server");
|
System.Console.WriteLine("Press any key to stop the server");
|
||||||
System.Console.ReadKey();
|
System.Console.ReadKey();
|
||||||
@@ -121,4 +157,4 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
System.Console.ReadKey();
|
System.Console.ReadKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,22 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// </value>
|
/// </value>
|
||||||
public int? Priority { get; set; }
|
public int? Priority { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scenario.
|
||||||
|
/// </summary>
|
||||||
|
public string Scenario { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execution state condition for the current mapping.
|
||||||
|
/// </summary>
|
||||||
|
public object WhenStateIs { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The next state which will be signaled after the current mapping execution.
|
||||||
|
/// In case the value is null state will not be changed.
|
||||||
|
/// </summary>
|
||||||
|
public object SetStateTo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the request.
|
/// Gets or sets the request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The scenario and state matcher.
|
/// The scenario and state matcher.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestMessageScenarioAndStateMatcher : IRequestMatcher
|
internal class RequestMessageScenarioAndStateMatcher : IRequestMatcher
|
||||||
{
|
{
|
||||||
///// <summary>
|
///// <summary>
|
||||||
///// Scenario.
|
///// Scenario.
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ namespace WireMock.Serialization
|
|||||||
Guid = mapping.Guid,
|
Guid = mapping.Guid,
|
||||||
Title = mapping.Title,
|
Title = mapping.Title,
|
||||||
Priority = mapping.Priority,
|
Priority = mapping.Priority,
|
||||||
|
Scenario = mapping.Scenario,
|
||||||
|
WhenStateIs = mapping.ExecutionConditionState,
|
||||||
|
SetStateTo = mapping.NextState,
|
||||||
Request = new RequestModel
|
Request = new RequestModel
|
||||||
{
|
{
|
||||||
ClientIP = clientIPMatchers != null && clientIPMatchers.Any() ? new ClientIPModel
|
ClientIP = clientIPMatchers != null && clientIPMatchers.Any() ? new ClientIPModel
|
||||||
|
|||||||
@@ -322,6 +322,13 @@ namespace WireMock.Server
|
|||||||
if (mappingModel.Priority != null)
|
if (mappingModel.Priority != null)
|
||||||
respondProvider = respondProvider.AtPriority(mappingModel.Priority.Value);
|
respondProvider = respondProvider.AtPriority(mappingModel.Priority.Value);
|
||||||
|
|
||||||
|
if (mappingModel.Scenario != null)
|
||||||
|
{
|
||||||
|
respondProvider = respondProvider.InScenario(mappingModel.Scenario);
|
||||||
|
respondProvider = respondProvider.WhenStateIs(mappingModel.WhenStateIs);
|
||||||
|
respondProvider = respondProvider.WillSetStateTo(mappingModel.SetStateTo);
|
||||||
|
}
|
||||||
|
|
||||||
respondProvider.RespondWith(responseBuilder);
|
respondProvider.RespondWith(responseBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user