From 3b0429e8c0d4b96bf398915a9f609b2bf8f8357f Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 29 Jan 2017 13:51:56 +0100 Subject: [PATCH] Created WireMock as a standalone process (markdown) --- WireMock-as-a-standalone-process.md | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 WireMock-as-a-standalone-process.md diff --git a/WireMock-as-a-standalone-process.md b/WireMock-as-a-standalone-process.md new file mode 100644 index 0000000..d6abe45 --- /dev/null +++ b/WireMock-as-a-standalone-process.md @@ -0,0 +1,60 @@ +##WireMock as a standalone process +This is quite straight forward to launch a mock server within a console application. + +```c# +static void Main(string[] args) +{ + int port; + if (args.Length == 0 || !int.TryParse(args[0], out port)) + port = 8080; + + var server = FluentMockServer.Start(port); + Console.WriteLine("FluentMockServer running at {0}", server.Port); + + server + .Given(Request.Create().WithUrl(u => u.Contains("x")).UsingGet()) + .RespondWith(Response.Create() + .WithStatusCode(200) + .WithHeader("Content-Type", "application/json") + .WithBody(@"{ ""result"": ""/x with FUNC 200""}")); + + server + .Given(Request.Create().WithUrl("/*").UsingGet()) + .RespondWith(Response.Create() + .WithStatusCode(200) + .WithHeader("Content-Type", "application/json") + .WithBody(@"{ ""msg"": ""Hello world!""}") + ); + + server + .Given(Request.Create().WithUrl("/data").UsingPost().WithBody(b => b.Contains("e"))) + .RespondWith(Response.Create() + .WithStatusCode(201) + .WithHeader("Content-Type", "application/json") + .WithBody(@"{ ""result"": ""data posted with FUNC 201""}")); + + server + .Given(Request.Create().WithUrl("/data").UsingPost()) + .RespondWith(Response.Create() + .WithStatusCode(201) + .WithHeader("Content-Type", "application/json") + .WithBody(@"{ ""result"": ""data posted with 201""}")); + + server + .Given(Request.Create().WithUrl("/data").UsingDelete()) + .RespondWith(Response.Create() + .WithStatusCode(200) + .WithHeader("Content-Type", "application/json") + .WithBody(@"{ ""result"": ""data deleted with 200""}")); + + Console.WriteLine("Press any key to stop the server"); + Console.ReadKey(); + + Console.WriteLine("Displaying all requests"); + var allRequests = server.RequestLogs; + Console.WriteLine(JsonConvert.SerializeObject(allRequests, Formatting.Indented)); + + Console.WriteLine("Press any key to quit"); + Console.ReadKey(); +} +``` \ No newline at end of file