Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a051eea
feat: Interop calls and internal interface code to support plugins
adamrodger Sep 20, 2025
e250aa8
refactor: Remove unnecessary PactHandle constructor parameters
max-lancaster Oct 7, 2025
bc6b21f
refactor: Introduce AbstractPactBuilder for shared verify functionality
max-lancaster Oct 7, 2025
b191d6b
refactor: Use mock server port to write pact file
max-lancaster Oct 7, 2025
ab5204b
refactor: Refactor InitialiseLogging to shared LogToBuffer extension …
max-lancaster Sep 10, 2025
6ab9c0f
feat: Add support for synchronous plugin interactions
max-lancaster Oct 7, 2025
85548d1
test(grpc): Add Grpc Sample
max-lancaster Oct 7, 2025
5a97adc
refactor: Fetch logs from buffer to display plugin output in pact tests
max-lancaster Oct 8, 2025
82387ed
refactor: Make AbstractPactBuilder public so it can be extended by pl…
max-lancaster Oct 8, 2025
be20e84
chore: Some style and consistency tidy ups
adamrodger Jan 22, 2026
275da9f
refactor: Make AbstractPactBuilder internal again
max-lancaster Jan 26, 2026
8b6d35e
refactor: Make WithContent the terminal call on the plugin request bu…
max-lancaster Sep 14, 2026
bd9bd36
feat: prototype public HTTP content plugin interactions
YOU54F Oct 9, 2026
71aa458
feat: prototype asynchronous binary plugin messages
YOU54F Oct 9, 2026
3de6c44
ci: add protoc to linux arm64 wf
max-lancaster Oct 12, 2026
7887b3e
chore(deps): update sample to latest grpc/proto packages
max-lancaster Oct 12, 2026
44d88b5
chore(ffi): upgrade to pact-ffi 0.5.10 and regenerate fixtures with p…
max-lancaster Oct 12, 2026
0e8d48f
chore(ffi): use pact-ffi 0.5.10 for Avro async verification
YOU54F Oct 12, 2026
c7f45bb
ci: Install Pact plugins in separate step
max-lancaster Oct 12, 2026
6e28aef
ci: install protobuf plugin with pact-cli instead of shell script
max-lancaster Oct 12, 2026
0816188
chore(ffi): upgrade to libpact_ffi 0.5.12
YOU54F Oct 16, 2026
aa18dc5
feat: add consumer-side support for synchronous (request/response) me…
fabio-andre-rodrigues Sep 24, 2026
94a4d8f
Refine summary comment in IConfiguredSyncMessageVerifier
fabio-andre-rodrigues Sep 24, 2026
5f055c3
refactor: rename sync message Reify() members to GenerateContents()
fabio-andre-rodrigues Sep 24, 2026
4b3b0e0
docs: document synchronous (request/response) message support
fabio-andre-rodrigues Sep 24, 2026
2a7194d
Simplify messaging pacts documentation
fabio-andre-rodrigues Sep 24, 2026
e506c0a
fix: free the native string returned by Reify/GenerateContents
fabio-andre-rodrigues Sep 25, 2026
961d1c2
feat: assert the handler's response against the configured response
fabio-andre-rodrigues Sep 28, 2026
9f64d81
chore: move sync message driver into Drivers/Message
fabio-andre-rodrigues Sep 28, 2026
e02541e
fix: typed sync message metadata, applied after the response exists
fabio-andre-rodrigues Oct 8, 2026
c22a50c
test: verify sync messages end to end on pact_ffi 0.5.10
fabio-andre-rodrigues Oct 8, 2026
29b2119
feat: add WithReference to synchronous message interactions
fabio-andre-rodrigues Oct 8, 2026
bc34c5c
feat: match the sync handler's response against the response matchers
fabio-andre-rodrigues Oct 8, 2026
b946d4f
docs: describe how sync message responses are matched
fabio-andre-rodrigues Oct 8, 2026
c1acf8d
test: bump sync message fixtures to pact-ffi 0.5.12
fabio-andre-rodrigues Oct 16, 2026
b4c6aea
test(compat): merge pr551 and route plugin transport scenarios throug…
YOU54F Oct 29, 2026
ae0a158
test(compat): merge pr562 synchronous message DSL (pact_ffi 0.5.12)
YOU54F Oct 29, 2026
51d2bf4
test(compat): merge pr-avro-http and route HTTP plugin scenarios thro…
YOU54F Oct 29, 2026
03952ce
test(compat): merge pr-avro-async and route async plugin messages thr…
YOU54F Oct 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ jobs:
run: bash -c "build/download-native-libs.sh"
if: ${{ steps.cache.outputs.cache-hit != 'true' }}

