Calling and Stubbing Multiple Services #284

Closed
opened 2025-12-29 15:19:42 +01:00 by adam · 3 comments
Owner

Originally created by @vermapraveen on GitHub (Jul 19, 2020).

First of all, thanks for this very useful lib. Planning to use in LoadTests, IntegrationTests.
I have started experiment with this, got question:

how to achieve multiple service call, as _mockServer.Urls gives only 1 url
My application makes multiple http calls to diff endpoints. currently I am able to stub 1 api call like below. I want to stub all of them so that I can test my app in isolation. please suggest.

       [Fact]
        public async Task ShouldAbleToGetMockRequest()
        {
            WebApiCaller sut = new WebApiCaller(_mockServer.Urls.First());
            StubResponseGenerator();

            var response = await sut.ExecuteInWebApi();
            response.Should().NotBeNull();
            response.Id1.Should().NotBeNull();
        }

        private void StubResponseGenerator()
        {
            var canned = new WebApiResponse
            {
                Id1 = "324234234",
                Id2 = "sdfsdfsdf",
                Data = new InternalData
                {
                    details = new[] { new Detail() }
                }
            };

            _mockServer
                  .Given(Request
                    .Create().WithPath("/GetAllDetails")
                    // The canned response will *only* be sent to the 
                    // request with the corresponding userName
                    //.WithParam("param1")
                    .UsingGet())
                  .RespondWith(
                    Response.Create()
                      .WithStatusCode(200)
                      .WithHeader("Content-Type", "application/json")
                    .WithBodyAsJson(canned)
                  );
        }
Originally created by @vermapraveen on GitHub (Jul 19, 2020). First of all, thanks for this very useful lib. Planning to use in LoadTests, IntegrationTests. I have started experiment with this, got question: how to achieve multiple service call, as **_mockServer.Urls gives only 1 url** My application makes multiple http calls to diff endpoints. currently I am able to stub 1 api call like below. I want to stub all of them so that I can test my app in isolation. please suggest. ``` C# [Fact] public async Task ShouldAbleToGetMockRequest() { WebApiCaller sut = new WebApiCaller(_mockServer.Urls.First()); StubResponseGenerator(); var response = await sut.ExecuteInWebApi(); response.Should().NotBeNull(); response.Id1.Should().NotBeNull(); } private void StubResponseGenerator() { var canned = new WebApiResponse { Id1 = "324234234", Id2 = "sdfsdfsdf", Data = new InternalData { details = new[] { new Detail() } } }; _mockServer .Given(Request .Create().WithPath("/GetAllDetails") // The canned response will *only* be sent to the // request with the corresponding userName //.WithParam("param1") .UsingGet()) .RespondWith( Response.Create() .WithStatusCode(200) .WithHeader("Content-Type", "application/json") .WithBodyAsJson(canned) ); } ```
adam added the question label 2025-12-29 15:19:42 +01:00
adam closed this issue 2025-12-29 15:19:42 +01:00
Author
Owner

@StefH commented on GitHub (Jul 19, 2020):

@vermapraveen
You can just use multiple URL's if you use the settings, see example:
https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L49

@StefH commented on GitHub (Jul 19, 2020): @vermapraveen You can just use multiple URL's if you use the settings, see example: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L49
Author
Owner

@StefH commented on GitHub (Aug 1, 2020):

@vermapraveen
Does this answer your question?

@StefH commented on GitHub (Aug 1, 2020): @vermapraveen Does this answer your question?
Author
Owner

@vermapraveen commented on GitHub (Aug 11, 2020):

yes, thanks

On Sat, Aug 1, 2020 at 9:55 AM Stef Heyenrath notifications@github.com
wrote:

@vermapraveen https://github.com/vermapraveen
Does this answer your question?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/WireMock-Net/WireMock.Net/issues/490#issuecomment-667543922,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABMDBFBSLEL7U5H5TXIPDRTR6QUH5ANCNFSM4PAROWJQ
.

--
Regards,
Praveen Verma

@vermapraveen commented on GitHub (Aug 11, 2020): yes, thanks On Sat, Aug 1, 2020 at 9:55 AM Stef Heyenrath <notifications@github.com> wrote: > @vermapraveen <https://github.com/vermapraveen> > Does this answer your question? > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > <https://github.com/WireMock-Net/WireMock.Net/issues/490#issuecomment-667543922>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ABMDBFBSLEL7U5H5TXIPDRTR6QUH5ANCNFSM4PAROWJQ> > . > -- Regards, Praveen Verma
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#284