Doc: Update outdated #168

Closed
opened 2025-12-29 08:23:16 +01:00 by adam · 2 comments
Owner

Originally created by @pmiossec on GitHub (Mar 26, 2019).

Originally assigned to: @StefH on GitHub.

Please update the documentation for the page WireMock as a standalone process.

The good content should be something like (it works at least for me):


        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}", string.Join(",", server.Ports));

            // Order of rules matters. First matching is taken.
            server
                .Given(Request.Create().WithPath(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().WithPath("/*").UsingGet())
                .RespondWith(Response.Create()
                    .WithStatusCode(200)
                    .WithHeader("Content-Type", "application/json")
                    .WithBody(@"{ ""msg"": ""Hello world!""}")
                );

            server
                .Given(Request.Create().WithPath("/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().WithPath("/data").UsingPost())
                .RespondWith(Response.Create()
                    .WithStatusCode(201)
                    .WithHeader("Content-Type", "application/json")
                    .WithBody(@"{ ""result"": ""data posted with 201""}"));

            server
                .Given(Request.Create().WithPath("/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.LogEntries;
            Console.WriteLine(JsonConvert.SerializeObject(allRequests, Formatting.Indented));

            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
Originally created by @pmiossec on GitHub (Mar 26, 2019). Originally assigned to: @StefH on GitHub. Please update the documentation for the page [WireMock as a standalone process](https://github.com/WireMock-Net/WireMock.Net/wiki/WireMock-as-a-standalone-process#option-3--coding-yourself). The good content should be something like (it works at least for me): ```csharp 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}", string.Join(",", server.Ports)); // Order of rules matters. First matching is taken. server .Given(Request.Create().WithPath(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().WithPath("/*").UsingGet()) .RespondWith(Response.Create() .WithStatusCode(200) .WithHeader("Content-Type", "application/json") .WithBody(@"{ ""msg"": ""Hello world!""}") ); server .Given(Request.Create().WithPath("/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().WithPath("/data").UsingPost()) .RespondWith(Response.Create() .WithStatusCode(201) .WithHeader("Content-Type", "application/json") .WithBody(@"{ ""result"": ""data posted with 201""}")); server .Given(Request.Create().WithPath("/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.LogEntries; Console.WriteLine(JsonConvert.SerializeObject(allRequests, Formatting.Indented)); Console.WriteLine("Press any key to quit"); Console.ReadKey(); } ```
adam added the question label 2025-12-29 08:23:16 +01:00
adam closed this issue 2025-12-29 08:23:17 +01:00
Author
Owner

@StefH commented on GitHub (Mar 26, 2019):

Thanks.

Done.

@StefH commented on GitHub (Mar 26, 2019): Thanks. Done.
Author
Owner

@pmiossec commented on GitHub (Mar 26, 2019):

thanks.

@pmiossec commented on GitHub (Mar 26, 2019): thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#168