mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 06:13:35 +01:00
123 lines
4.2 KiB
Plaintext
123 lines
4.2 KiB
Plaintext
var server = WireMockServer.Start();
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("GET")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo", false, WireMock.Matchers.MatchOperator.Or))
|
|
.WithParam("test", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, "abc"))
|
|
)
|
|
.WithGuid("41372914-1838-4c67-916b-b9aacdd096ce")
|
|
.RespondWith(Response.Create()
|
|
.WithBody("{ msg: \"Hello world!\"}")
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("POST")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post1", false, WireMock.Matchers.MatchOperator.Or))
|
|
.WithBody(new JsonMatcher(
|
|
value: new
|
|
{
|
|
Request = "Hello?"
|
|
},
|
|
ignoreCase: false,
|
|
regex: false
|
|
))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931001")
|
|
.RespondWith(Response.Create()
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("POST")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post2", false, WireMock.Matchers.MatchOperator.Or))
|
|
.WithBody(new JsonMatcher(
|
|
value: new
|
|
{
|
|
city = "Amsterdam",
|
|
country = "The Netherlands"
|
|
},
|
|
ignoreCase: false,
|
|
regex: false
|
|
))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931002")
|
|
.RespondWith(Response.Create()
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("POST")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/form-urlencoded", false, WireMock.Matchers.MatchOperator.Or))
|
|
.WithHeader("Content-Type", "application/x-www-form-urlencoded", true)
|
|
.WithBody("name=John Doe")
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931003")
|
|
.RespondWith(Response.Create()
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("GET")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/regex", false, WireMock.Matchers.MatchOperator.Or))
|
|
.WithParam("foo", new RegexMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, ".*", false, true, WireMock.Matchers.MatchOperator.Or))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931004")
|
|
.RespondWith(Response.Create()
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("GET")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/todo/items", false, WireMock.Matchers.MatchOperator.Or))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931005")
|
|
.InScenario("To do list")
|
|
.WhenStateIs("TodoList State Started", 2)
|
|
.RespondWith(Response.Create()
|
|
.WithBody("Buy milk")
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("GET")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/delay", false, WireMock.Matchers.MatchOperator.Or))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931006")
|
|
.RespondWith(Response.Create()
|
|
.WithDelay(1000)
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("GET")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/random-delay", false, WireMock.Matchers.MatchOperator.Or))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931007")
|
|
.RespondWith(Response.Create()
|
|
.WithRandomDelay(1234, 60000)
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("GET")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931008")
|
|
.WithProbability(0.1)
|
|
.RespondWith(Response.Create()
|
|
.WithStatusCode(300)
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingMethod("GET")
|
|
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
|
)
|
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931009")
|
|
.WithProbability(0.9)
|
|
.RespondWith(Response.Create()
|
|
.WithStatusCode(201)
|
|
);
|
|
|