Define multiple scenarios for the same url path and switch to it at run-time? #186

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

Originally created by @dnovhorodov on GitHub (Jun 25, 2019).

Hello guys,

In WireMock.NET there is a possibility to define scenarios which acts as a state machine for requests. Very nice 👍

Is there possibility at run-time (hosted by Azure/IIS) route requests to specific pre-loaded scenarios based on some request attribute like header, param, etc.?
Or at least switch mock server to use specific scenario for specific url path (in case of N scenarios for same path) by calling __admin endpoints ?

Currently I found only __admin endpoints to manage collection of scenarios on the server like POST,GET,DELETE. But nothing like ability to switch to use some scenario depending on... request attribute or calling some __admin endpoint.

So my questions:

  1. Could that behavior be achieved by dynamically managing Scenarios collection on the server?
    Say on top of wiremock server there some other API running and exposing endpoint like POST api/scenarios/{name}/use which will clear Scenarios collection and load only scenario with {name}

  2. Is it possible to do some side-effect action (Action<> like) on .Given(..) when creating mappings?

Originally created by @dnovhorodov on GitHub (Jun 25, 2019). Hello guys, In **WireMock.NET** there is a possibility to define scenarios which acts as a state machine for requests. Very nice :+1: Is there possibility at run-time (hosted by Azure/IIS) route requests to specific pre-loaded scenarios based on some request attribute like header, param, etc.? Or at least switch mock server to use specific scenario for specific url path (in case of N scenarios for same path) by calling __admin endpoints ? Currently I found only __admin endpoints to manage collection of scenarios on the server like POST,GET,DELETE. But nothing like ability to switch to use some scenario depending on... request attribute or calling some __admin endpoint. So my questions: 1. Could that behavior be achieved by dynamically managing Scenarios collection on the server? Say on top of wiremock server there some other API running and exposing endpoint like POST api/scenarios/{name}/use which will clear Scenarios collection and load only scenario with {name} 2. Is it possible to do some side-effect action (Action<<T>> like) on .Given(..) when creating mappings?
adam added the question label 2025-12-29 08:23:36 +01:00
adam closed this issue 2025-12-29 08:23:36 +01:00
Author
Owner

@dnovhorodov commented on GitHub (Jul 2, 2019):

Hey mates,

Still didn't get any answers, but I found how to inject custom Owin middleware if you need to have custom behavior. In my case I do it like this:

// Add access to IFluentMockServerSettings
var settings = configuration.GetSection("FluentMockServerSettings").Get<FluentMockServerSettings>();
settings.PreWireMockMiddlewareInit = app => 
{
    ((IApplicationBuilder)app).UseMiddleware<MyCustomMiddleware>();
};
services.AddSingleton<IFluentMockServerSettings>(settings);
@dnovhorodov commented on GitHub (Jul 2, 2019): Hey mates, Still didn't get any answers, but I found how to inject custom Owin middleware if you need to have custom behavior. In my case I do it like this: ``` c# // Add access to IFluentMockServerSettings var settings = configuration.GetSection("FluentMockServerSettings").Get<FluentMockServerSettings>(); settings.PreWireMockMiddlewareInit = app => { ((IApplicationBuilder)app).UseMiddleware<MyCustomMiddleware>(); }; services.AddSingleton<IFluentMockServerSettings>(settings); ```
Author
Owner

@StefH commented on GitHub (Jul 2, 2019):

This is indeed also an option to introduce custom logic. I'll add this to the wiki.

@StefH commented on GitHub (Jul 2, 2019): This is indeed also an option to introduce custom logic. I'll add this to the wiki.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#186