Open tl-madhulika-mitra opened 2 years ago
I don't believe so.
You could achieve this by adding some custom middleware to your test application that can transform the incoming request.
Thank you @mefellows , @adamrodger- Could you let me know if we plan to add this for the upcoming versions, as currently we are adding some heavy middleware to support our chained requests.
I don't fully understand the feature request if I'm honest.
It would be really helpful if you could create a proposal for the API changes with an explanation of what the changes do, and then we can discuss about feasibility/design.
For example, see issue #392 for a good format for proposing changes.
to support our chained requests.
I'd be keen to understand this use case also. "chained requests" is an anti-pattern as far as contract testing is concerned, each request/response should be able to be tested in isolation.
Whilst the feature of essentially proxying incoming/outgoing bodies is doable, I'd be wary of adding features that readily enables improper use of the tool that will lead to future challenges for all parties.
Closed due to inactivity
Please consider reopening this issue. The problem is described in the blog post: https://pactflow.io/blog/injecting-values-from-provider-states/ .
Assume I have the following setup:
_pactBuilder
.UponReceiving("A POST request to process the entity")
.Given("An entity {id} is created", new Dictionary<string, string> { ["id"] = entityId })
.WithRequest(HttpMethod.Post, $"/entities/{entityId}/process")
.WithHeader("X-Api-Key", ApiKey)
.WillRespond()
.WithStatus(HttpStatusCode.OK)
.WithJsonBody(new
{
Result = Match.Regex("123456789012", "\\w{13}"),
});
The problem is that the entityId
is auto-generated, I cannot easily force it via Given step.
Therefore, it would be nice to be able to return that auto-generated value from Given state, and make it accessible in VerifyAsync, e.g.
await _pactBuilder.VerifyAsync(async ctx =>
{
// Injected from provider state
var entityId = ctx.FromProviderState("entityId");
await ProcessEntity(entityId);
});
Hi , I found a post for JVM https://pactflow.io/blog/injecting-values-from-provider-states/ where we can modify the request before the validation, but is there a mechanism in C#?