mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Save proxied requests during an XUnit integration test? #572
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 @dahlsailrunner on GitHub (Feb 13, 2024).
Originally assigned to: @StefH on GitHub.
I have an API that I have written integration tests for using XUnit and a custom implementation of
WebApplicationFactory<TEntryPoint>. If I make calls to that through a wiremock proxy with "save mappings" turned on the proxying does indeed work but I don't see any mappings getting saved anywhere.If I run the same code and settings with a console app against the actual running API the mappings get saved to files just fine.
The test project would look something like this: https://github.com/dahlsailrunner/testing-examples/tree/main/01-simple-api/SimpleApi.Tests
But I would simply run the
Clienthttp requests through the proxy. Should this be possible? I just don't get any saved mappings.I can provide an actual project / tests if it seems like this should be possible and such an example would be helpful.
@StefH commented on GitHub (Feb 23, 2024):
@dahlsailrunner
This xunit test does what you need?
ce833c1f29/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.GetMappingsAsync.cs@dahlsailrunner commented on GitHub (Feb 25, 2024):
I had a quick look and I don't think that's what I'm looking for. Will review more closely soon and post a sample with more precise details if the the above is indeed not what I'm after. Thanks for the response and will keep you posted.
@StefH commented on GitHub (Mar 11, 2024):
@dahlsailrunner : did you time to verify?
@dahlsailrunner commented on GitHub (Mar 11, 2024):
I have not but should have time this week. Thanks for the reminder here - I will let you know by Sunday for sure.
@dahlsailrunner commented on GitHub (Mar 12, 2024):
I checked - I don't think it does what I'm looking for but I've got a repo that lays things out (and tried the admin api rest client too).
I'm fairly certain you should be able to clone this repo: https://github.com/dahlsailrunner/automation-testing-strategies-aspnet/tree/main
and then run/debug the tests.
The
tests/CarvedRock.InnerLoop.Tests/ProductControllerTests.csfile contains some simple tests against an API that should pass. As the calls to the API endpoints happen during the test run, I was hoping to be able to record those results so that they could be used as the wiremock setup for a UI that calls that API.The code that invokes the WireMock call starts in the
Utilities/BaseTest.csfile, but all of the interesting stuff is in theUtilities/SharedFixture.csfile (seeProxyAndRecordApiCallsmethod andDisposeAsync).If you put a breakpoint in the
DisposeAsyncmethod I think you'll see that the only mapping I get back is the "map everything" one and nothing about the proxied api calls made in the tests.I was actually trying to get the proxied calls saved to a file but couldn't find the file(s) anywhere after the test run.
If there's a way to do this, it would be great. Then we could "run a test against the API", then use the recorded API test calls as the wiremock back end for at least some of the tests from a UI that calls the API that was just tested.
Thanks in advance for any help / guidance here.
@StefH commented on GitHub (Mar 12, 2024):
I did have a quick look, however I don't understand yet what you are trying to test, because when I comment out WireMock, all tests still work fine?
Like:
@dahlsailrunner commented on GitHub (Mar 12, 2024):
I'm trying to record the calls in the test. Then use those calls later. There is no need for wire mock in this set of tests other than to record the calls for a test that will use these calls (with WireMock) -- recording this test would simply let me avoid hand-coding the mapping. Does that make sense?