- name: Install protoc (for grpc plugin test)
run: sudo apt-get install --yes protobuf-compiler
if: ${{ matrix.os == 'ubuntu-24.04-arm' }}

# Pre-install the plugins the tests need so that parallel test projects
# don't race each other auto-downloading them on first use
- name: Install Pact CLI
uses: pact-foundation/pact-cli@v0.10.8

- name: Install Pact plugins
run: pact plugin install --yes protobuf --version 0.8.0

- name: Restore
run: dotnet restore

Expand Down
69 changes: 69 additions & 0 deletions PactNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PactNet.Output.Xunit", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PactNet.Compatibility.Tests", "tests\PactNet.Compatibility.Tests\PactNet.Compatibility.Tests.csproj", "{063989E4-6B3A-4BA1-BDDD-72B105B9919C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Grpc", "Grpc", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcGreeter", "samples\Grpc\GrpcGreeter\GrpcGreeter.csproj", "{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcGreeterClient", "samples\Grpc\GrpcGreeterClient\GrpcGreeterClient.csproj", "{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcGreeterClient.Tests", "samples\Grpc\GrpcGreeterClient.Tests\GrpcGreeterClient.Tests.csproj", "{13756BC3-0750-E2AF-E1F0-565855A3E636}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcGreeter.Tests", "samples\Grpc\GrpcGreeter.Tests\GrpcGreeter.Tests.csproj", "{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pacts", "pacts", "{FB3A8B7F-7DA0-40A8-AFD1-FB0992FB9B2C}"
ProjectSection(SolutionItems) = preProject
samples\Grpc\pacts\grpc-greeter-client-grpc-greeter.json = samples\Grpc\pacts\grpc-greeter-client-grpc-greeter.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -169,6 +184,54 @@ Global
{063989E4-6B3A-4BA1-BDDD-72B105B9919C}.Release|x64.Build.0 = Release|Any CPU
{063989E4-6B3A-4BA1-BDDD-72B105B9919C}.Release|x86.ActiveCfg = Release|Any CPU
{063989E4-6B3A-4BA1-BDDD-72B105B9919C}.Release|x86.Build.0 = Release|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Debug|x64.ActiveCfg = Debug|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Debug|x64.Build.0 = Debug|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Debug|x86.ActiveCfg = Debug|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Debug|x86.Build.0 = Debug|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Release|Any CPU.Build.0 = Release|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Release|x64.ActiveCfg = Release|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Release|x64.Build.0 = Release|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Release|x86.ActiveCfg = Release|Any CPU
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69}.Release|x86.Build.0 = Release|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Debug|x64.ActiveCfg = Debug|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Debug|x64.Build.0 = Debug|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Debug|x86.ActiveCfg = Debug|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Debug|x86.Build.0 = Debug|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Release|Any CPU.Build.0 = Release|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Release|x64.ActiveCfg = Release|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Release|x64.Build.0 = Release|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Release|x86.ActiveCfg = Release|Any CPU
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A}.Release|x86.Build.0 = Release|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Debug|x64.ActiveCfg = Debug|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Debug|x64.Build.0 = Debug|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Debug|x86.ActiveCfg = Debug|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Debug|x86.Build.0 = Debug|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Release|Any CPU.Build.0 = Release|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Release|x64.ActiveCfg = Release|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Release|x64.Build.0 = Release|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Release|x86.ActiveCfg = Release|Any CPU
{13756BC3-0750-E2AF-E1F0-565855A3E636}.Release|x86.Build.0 = Release|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Debug|x64.ActiveCfg = Debug|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Debug|x64.Build.0 = Debug|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Debug|x86.ActiveCfg = Debug|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Debug|x86.Build.0 = Debug|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Release|Any CPU.Build.0 = Release|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Release|x64.ActiveCfg = Release|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Release|x64.Build.0 = Release|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Release|x86.ActiveCfg = Release|Any CPU
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -185,6 +248,12 @@ Global
{D8B75E48-6E45-468B-8049-B73823C14CB8} = {6663C12E-9912-40D0-9310-D119D1F6B023}
{02E265A1-A7A2-4106-8F6A-5027FDC3FC50} = {CF67D7A1-AE96-420B-9971-65E535B903E8}
{063989E4-6B3A-4BA1-BDDD-72B105B9919C} = {A117BBC6-60BB-4282-BF10-E616DE0AFAD0}
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {547DB478-460A-428F-9371-1D653CE85DB5}
{529F37CB-CDA0-6553-EAC9-8DAC2195ED69} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{917DAC61-55B4-D721-B1ED-B0E352E4CF1A} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{13756BC3-0750-E2AF-E1F0-565855A3E636} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{DC5371A0-7DE2-4CC5-D0E1-1DF6CB567FA6} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{FB3A8B7F-7DA0-40A8-AFD1-FB0992FB9B2C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C2CBC30C-92D4-4E3A-A5B8-1E5D4E938DFC}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ For writing messaging pacts instead of requests/response pacts, see the [messagi

![----------](https://raw.githubusercontent.com/pactumjs/pactum/master/assets/rainbow.png)

### Plugin Interactions

For protocols handled by a Pact plugin, such as gRPC, see the [plugin interactions guide](docs/plugin-interactions.md).

![----------](https://raw.githubusercontent.com/pactumjs/pactum/master/assets/rainbow.png)

## Compatibility

### Operating System
Expand Down
2 changes: 1 addition & 1 deletion build/download-native-libs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

FFI_VERSION="0.4.27"
FFI_VERSION="0.5.12"
FFI_BASE_URL="https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$FFI_VERSION"

GREEN="\e[32m"
Expand Down
35 changes: 35 additions & 0 deletions docs/async-plugin-interactions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Asynchronous Plugin Messages

Use `WithAsynchronousPluginInteractions` for content plugins without a transport
server. Configure a single message, then exercise the real consumer with generated
binary contents and metadata:

```csharp
using var pact = Pact.V4("consumer", "provider", config)
.WithAsynchronousPluginInteractions("avro", "0.1.3");

await pact.ExpectsToReceive("an Avro user")
.WithMetadata("topic", "users")
.WithContent("avro/binary", contents)
.VerifyAsync(message => ConsumeUserAsync(message.Contents, message.Metadata));
```

The contents dictionary follows the plugin's schema; for Avro it includes
`pact:avro`, `pact:record-name` and record field matching expressions. Message
contents are terminal. User metadata is applied after plugin configuration so
it is not replaced by the plugin's generated metadata.

`PluginMessage` contains copied binary contents, the media type and cloned JSON
metadata values. PactNet decodes the V4 base64 envelope, owns the reified native
string, writes the pact only after a successful callback, and cleans up plugins
when the pact builder is disposed. The existing JSON message API is unchanged.

This does not start Kafka/RabbitMQ or claim broker-delivery coverage. Producer
verification uses the normal verifier with a message provider or HTTP message
adapter. Review multi-message/generator/error paths and platform coverage before
publishing this prototype API.

Avro 0.1.3's single unlabelled interaction does not populate a synchronous message's
request/response fields with FFI 0.4.27. An opt-in native capability test records
that limitation. Distinct sync parts require an Avro plugin change; transport-free
binary request/response consumer verification also needs a separate PactNet API.
31 changes: 31 additions & 0 deletions docs/http-plugin-interactions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# HTTP Plugin Interactions

Content plugins can configure binary HTTP request and response bodies without
providing their own transport. The public `WithHttpPluginInteractions` entry point
creates HTTP interactions on a plugin-loaded pact and keeps native handles private.

```csharp
using var pact = Pact.V4("consumer", "provider", config)
.WithHttpPluginInteractions("avro", "0.1.3");

pact.UponReceiving("an Avro response")
.WithRequest(HttpMethod.Get, "/avro")
.WillRespondWithStatus(200)
.WithHeader("Content-Type", "avro/binary;record=User")
.WithContent("avro/binary", new Dictionary<string, object>
{
["pact:avro"] = schemaPath,
["pact:record-name"] = "User",
["id"] = "matching(integer, 1)",
["username"] = "matching(equalTo, 'alice')"
});
```

Use `Verify`/`VerifyAsync` with the real HTTP client and dispose the builder.
Request contents can be configured once before the response stage. Response
contents complete the interaction and can be configured once; later headers or
contents are rejected. The plugin owns its configuration schema and binary encoding.

PactNet still owns HTTP server startup, mismatches, logs, pact writing and plugin
cleanup. Provider verification uses the ordinary `PactVerifier`. This prototype
does not add asynchronous plugin message reification or expose FFI internals.
61 changes: 61 additions & 0 deletions docs/messaging-pacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,64 @@ public class StockEventGeneratorTests : IDisposable
}
}
```

Synchronous (Request/Response) Messages
----------------------------------------

> This is a V4-only pact feature (`Pact.V4(...)`). It's used for message flows that expect a reply
> to each request - for example an AsyncAPI operation with a `reply` block.

Unlike the fire-and-forget messages above, a synchronous message interaction has both a request and a
response. The consumer specifies the expected request and response content, PactNet feeds the
generated request (matchers stripped, generators applied) to your handler under test, and checks the
value your handler returns against the response's matchers before writing the pact file. For example
`Match.Type("shipped")` accepts any string, `Match.Integer(12)` any integer, `Match.Decimal(12.5)` any
decimal, and `Match.Regex(...)` any value in the given format, such as a datetime. Values without a
matcher must be equal, and extra properties in the response are allowed.

In code, this is:

```csharp
public class OrderLookupConsumerTests
{
private readonly ISyncMessagePactBuilderV4 messagePact;

public OrderLookupConsumerTests(ITestOutputHelper output)
{
IPactV4 v4 = Pact.V4("Order Lookup Consumer", "Order Lookup Producer", new PactConfig
{
PactDir = "../../../pacts/",
Outputters = new[]
{
new XUnitOutput(output)
}
});

this.messagePact = v4.WithSynchronousMessageInteractions();
}

[Fact]
public void LooksUpAnOrder()
{
this.messagePact
.ExpectsToReceive("a request for an order")
.Given("order 1234 exists")
.WithReference("AsyncAPI", "operationId", "getOrder")
.WithRequestMetadata("priority", 1)
.WithRequestJsonContent(new { OrderId = Match.Type("1234") })
.WithResponseMetadata("replyTo", Match.Regex("orders-reply", "^orders-"))
.WithResponseJsonContent(new { Status = Match.Type("shipped") })
.Verify<OrderRequest, OrderStatus>(request =>
{
OrderStatus response = this.orderLookupClient.Lookup(request);
return response;
});
}
}
```

Metadata values are serialised as JSON, so they keep their type (`1` is a number, `"1"` is a string) and can be
matchers. `WithReference` links the interaction to an external resource such as an AsyncAPI operation; it's
written to the pact under `comments.references.{group}.{name}`.

As with fire-and-forget messages, a pact file is written to disk once all consumer tests have passed
127 changes: 127 additions & 0 deletions docs/plugin-interactions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
Plugin Interactions
===================

Pact [plugins](https://docs.pact.io/plugins) extend Pact to protocols and content types beyond HTTP and
plain messaging, for example gRPC/protobuf or CSV. PactNet exposes a "raw" plugin API which works with any
plugin, so that a new plugin can be used before a friendlier wrapper library exists for it.

Currently only **synchronous** plugin interactions are supported: a single request with one or more
responses, such as a gRPC unary call. Asynchronous (message-style) plugin interactions are not yet exposed.

Prerequisites
-------------

The plugin itself must be installed on the machine running the tests, on both the consumer and provider side.
Plugins live under `~/.pact/plugins/<name>-<version>` and are installed with the
[plugin CLI](https://docs.pact.io/implementation_guides/pact_plugins/cli), for example:

```shell
pact-plugin-cli install https://github.com/pact-foundation/pact-protobuf-plugin/releases/tag/v-0.8.0
```

Sample
------

See the [gRPC sample](../samples/Grpc/) for a working consumer and provider using the protobuf plugin.

Consumer Tests
--------------

A plugin pact is created from a V4 pact by naming the plugin, its version and the transport the mock
server should use. Each interaction is then defined by handing the plugin a content type it understands
plus a dictionary describing the interaction. The plugin, not PactNet, decides what that dictionary must
contain and how it is split into a request and its responses.

```csharp
public class GreeterClientTests : IDisposable
{
private readonly ISynchronousPluginPactBuilderV4 pact;

public GreeterClientTests(ITestOutputHelper output)
{
IPactV4 v4 = Pact.V4("Greeter Client", "Greeter Service", new PactConfig
{
PactDir = "../../../pacts/",
Outputters = new[] { new XunitOutput(output) }
});

this.pact = v4.WithSynchronousPluginInteractions("protobuf", "0.8.0", transport: "grpc");
}

[Fact]
public async Task SayHello_ReturnsGreeting()
{
var content = new Dictionary<string, object>
{
["pact:proto"] = Path.GetFullPath("../../../Protos/greet.proto"),
["pact:proto-service"] = "Greeter/SayHello",
["pact:content-type"] = "application/protobuf",
["request"] = new { name = "matching(equalTo, 'foo')" },
["response"] = new { message = "matching(equalTo, 'Hello foo')" }
};

this.pact
.UponReceiving("a request to say hello")
.Given("the greeter is available")
.WithContent("application/grpc", content);

await this.pact.VerifyAsync(async ctx =>
{
var client = new GreeterClient(ctx.MockServerUri);

string greeting = await client.SayHello("foo");

greeting.Should().Be("Hello foo");
});
}

public void Dispose() => this.pact.Dispose();
}
```

`Verify`/`VerifyAsync` starts a mock server using the requested transport, runs your client against it, checks
every interaction was matched, writes the pact file and prints the mock server logs, exactly as for HTTP pacts.
Dispose the builder when the test finishes so the underlying plugin resources are released.

### Building an interaction

Each call to `UponReceiving` starts a new interaction and a pact may contain as many as you need. The builder
has two kinds of call:

- `Given(...)` adds provider states and may be repeated.
- `WithContent(contentType, content)` sets the plugin contents. **It completes the interaction and must be the
last call.** It returns nothing, so it cannot be chained further.

`WithContent` is deliberately single-shot. The plugin splits one contents dictionary into the request and its
responses. If contents were set a second time on the same interaction the request would be replaced but the
response would be appended, leaving the interaction with two responses, so PactNet does not allow it. Define a
second `UponReceiving` instead.

### Multiple interactions on one method

The gRPC mock server tracks whether each service method was called, not each interaction. If two interactions
target the same `Service/Method` and your client only exercises one of them, verification still passes. Give
interactions on the same method distinguishable requests and make sure your test calls each of them.

Provider Tests
--------------

Provider verification uses the normal `PactVerifier`. Point it at the running gRPC server as the HTTP endpoint;
the transport recorded in the pact file tells the verifier to hand the interaction to the plugin.

```csharp
this.verifier
.WithHttpEndpoint(new Uri("http://localhost:5000"))
.WithFileSource(new FileInfo(pactPath))
.Verify();
```

Writing a plugin wrapper
------------------------

A wrapper library gives a plugin a protocol-specific fluent API on top of the raw builders, without needing
any access to PactNet internals. Wrap `ISynchronousPluginPactBuilderV4`, have your own request/response builders
assemble the contents dictionary, and call `WithContent` once when the user has finished describing the
interaction. Delegate `Verify`, `VerifyAsync` and `Dispose` straight through. The
[`PactNet.Extensions.Grpc`](https://github.com/pact-foundation/pact-net/pull/548) package is the reference
implementation of this pattern.
Loading