Eddie Stanley
04/20/2023, 8:48 PMHttpRequestMessage
/ HttpResponseMessage
pairs.
NB: I'm aware of pact-stub-server
(link) however it's not quite what I'm looking for.
i.e. assume we've got some shared code to define the "Foo" interaction
private static void PopulateFooInteraction(IPactBuilderV3 pactBuilder)
{
pactBuilder
.UponReceiving("Request For Foo")
.WithRequest(HttpMethod.Get, "/foo/endpoint")
.WithHeader("x-correlation-id", "55dbb0b0-b0a0-4b2c-bee2-1cc77e8fba56")
.WillRespond()
.WithStatus(HttpStatusCode.OK)
.WithHeader("Content-Type", "application/json")
.WithJsonBody(Match.Type(new
{
Foo = "Bar"
}));
}
Then we exercise the client code that depends on the Foo interaction - it calls PopulateFooInteraction()
[Fact]
public async Task CheckFooInteraction()
{
var pact = Pact.V3("The.Consumer", "The.Provider", new PactConfig());
var pactBuilder = pact.UsingNativeBackend();
PopulateFooInteraction(pactBuilder);
await PactBuilder.VerifyAsync(async ctx =>
{
// .. code that consumes the stubbed responses coming back for Foo
});
}
Finally (somehow!) we harvest the messages implied by PopulateFooInteraction()
This is the missing bit
[Fact]
public void GetMessages()
{
var messageCapture = new MessageCapture();
PopulateFooInteraction(messageCapture);
IEnumerable<(HttpRequestMessage, HttpResponseMessage)> messages = messageCapture.CollectInteractions();
}
The end goal being to use these messages with something like mockhttp.Matt (pactflow.io / pact-js / pact-go)
mockhttp
mocks?Timothy Jones
04/22/2023, 4:09 AMTimothy Jones
04/22/2023, 4:10 AMTimothy Jones
04/22/2023, 4:11 AMTimothy Jones
04/22/2023, 4:12 AMTimothy Jones
04/22/2023, 4:25 AMTimothy Jones
04/22/2023, 4:25 AMTimothy Jones
04/22/2023, 4:26 AM