mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
How to best leverage WireMock #368
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @The-Futurist on GitHub (Oct 9, 2021).
We use this REST service - Valence, here's a typical endpoint we use.
To do this I created (several years ago) a T4 based solution, with this I can define an endpoint in XML and the T4 code generator generates classes and methods that expose the endpoint as a pure .Net method.
This approach works extremely well and enables us to add definitions for endpoints that we've not yet used, takes less than 15 minutes to add a new XML definition and rebuild the code.
Most of the JSON data structures (there are a great many) exist as concrete .Net classes - e.g. this for example - in the solution so the developer sees a strongly typed model of the entire API.
So that's the background, I want to be able to change the code so that we can capture outbound requests and inbound responses and devise a way to have the API operate from this captured data, I'm not sure how I can leverage WireMock for this of even if that is a good use case for it.
The .Net API is a .Net Standard 2.0 nuget package at this stage so there's no need for any legacy or .Net Framework stuff.
The actual network send/recv is done using RestSharp and is not particularly complex.
Any thoughts, guidance much appreciated!
Thanks
@StefH commented on GitHub (Oct 10, 2021):
Good morning @Korporal ,
I've trying to understand what you want.
It is something like:
And now you want something like?
(If possible provide an example project or make a picture of the flow.)
@The-Futurist commented on GitHub (Oct 10, 2021):
@StefH - To soon for an code as such, also I'm a bit of a novice with respect to mocking which is part of the reason for the question.
I'd like to modify the Valence API so it can run against the "real" internet as it does now, but also against a "simulation" or "mock" of the service, so that we can issues data requests but have the data pulled from a log.
So instead of HTTP requests going to the internet to their remote service, they instead get intercept and the response is pulled from a log.
I say log because I can imagine running a test against the real service and logging what goes out and what comes back, for example an invocation of this endpoint will see a response that contains this data:
this data (what is sent and it's response) could be logged and that log later used by something - Wiremock? - to make it look as if this was a genuine send/response.
So I'm not clear to what extent Wiremock can be used here, in what way, I have no idea how the "logging" (aka "recording") of request/response could be done or whether Wiremock can do that or how Wiremock could leverage said log later.
For all I know I've totally misunderstood what Wiremock is or the way I'm even envisaging this is all wrong!
@The-Futurist commented on GitHub (Oct 10, 2021):
Here's a crude representation of what I thinking:
@The-Futurist commented on GitHub (Oct 10, 2021):
The Valence class library is our code, a .Net standard library, it uses RestSharp. I envisage some mechanism that can intercept the traffic and log to a file, invisible to the class library to all intents and purposes.
The diagram is intended to show that the Valence Class Library can interact either with "Logging, Internet" or with "Mocked Service/Log".
Then I envisage being able to run the same app which calls into the Valence class library as before but this time the class library (perhaps via Wiremock) is not interacting with real internet but with log/Wiremock and although it issues a GET that becomes a lookup into the log and the canned response is returned, again perhaps this can even be done without the Valence class library "knowing"...
As I mentioned I am a novice with mocking so if some of what I' envisaging seems silly that's the reason!
@StefH commented on GitHub (Oct 11, 2021):
Hello @Korporal ,
This is possible, I've change you picture to make it more compliant to the terms used within WireMock.Net:

Switching between the two modes (1 and 2) is just a matter of using a different endpoint or port.
@StefH commented on GitHub (Oct 21, 2021):
Hello @Korporal, does this answer your question?
@StefH commented on GitHub (Oct 27, 2021):
@Korporal
I'll close this now.
If you have still a question, just reply here and I can reopen this.