diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ca135af5..688c5d68 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -20,6 +20,7 @@ jobs:
build-dotnet:
name: "Build and Test (dotnet)"
strategy:
+ fail-fast: false
matrix:
os:
- windows-latest
diff --git a/build/download-native-libs.sh b/build/download-native-libs.sh
index c3ace891..295f3f4e 100755
--- a/build/download-native-libs.sh
+++ b/build/download-native-libs.sh
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
-FFI_VERSION="0.4.27"
-FFI_BASE_URL="https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$FFI_VERSION"
+FFI_VERSION="0.5.13-rc.1"
+FFI_BASE_URL="https://github.com/YOU54F/pact-reference/releases/download/libpact_ffi-v$FFI_VERSION"
GREEN="\e[32m"
YELLOW="\e[33m"
diff --git a/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json b/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json
index b6f1a702..ca070b0c 100644
--- a/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json
+++ b/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json
@@ -158,8 +158,8 @@
],
"metadata": {
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "4.0"
diff --git a/src/PactNet.Abstractions/Exceptions/PactMockServerMismatchException.cs b/src/PactNet.Abstractions/Exceptions/PactMockServerMismatchException.cs
new file mode 100644
index 00000000..aee25cd1
--- /dev/null
+++ b/src/PactNet.Abstractions/Exceptions/PactMockServerMismatchException.cs
@@ -0,0 +1,39 @@
+using System;
+
+namespace PactNet.Exceptions
+{
+ ///
+ /// The mock server received requests which didn't match the configured interactions, or didn't receive the
+ /// expected requests
+ ///
+ [Serializable]
+ public class PactMockServerMismatchException : PactFailureException
+ {
+ ///
+ /// Mismatches reported by the mock server, as a JSON array (the format produced by pactffi_mock_server_mismatches)
+ ///
+ public string Mismatches { get; }
+
+ ///
+ /// Log lines captured for this mock server (the format produced by pactffi_mock_server_logs)
+ ///
+ ///
+ /// The level of these logs is set by the first time a pact is created
+ /// in the process, because the native logger can only be initialised once
+ ///
+ public string MockServerLogs { get; }
+
+ ///
+ /// Initialises a new instance of the class.
+ ///
+ /// The message that describes the error
+ /// Mismatches reported by the mock server, as a JSON array
+ /// Log lines captured for this mock server
+ public PactMockServerMismatchException(string message, string mismatches, string mockServerLogs)
+ : base(message)
+ {
+ this.Mismatches = mismatches;
+ this.MockServerLogs = mockServerLogs;
+ }
+ }
+}
diff --git a/src/PactNet.Abstractions/IRequestBuilder.cs b/src/PactNet.Abstractions/IRequestBuilder.cs
index 357ea8ab..f3a2041b 100644
--- a/src/PactNet.Abstractions/IRequestBuilder.cs
+++ b/src/PactNet.Abstractions/IRequestBuilder.cs
@@ -58,6 +58,30 @@ public interface IRequestBuilderV2
/// Fluent builder
IRequestBuilderV2 WithHeader(string key, IMatcher matcher);
+ ///
+ /// Add a request header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV2 WithHeader(string key, params string[] values);
+
+ ///
+ /// Add a request header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV2 WithHeader(string key, params IMatcher[] matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -175,6 +199,30 @@ public interface IRequestBuilderV3
/// Fluent builder
IRequestBuilderV3 WithHeader(string key, IMatcher matcher);
+ ///
+ /// Add a request header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV3 WithHeader(string key, params string[] values);
+
+ ///
+ /// Add a request header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV3 WithHeader(string key, params IMatcher[] matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -294,6 +342,30 @@ public interface IRequestBuilderV4
/// Fluent builder
IRequestBuilderV4 WithHeader(string key, IMatcher matcher);
+ ///
+ /// Add a request header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV4 WithHeader(string key, params string[] values);
+
+ ///
+ /// Add a request header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV4 WithHeader(string key, params IMatcher[] matchers);
+
///
/// Set a body which is serialised as JSON
///
diff --git a/src/PactNet.Abstractions/IResponseBuilder.cs b/src/PactNet.Abstractions/IResponseBuilder.cs
index c15e1713..3b3e5ef0 100644
--- a/src/PactNet.Abstractions/IResponseBuilder.cs
+++ b/src/PactNet.Abstractions/IResponseBuilder.cs
@@ -39,6 +39,30 @@ public interface IResponseBuilderV2
/// Fluent builder
IResponseBuilderV2 WithHeader(string key, IMatcher matcher);
+ ///
+ /// Add a response header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV2 WithHeader(string key, params string[] values);
+
+ ///
+ /// Add a response header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV2 WithHeader(string key, params IMatcher[] matchers);
+
///
/// Set a response body which is serialised as JSON
///
@@ -98,6 +122,30 @@ public interface IResponseBuilderV3
/// Fluent builder
IResponseBuilderV3 WithHeader(string key, IMatcher matcher);
+ ///
+ /// Add a response header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV3 WithHeader(string key, params string[] values);
+
+ ///
+ /// Add a response header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV3 WithHeader(string key, params IMatcher[] matchers);
+
///
/// Set a response body which is serialised as JSON
///
@@ -157,6 +205,30 @@ public interface IResponseBuilderV4
/// Fluent builder
IResponseBuilderV4 WithHeader(string key, IMatcher matcher);
+ ///
+ /// Add a response header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV4 WithHeader(string key, params string[] values);
+
+ ///
+ /// Add a response header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV4 WithHeader(string key, params IMatcher[] matchers);
+
///
/// Set a response body which is serialised as JSON
///
diff --git a/src/PactNet/PactBuilder.cs b/src/PactNet/PactBuilder.cs
index fe311c88..fc42c181 100644
--- a/src/PactNet/PactBuilder.cs
+++ b/src/PactNet/PactBuilder.cs
@@ -73,13 +73,17 @@ internal RequestBuilder UponReceiving(string description)
/// Verify the configured interactions
///
/// Action to perform the real interactions against the mock driver
- /// Failed to verify the interactions
+ /// Failed to verify the interactions
public void Verify(Action interact)
{
Guard.NotNull(interact, nameof(interact));
using IMockServerDriver mockServer = this.StartMockServer();
+ // reading the logs drains the FFI buffer, so read them at most once
+ string logs = null;
+ string ReadLogs() => logs ??= mockServer.MockServerLogs();
+
try
{
interact(new ConsumerContext
@@ -87,11 +91,11 @@ public void Verify(Action interact)
MockServerUri = mockServer.Uri
});
- this.VerifyInternal(mockServer);
+ this.VerifyInternal(mockServer, ReadLogs);
}
finally
{
- this.PrintLogs(mockServer);
+ this.PrintLogs(ReadLogs());
}
}
@@ -99,13 +103,17 @@ public void Verify(Action interact)
/// Verify the configured interactions
///
/// Action to perform the real interactions against the mock driver
- /// Failed to verify the interactions
+ /// Failed to verify the interactions
public async Task VerifyAsync(Func interact)
{
Guard.NotNull(interact, nameof(interact));
using IMockServerDriver mockServer = this.StartMockServer();
+ // reading the logs drains the FFI buffer, so read them at most once
+ string logs = null;
+ string ReadLogs() => logs ??= mockServer.MockServerLogs();
+
try
{
await interact(new ConsumerContext
@@ -113,11 +121,11 @@ await interact(new ConsumerContext
MockServerUri = mockServer.Uri
});
- this.VerifyInternal(mockServer);
+ this.VerifyInternal(mockServer, ReadLogs);
}
finally
{
- this.PrintLogs(mockServer);
+ this.PrintLogs(ReadLogs());
}
}
@@ -142,7 +150,8 @@ private IMockServerDriver StartMockServer()
/// Verify the interactions after the consumer client has been invoked
///
/// Mock server
- private void VerifyInternal(IMockServerDriver mockServer)
+ /// Reads the mock server logs
+ private void VerifyInternal(IMockServerDriver mockServer, Func readLogs)
{
string errors = mockServer.MockServerMismatches();
@@ -157,17 +166,17 @@ private void VerifyInternal(IMockServerDriver mockServer)
this.config.WriteLine(string.Empty);
this.config.WriteLine(errors);
- throw new PactFailureException("Pact verification failed. See output for details");
+ throw new PactMockServerMismatchException("Pact verification failed. See output for details",
+ errors,
+ readLogs());
}
///
/// Print logs to the configured outputs
///
- /// Mock server
- private void PrintLogs(IMockServerDriver mockServer)
+ /// Mock server logs
+ private void PrintLogs(string logs)
{
- string logs = mockServer.MockServerLogs();
-
this.config.WriteLine("Mock driver logs:");
this.config.WriteLine(string.Empty);
this.config.WriteLine(logs);
diff --git a/src/PactNet/RequestBuilder.cs b/src/PactNet/RequestBuilder.cs
index d245cfbf..ed173c1c 100644
--- a/src/PactNet/RequestBuilder.cs
+++ b/src/PactNet/RequestBuilder.cs
@@ -3,6 +3,7 @@
using System.Net.Http;
using System.Text.Json;
using PactNet.Drivers;
+using PactNet.Internal;
using PactNet.Matchers;
namespace PactNet
@@ -88,6 +89,32 @@ IRequestBuilderV2 IRequestBuilderV2.WithHeader(string key, string value)
IRequestBuilderV2 IRequestBuilderV2.WithHeader(string key, IMatcher matcher)
=> this.WithHeader(key, matcher);
+ ///
+ /// Add a request header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV2 IRequestBuilderV2.WithHeader(string key, params string[] values)
+ => this.WithHeader(key, values);
+
+ ///
+ /// Add a request header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV2 IRequestBuilderV2.WithHeader(string key, params IMatcher[] matchers)
+ => this.WithHeader(key, matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -217,6 +244,32 @@ IRequestBuilderV3 IRequestBuilderV3.WithHeader(string key, string value)
IRequestBuilderV3 IRequestBuilderV3.WithHeader(string key, IMatcher matcher)
=> this.WithHeader(key, matcher);
+ ///
+ /// Add a request header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV3 IRequestBuilderV3.WithHeader(string key, params string[] values)
+ => this.WithHeader(key, values);
+
+ ///
+ /// Add a request header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV3 IRequestBuilderV3.WithHeader(string key, params IMatcher[] matchers)
+ => this.WithHeader(key, matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -346,6 +399,32 @@ IRequestBuilderV4 IRequestBuilderV4.WithHeader(string key, string value)
IRequestBuilderV4 IRequestBuilderV4.WithHeader(string key, IMatcher matcher)
=> this.WithHeader(key, matcher);
+ ///
+ /// Add a request header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV4 IRequestBuilderV4.WithHeader(string key, params string[] values)
+ => this.WithHeader(key, values);
+
+ ///
+ /// Add a request header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IRequestBuilderV4 IRequestBuilderV4.WithHeader(string key, params IMatcher[] matchers)
+ => this.WithHeader(key, matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -509,6 +588,50 @@ internal RequestBuilder WithHeader(string key, IMatcher matcher)
return this.WithHeader(key, serialised);
}
+ ///
+ /// Add a request header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ internal RequestBuilder WithHeader(string key, params string[] values)
+ {
+ Guard.NotNull(values, nameof(values));
+
+ foreach (string value in values)
+ {
+ this.WithHeader(key, value);
+ }
+
+ return this;
+ }
+
+ ///
+ /// Add a request header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ internal RequestBuilder WithHeader(string key, params IMatcher[] matchers)
+ {
+ Guard.NotNull(matchers, nameof(matchers));
+
+ foreach (IMatcher matcher in matchers)
+ {
+ this.WithHeader(key, matcher);
+ }
+
+ return this;
+ }
+
///
/// Set a body which is serialised as JSON
///
diff --git a/src/PactNet/ResponseBuilder.cs b/src/PactNet/ResponseBuilder.cs
index badb0e96..07073595 100644
--- a/src/PactNet/ResponseBuilder.cs
+++ b/src/PactNet/ResponseBuilder.cs
@@ -3,6 +3,7 @@
using System.Net;
using System.Text.Json;
using PactNet.Drivers;
+using PactNet.Internal;
using PactNet.Matchers;
namespace PactNet
@@ -64,6 +65,32 @@ IResponseBuilderV2 IResponseBuilderV2.WithHeader(string key, string value)
IResponseBuilderV2 IResponseBuilderV2.WithHeader(string key, IMatcher matcher)
=> this.WithHeader(key, matcher);
+ ///
+ /// Add a response header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV2 IResponseBuilderV2.WithHeader(string key, params string[] values)
+ => this.WithHeader(key, values);
+
+ ///
+ /// Add a response header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV2 IResponseBuilderV2.WithHeader(string key, params IMatcher[] matchers)
+ => this.WithHeader(key, matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -128,6 +155,32 @@ IResponseBuilderV3 IResponseBuilderV3.WithHeader(string key, string value)
IResponseBuilderV3 IResponseBuilderV3.WithHeader(string key, IMatcher matcher)
=> this.WithHeader(key, matcher);
+ ///
+ /// Add a response header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV3 IResponseBuilderV3.WithHeader(string key, params string[] values)
+ => this.WithHeader(key, values);
+
+ ///
+ /// Add a response header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV3 IResponseBuilderV3.WithHeader(string key, params IMatcher[] matchers)
+ => this.WithHeader(key, matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -192,6 +245,32 @@ IResponseBuilderV4 IResponseBuilderV4.WithHeader(string key, string value)
IResponseBuilderV4 IResponseBuilderV4.WithHeader(string key, IMatcher matcher)
=> this.WithHeader(key, matcher);
+ ///
+ /// Add a response header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV4 IResponseBuilderV4.WithHeader(string key, params string[] values)
+ => this.WithHeader(key, values);
+
+ ///
+ /// Add a response header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ IResponseBuilderV4 IResponseBuilderV4.WithHeader(string key, params IMatcher[] matchers)
+ => this.WithHeader(key, matchers);
+
///
/// Set a body which is serialised as JSON
///
@@ -273,6 +352,50 @@ internal ResponseBuilder WithHeader(string key, IMatcher matcher)
return this.WithHeader(key, serialised);
}
+ ///
+ /// Add a response header with multiple values, e.g. a header which appears on multiple field lines
+ ///
+ /// Header key
+ /// Header values, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, value) once per value. Each value is added at the next index for
+ /// that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ internal ResponseBuilder WithHeader(string key, params string[] values)
+ {
+ Guard.NotNull(values, nameof(values));
+
+ foreach (string value in values)
+ {
+ this.WithHeader(key, value);
+ }
+
+ return this;
+ }
+
+ ///
+ /// Add a response header with multiple values, each with its own matcher
+ ///
+ /// Header key
+ /// Header value matchers, in order
+ /// Fluent builder
+ ///
+ /// Equivalent to calling WithHeader(key, matcher) once per matcher. Each matcher is added at the next index
+ /// for that header, so values added by previous calls for the same key are kept and these are appended after them.
+ ///
+ internal ResponseBuilder WithHeader(string key, params IMatcher[] matchers)
+ {
+ Guard.NotNull(matchers, nameof(matchers));
+
+ foreach (IMatcher matcher in matchers)
+ {
+ this.WithHeader(key, matcher);
+ }
+
+ return this;
+ }
+
///
/// Set a body which is serialised as JSON
///
diff --git a/tests/PactNet.Tests/PactBuilderTests.cs b/tests/PactNet.Tests/PactBuilderTests.cs
index fd645304..1abaa087 100644
--- a/tests/PactNet.Tests/PactBuilderTests.cs
+++ b/tests/PactNet.Tests/PactBuilderTests.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading.Tasks;
using AutoFixture;
using FluentAssertions;
using Moq;
@@ -174,6 +175,50 @@ public void Verify_Mismatches_ThrowsPactFailureException()
action.Should().Throw();
}
+ [Fact]
+ public void Verify_Mismatches_ExposesMismatchesAndLogsOnException()
+ {
+ this.mockServer.Setup(s => s.MockServerMismatches()).Returns("[{\"type\":\"request-mismatch\"}]");
+ this.mockServer.Setup(s => s.MockServerLogs()).Returns("some logs");
+
+ Action action = () => this.builder.Verify(Success);
+
+ action.Should().Throw()
+ .Which.Should().BeEquivalentTo(new
+ {
+ Mismatches = "[{\"type\":\"request-mismatch\"}]",
+ MockServerLogs = "some logs"
+ });
+ }
+
+ [Fact]
+ public async Task VerifyAsync_Mismatches_ExposesMismatchesAndLogsOnException()
+ {
+ this.mockServer.Setup(s => s.MockServerMismatches()).Returns("[{\"type\":\"request-mismatch\"}]");
+ this.mockServer.Setup(s => s.MockServerLogs()).Returns("some logs");
+
+ Func action = () => this.builder.VerifyAsync(SuccessAsync);
+
+ var exception = await action.Should().ThrowAsync();
+ exception.Which.Mismatches.Should().Be("[{\"type\":\"request-mismatch\"}]");
+ exception.Which.MockServerLogs.Should().Be("some logs");
+ }
+
+ [Fact]
+ public void Verify_Mismatches_ReadsLogsOnceForExceptionAndOutput()
+ {
+ // the FFI log buffer is drained on read, so a second read would return nothing
+ this.mockServer.Setup(s => s.MockServerMismatches()).Returns("[{\"type\":\"request-mismatch\"}]");
+ this.mockServer.SetupSequence(s => s.MockServerLogs()).Returns("some logs").Returns(string.Empty);
+
+ Action action = () => this.builder.Verify(Success);
+
+ action.Should().Throw()
+ .Which.MockServerLogs.Should().Be("some logs");
+ this.mockOutput.Verify(o => o.WriteLine("some logs"));
+ this.mockServer.Verify(s => s.MockServerLogs(), Times.Once);
+ }
+
[Fact]
public void Verify_Mismatches_ShutsDownMockServer()
{
@@ -195,6 +240,8 @@ private static void Success(IConsumerContext ctx)
{
}
+ private static Task SuccessAsync(IConsumerContext ctx) => Task.CompletedTask;
+
private static void Error(IConsumerContext ctx)
{
throw new Exception("Interaction failed");
diff --git a/tests/PactNet.Tests/RepeatedHeaderTests.cs b/tests/PactNet.Tests/RepeatedHeaderTests.cs
new file mode 100644
index 00000000..3aa9834b
--- /dev/null
+++ b/tests/PactNet.Tests/RepeatedHeaderTests.cs
@@ -0,0 +1,416 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading.Tasks;
+using FluentAssertions;
+using PactNet.Exceptions;
+using PactNet.Infrastructure.Outputters;
+using PactNet.Matchers;
+using PactNet.Output.Xunit;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace PactNet.Tests
+{
+ ///
+ /// Mock server matching of repeated request headers, following RFC 9110 §5.3 (a recipient may combine
+ /// multiple field lines with the same name into one comma-separated field value).
+ ///
+ ///
+ /// The requests are written over a raw socket because merges repeated headers
+ /// into a single field line, so it can't send each value as its own field line.
+ ///
+ public class RepeatedHeaderTests
+ {
+ private readonly ITestOutputHelper output;
+ private readonly CapturingOutput captured = new();
+
+ public RepeatedHeaderTests(ITestOutputHelper output)
+ {
+ this.output = output;
+ }
+
+ [Fact]
+ public async Task H1_RepeatedFieldLines_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H1");
+
+ builder.UponReceiving("a request with repeated X-Request field lines")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", "a")
+ .WithHeader("X-Request", "b")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder, "X-Request: a", "X-Request: b");
+ }
+
+ [Fact]
+ public async Task H2_SingleCombinedFieldLine_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H2");
+
+ builder.UponReceiving("a request with combined X-Request field line")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", "a")
+ .WithHeader("X-Request", "b")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder, "X-Request: a, b");
+ }
+
+ [Fact]
+ public async Task H3_RepeatedDateValuesContainingCommas_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H3");
+
+ builder.UponReceiving("a request with repeated X-Sunset date field lines")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Sunset", "Sat, 01 Jan 2028 00:00:00 GMT")
+ .WithHeader("X-Sunset", "Sun, 02 Jan 2028 00:00:00 GMT")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder,
+ "X-Sunset: Sat, 01 Jan 2028 00:00:00 GMT",
+ "X-Sunset: Sun, 02 Jan 2028 00:00:00 GMT");
+ }
+
+ [Fact]
+ public async Task H4_SingletonContentTypeCombined_DoesNotMatch()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H4");
+
+ builder.UponReceiving("a request with combined Content-Type field line")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("Content-Type", "text/plain")
+ .WithHeader("Content-Type", "text/html")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ HttpStatusCode? status = null;
+
+ Func verify = () => builder.VerifyAsync(async ctx =>
+ {
+ status = await SendRawAsync(ctx.MockServerUri, "Content-Type: text/plain, text/html");
+ });
+
+ var exception = await verify.Should().ThrowAsync();
+ this.DumpOutput();
+
+ status.Should().NotBe(HttpStatusCode.OK);
+ this.captured.Mismatches.Should().NotBeNullOrWhiteSpace().And.NotBe("[]");
+
+ // the same mismatches and this mock server's logs are available on the exception, not just the outputters
+ exception.Which.Mismatches.Should().Be(this.captured.Mismatches);
+ exception.Which.Mismatches.Should().ContainEquivalentOf("content-type");
+ exception.Which.MockServerLogs.Should().NotBeNullOrWhiteSpace();
+ }
+
+ [Fact]
+ public async Task H5_ListHeaderCombined_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H5");
+
+ builder.UponReceiving("a request with combined Cache-Control field line")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("Cache-Control", "no-cache")
+ .WithHeader("Cache-Control", "no-store")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder, "Cache-Control: no-cache, no-store");
+ }
+
+ [Fact]
+ public async Task H6a_MatcherPerIndex_MatchesWithoutDeprecationWarning()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H6a");
+
+ builder.UponReceiving("a request with repeated X-Request field lines and regex matchers")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", Match.Regex("first-1", @"^first-\d+$"))
+ .WithHeader("X-Request", Match.Regex("first-2", @"^first-\d+$"))
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder, "X-Request: first-42", "X-Request: first-99");
+
+ this.captured.Logs.Should().NotContainEquivalentOf("deprecat");
+ }
+
+ [Fact]
+ public async Task H6b_QuotedValueWhitespaceIsLiteral_DoesNotMatch()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H6b");
+
+ // quoted-string content is literal (RFC 9110 §5.6.4), so the whitespace before the comma
+ // inside the quotes is significant and "x , y" does not match "x, y"
+ builder.UponReceiving("a request with a quoted X-Request value containing a comma")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", "\"x , y\"")
+ .WithHeader("X-Request", "z")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ HttpStatusCode? status = null;
+
+ Func verify = () => builder.VerifyAsync(async ctx =>
+ {
+ status = await SendRawAsync(ctx.MockServerUri, "X-Request: \"x, y\"", "X-Request: z");
+ });
+
+ var exception = await verify.Should().ThrowAsync();
+ this.DumpOutput();
+
+ status.Should().NotBe(HttpStatusCode.OK);
+ this.captured.Mismatches.Should().NotBeNullOrWhiteSpace().And.NotBe("[]");
+ exception.Which.Mismatches.Should().ContainEquivalentOf("x-request");
+ this.captured.Logs.Should().NotContain("RFC 9110");
+ }
+
+ [Fact]
+ public async Task H8a_RepeatedLinkFieldLines_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H8a");
+
+ builder.UponReceiving("a request with repeated Link field lines")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("Link", "; rel=\"a\"")
+ .WithHeader("Link", "; rel=\"b\"")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder,
+ "Link: ; rel=\"a\"",
+ "Link: ; rel=\"b\"");
+ }
+
+ [Fact]
+ public async Task H8b_CombinedLinkFieldLine_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("H8b");
+
+ builder.UponReceiving("a request with combined Link field line")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("Link", "; rel=\"a\"")
+ .WithHeader("Link", "; rel=\"b\"")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder,
+ "Link: ; rel=\"a\", ; rel=\"b\"");
+ }
+
+ ///
+ /// The repeated custom header scenario from the original expectations
+ /// (pact-net PR 570 renamed it to Accept-Language to avoid a mock server 500 on older FFI versions)
+ ///
+ [Fact]
+ public async Task RepeatedCustomHeader_SeparateFieldLines_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("X-Request-lines");
+
+ builder.UponReceiving("a request with repeated custom header field lines")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", "request1")
+ .WithHeader("X-Request", "request2")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder, "X-Request: request1", "X-Request: request2");
+ }
+
+ ///
+ /// As above, but sent via which combines the values into one field line
+ ///
+ [Fact]
+ public async Task RepeatedCustomHeader_HttpClient_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("X-Request-httpclient");
+
+ builder.UponReceiving("a request with a repeated custom header from HttpClient")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", "request1")
+ .WithHeader("X-Request", "request2")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await builder.VerifyAsync(async ctx =>
+ {
+ using var client = new HttpClient { BaseAddress = ctx.MockServerUri };
+ client.DefaultRequestHeaders.Add("X-Request", new[] { "request1", "request2" });
+
+ HttpResponseMessage response = await client.GetAsync("/headers");
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+ });
+ }
+
+ [Fact]
+ public async Task MultipleValuesOverload_SeparateFieldLines_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("values-overload");
+
+ builder.UponReceiving("a request with repeated X-Request field lines from the values overload")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", "request1", "request2")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder, "X-Request: request1", "X-Request: request2");
+ }
+
+ [Fact]
+ public async Task MultipleMatchersOverload_SeparateFieldLines_Matches()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("matchers-overload");
+
+ builder.UponReceiving("a request with repeated X-Request field lines from the matchers overload")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WithHeader("X-Request", Match.Regex("first-1", @"^first-\d+$"), Match.Type("second"))
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK);
+
+ await this.ShouldMatchAsync(builder, "X-Request: first-42", "X-Request: anything");
+ }
+
+ [Fact]
+ public async Task MultipleValuesOverload_Response_ReturnsEachValue()
+ {
+ IPactBuilderV3 builder = this.NewBuilder("response-values-overload");
+
+ builder.UponReceiving("a request for a response with a repeated header")
+ .WithRequest(HttpMethod.Get, "/headers")
+ .WillRespond()
+ .WithStatus(HttpStatusCode.OK)
+ .WithHeader("X-Response", "response1", "response2");
+
+ await builder.VerifyAsync(async ctx =>
+ {
+ using var client = new HttpClient { BaseAddress = ctx.MockServerUri };
+
+ HttpResponseMessage response = await client.GetAsync("/headers");
+
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+ response.Headers.GetValues("X-Response").Should().BeEquivalentTo(new[] { "response1", "response2" },
+ o => o.WithStrictOrdering());
+ });
+ }
+
+ private IPactBuilderV3 NewBuilder(string id)
+ {
+ var config = new PactConfig
+ {
+ PactDir = Environment.CurrentDirectory,
+ Outputters = new IOutput[] { new XunitOutput(this.output), this.captured }
+ };
+
+ string consumer = $"RepeatedHeaderTests-{id}-Consumer";
+ string provider = "RepeatedHeaderTests-Provider";
+
+ File.Delete(Path.Combine(config.PactDir, $"{consumer}-{provider}.json"));
+
+ return Pact.V3(consumer, provider, config).WithHttpInteractions();
+ }
+
+ ///
+ /// Send the raw field lines, then assert a 200 and no mismatches (VerifyAsync throws on any mismatch)
+ ///
+ private async Task ShouldMatchAsync(IPactBuilderV3 builder, params string[] fieldLines)
+ {
+ HttpStatusCode? status = null;
+
+ Func verify = () => builder.VerifyAsync(async ctx =>
+ {
+ status = await SendRawAsync(ctx.MockServerUri, fieldLines);
+ });
+
+ try
+ {
+ await verify.Should().NotThrowAsync();
+ status.Should().Be(HttpStatusCode.OK);
+ }
+ finally
+ {
+ this.DumpOutput();
+ }
+ }
+
+ private void DumpOutput()
+ {
+ if (!string.IsNullOrWhiteSpace(this.captured.Mismatches))
+ {
+ this.output.WriteLine("Captured mismatches: " + this.captured.Mismatches);
+ }
+ }
+
+ ///
+ /// Write a GET /headers request with each header field line exactly as given
+ ///
+ private static async Task SendRawAsync(Uri baseUri, params string[] fieldLines)
+ {
+ using var client = new TcpClient();
+ await client.ConnectAsync(baseUri.Host, baseUri.Port);
+
+ var request = new StringBuilder();
+ request.Append("GET /headers HTTP/1.1\r\n");
+ request.Append($"Host: {baseUri.Host}:{baseUri.Port}\r\n");
+
+ foreach (string line in fieldLines)
+ {
+ request.Append(line).Append("\r\n");
+ }
+
+ request.Append("Connection: close\r\n\r\n");
+
+ using NetworkStream stream = client.GetStream();
+ byte[] bytes = Encoding.UTF8.GetBytes(request.ToString());
+ await stream.WriteAsync(bytes, 0, bytes.Length);
+
+ using var reader = new StreamReader(stream, Encoding.ASCII);
+ string statusLine = await reader.ReadLineAsync();
+
+ // e.g. "HTTP/1.1 200 OK"
+ string[] parts = statusLine?.Split(' ') ?? Array.Empty();
+ parts.Length.Should().BeGreaterThan(1, "the mock server should return a status line, got '{0}'", statusLine);
+
+ await reader.ReadToEndAsync();
+
+ return (HttpStatusCode)int.Parse(parts[1]);
+ }
+
+ ///
+ /// Captures what writes to outputters, i.e. the mock server log buffer
+ /// (which receives the FFI's log lines for this mock server) and any verification mismatches
+ ///
+ private class CapturingOutput : IOutput
+ {
+ private readonly List lines = new();
+
+ public string Logs => string.Join(Environment.NewLine, this.lines);
+
+ public string Mismatches
+ {
+ get
+ {
+ // PactBuilder writes the heading, a blank line, then the mismatches JSON
+ int index = this.lines.IndexOf("Verification mismatches:");
+ return index < 0 || index + 2 >= this.lines.Count ? null : this.lines[index + 2];
+ }
+ }
+
+ public void WriteLine(string line)
+ {
+ lock (this.lines)
+ {
+ this.lines.Add(line);
+ }
+ }
+ }
+ }
+}
diff --git a/tests/PactNet.Tests/RequestBuilderTests.cs b/tests/PactNet.Tests/RequestBuilderTests.cs
index d4be9624..35d58683 100644
--- a/tests/PactNet.Tests/RequestBuilderTests.cs
+++ b/tests/PactNet.Tests/RequestBuilderTests.cs
@@ -141,6 +141,58 @@ public void WithHeader_RepeatedStringHeader_SetsIndex()
this.mockDriver.Verify(s => s.WithRequestHeader("other", "value", 0));
}
+ [Fact]
+ public void WithHeader_MultipleStringValues_SetsIndexPerValue()
+ {
+ this.builder.WithHeader("name", "value1", "value2", "value3");
+
+ this.mockDriver.Verify(s => s.WithRequestHeader("name", "value1", 0));
+ this.mockDriver.Verify(s => s.WithRequestHeader("name", "value2", 1));
+ this.mockDriver.Verify(s => s.WithRequestHeader("name", "value3", 2));
+ }
+
+ [Fact]
+ public void WithHeader_MultipleStringValuesAfterSingleValue_ContinuesIndex()
+ {
+ this.builder.WithHeader("name", "value1");
+ this.builder.WithHeader("NAME", "value2", "value3");
+ this.builder.WithHeader("other", "value", "value");
+
+ this.mockDriver.Verify(s => s.WithRequestHeader("name", "value1", 0));
+ this.mockDriver.Verify(s => s.WithRequestHeader("NAME", "value2", 1));
+ this.mockDriver.Verify(s => s.WithRequestHeader("NAME", "value3", 2));
+ this.mockDriver.Verify(s => s.WithRequestHeader("other", "value", 0));
+ this.mockDriver.Verify(s => s.WithRequestHeader("other", "value", 1));
+ }
+
+ [Fact]
+ public void WithHeader_MultipleMatchers_SetsSerialisedValuePerIndex()
+ {
+ var expectedValue1 = "{\"pact:matcher:type\":\"regex\",\"value\":\"value1\",\"regex\":\"^value[0-9]$\"}";
+ var expectedValue2 = "{\"pact:matcher:type\":\"type\",\"value\":\"value2\"}";
+
+ this.builder.WithHeader("name", Match.Regex("value1", "^value[0-9]$"), Match.Type("value2"));
+
+ this.mockDriver.Verify(s => s.WithRequestHeader("name", expectedValue1, 0));
+ this.mockDriver.Verify(s => s.WithRequestHeader("name", expectedValue2, 1));
+ }
+
+ [Fact]
+ public void WithHeader_NullValues_ThrowsArgumentException()
+ {
+ Action action = () => this.builder.WithHeader("name", (string[])null);
+
+ action.Should().Throw();
+ }
+
+ [Fact]
+ public void WithHeader_NullMatchers_ThrowsArgumentException()
+ {
+ Action action = () => this.builder.WithHeader("name", (Matchers.IMatcher[])null);
+
+ action.Should().Throw();
+ }
+
[Fact]
public void WithJsonBody_NoOverrides_AddsRequestBodyWithDefaultSettings()
{
diff --git a/tests/PactNet.Tests/ResponseBuilderTests.cs b/tests/PactNet.Tests/ResponseBuilderTests.cs
index d92cee71..28e8b50a 100644
--- a/tests/PactNet.Tests/ResponseBuilderTests.cs
+++ b/tests/PactNet.Tests/ResponseBuilderTests.cs
@@ -1,5 +1,7 @@
+using System;
using System.Net;
using System.Text.Json;
+using FluentAssertions;
using Moq;
using PactNet.Drivers;
using Xunit;
@@ -86,6 +88,58 @@ public void WithHeader_RepeatedStringHeader_SetsIndex()
this.mockDriver.Verify(s => s.WithResponseHeader("other", "value", 0));
}
+ [Fact]
+ public void WithHeader_MultipleStringValues_SetsIndexPerValue()
+ {
+ this.builder.WithHeader("name", "value1", "value2", "value3");
+
+ this.mockDriver.Verify(s => s.WithResponseHeader("name", "value1", 0));
+ this.mockDriver.Verify(s => s.WithResponseHeader("name", "value2", 1));
+ this.mockDriver.Verify(s => s.WithResponseHeader("name", "value3", 2));
+ }
+
+ [Fact]
+ public void WithHeader_MultipleStringValuesAfterSingleValue_ContinuesIndex()
+ {
+ this.builder.WithHeader("name", "value1");
+ this.builder.WithHeader("NAME", "value2", "value3");
+ this.builder.WithHeader("other", "value", "value");
+
+ this.mockDriver.Verify(s => s.WithResponseHeader("name", "value1", 0));
+ this.mockDriver.Verify(s => s.WithResponseHeader("NAME", "value2", 1));
+ this.mockDriver.Verify(s => s.WithResponseHeader("NAME", "value3", 2));
+ this.mockDriver.Verify(s => s.WithResponseHeader("other", "value", 0));
+ this.mockDriver.Verify(s => s.WithResponseHeader("other", "value", 1));
+ }
+
+ [Fact]
+ public void WithHeader_MultipleMatchers_SetsSerialisedValuePerIndex()
+ {
+ var expectedValue1 = "{\"pact:matcher:type\":\"regex\",\"value\":\"value1\",\"regex\":\"^value[0-9]$\"}";
+ var expectedValue2 = "{\"pact:matcher:type\":\"type\",\"value\":\"value2\"}";
+
+ this.builder.WithHeader("name", Match.Regex("value1", "^value[0-9]$"), Match.Type("value2"));
+
+ this.mockDriver.Verify(s => s.WithResponseHeader("name", expectedValue1, 0));
+ this.mockDriver.Verify(s => s.WithResponseHeader("name", expectedValue2, 1));
+ }
+
+ [Fact]
+ public void WithHeader_NullValues_ThrowsArgumentException()
+ {
+ Action action = () => this.builder.WithHeader("name", (string[])null);
+
+ action.Should().Throw();
+ }
+
+ [Fact]
+ public void WithHeader_NullMatchers_ThrowsArgumentException()
+ {
+ Action action = () => this.builder.WithHeader("name", (Matchers.IMatcher[])null);
+
+ action.Should().Throw();
+ }
+
[Fact]
public void WithJsonBody_WithoutCustomSettings_AddsRequestBodyWithDefaultSettings()
{
diff --git a/tests/PactNet.Tests/data/v2-consumer-integration.json b/tests/PactNet.Tests/data/v2-consumer-integration.json
index 9484eef4..4245b1ca 100644
--- a/tests/PactNet.Tests/data/v2-consumer-integration.json
+++ b/tests/PactNet.Tests/data/v2-consumer-integration.json
@@ -74,8 +74,8 @@
],
"metadata": {
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "2.0.0"
diff --git a/tests/PactNet.Tests/data/v3-consumer-integration.json b/tests/PactNet.Tests/data/v3-consumer-integration.json
index b220eb49..4d17a13c 100644
--- a/tests/PactNet.Tests/data/v3-consumer-integration.json
+++ b/tests/PactNet.Tests/data/v3-consumer-integration.json
@@ -130,8 +130,8 @@
],
"metadata": {
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "3.0.0"
diff --git a/tests/PactNet.Tests/data/v3-message-consumer-integration.json b/tests/PactNet.Tests/data/v3-message-consumer-integration.json
index 494ea225..ce0212de 100644
--- a/tests/PactNet.Tests/data/v3-message-consumer-integration.json
+++ b/tests/PactNet.Tests/data/v3-message-consumer-integration.json
@@ -36,8 +36,8 @@
"language": "C#"
},
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "3.0.0"
diff --git a/tests/PactNet.Tests/data/v3-message-integration.json b/tests/PactNet.Tests/data/v3-message-integration.json
index 4a3ace22..735842f2 100644
--- a/tests/PactNet.Tests/data/v3-message-integration.json
+++ b/tests/PactNet.Tests/data/v3-message-integration.json
@@ -16,8 +16,8 @@
],
"metadata": {
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "3.0.0"
diff --git a/tests/PactNet.Tests/data/v3-server-integration.json b/tests/PactNet.Tests/data/v3-server-integration.json
index c5050bd5..4ee98ce8 100644
--- a/tests/PactNet.Tests/data/v3-server-integration.json
+++ b/tests/PactNet.Tests/data/v3-server-integration.json
@@ -46,8 +46,8 @@
],
"metadata": {
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "3.0.0"
diff --git a/tests/PactNet.Tests/data/v4-combined-integration.json b/tests/PactNet.Tests/data/v4-combined-integration.json
index 61808511..41154860 100644
--- a/tests/PactNet.Tests/data/v4-combined-integration.json
+++ b/tests/PactNet.Tests/data/v4-combined-integration.json
@@ -185,8 +185,8 @@
"language": "C#"
},
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "4.0"
diff --git a/tests/PactNet.Tests/data/v4-consumer-integration.json b/tests/PactNet.Tests/data/v4-consumer-integration.json
index 87ef562b..c717b3ca 100644
--- a/tests/PactNet.Tests/data/v4-consumer-integration.json
+++ b/tests/PactNet.Tests/data/v4-consumer-integration.json
@@ -150,8 +150,8 @@
],
"metadata": {
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "4.0"
diff --git a/tests/PactNet.Tests/data/v4-message-consumer-integration.json b/tests/PactNet.Tests/data/v4-message-consumer-integration.json
index 8861180b..32367539 100644
--- a/tests/PactNet.Tests/data/v4-message-consumer-integration.json
+++ b/tests/PactNet.Tests/data/v4-message-consumer-integration.json
@@ -41,8 +41,8 @@
"language": "C#"
},
"pactRust": {
- "ffi": "0.4.27",
- "models": "1.2.8"
+ "ffi": "0.5.13-rc.1",
+ "models": "1.3.17"
},
"pactSpecification": {
"version": "4.0"