diff --git a/samples/OrdersApi/Provider.Tests/ProviderTests.cs b/samples/OrdersApi/Provider.Tests/ProviderTests.cs
index 1feb302e..05daad1a 100644
--- a/samples/OrdersApi/Provider.Tests/ProviderTests.cs
+++ b/samples/OrdersApi/Provider.Tests/ProviderTests.cs
@@ -38,7 +38,7 @@ public ProviderTests(ITestOutputHelper output)
.Build();
this.server.Start();
-
+
this.verifier = new PactVerifier("Orders API", new PactVerifierConfig
{
LogLevel = PactLogLevel.Debug,
diff --git a/src/PactNet.Abstractions/Verifier/IPactBrokerOptions.cs b/src/PactNet.Abstractions/Verifier/IPactBrokerOptions.cs
index 7ba2cc40..47fb86f3 100644
--- a/src/PactNet.Abstractions/Verifier/IPactBrokerOptions.cs
+++ b/src/PactNet.Abstractions/Verifier/IPactBrokerOptions.cs
@@ -104,5 +104,12 @@ public interface IPactBrokerOptions
/// Configure the publish options
/// Fluent builder
IPactBrokerOptions PublishResults(bool condition, string providerVersion, Action configure);
+
+ ///
+ /// Return an error when no pacts are found on the Pact Broker. By default, an error is returned.
+ ///
+ /// return error or not
+ /// Fluent builder
+ IPactBrokerOptions NoPactsIsError(bool isError);
}
}
diff --git a/src/PactNet/Interop/NativeInterop.cs b/src/PactNet/Interop/NativeInterop.cs
index 92bdc911..08e6943f 100644
--- a/src/PactNet/Interop/NativeInterop.cs
+++ b/src/PactNet/Interop/NativeInterop.cs
@@ -167,6 +167,9 @@ public static extern void VerifierBrokerSourceWithSelectors(IntPtr handle,
[DllImport(DllName, EntryPoint = "pactffi_verifier_output")]
public static extern IntPtr VerifierOutput(IntPtr handle, byte stripAnsi);
+ [DllImport(DllName, EntryPoint = "pactffi_verifier_set_no_pacts_is_error")]
+ public static extern void VerifierSetNoPactsIsError(IntPtr handle, bool isError);
+
#endregion
}
}
diff --git a/src/PactNet/Verifier/IVerifierProvider.cs b/src/PactNet/Verifier/IVerifierProvider.cs
index 369ba00c..615efc2d 100644
--- a/src/PactNet/Verifier/IVerifierProvider.cs
+++ b/src/PactNet/Verifier/IVerifierProvider.cs
@@ -131,6 +131,12 @@ void AddBrokerSource(Uri url,
ICollection consumerVersionSelectors,
ICollection consumerVersionTags);
+ ///
+ /// Configures the verifier to return an error when no pacts are found on the Pact Broker. By default, an error is returned.
+ ///
+ /// return error or not
+ void SetNoPactsIsError(bool isError);
+
///
/// Verify the pact from the given args
///
diff --git a/src/PactNet/Verifier/InteropVerifierProvider.cs b/src/PactNet/Verifier/InteropVerifierProvider.cs
index c0245296..f9884fae 100644
--- a/src/PactNet/Verifier/InteropVerifierProvider.cs
+++ b/src/PactNet/Verifier/InteropVerifierProvider.cs
@@ -215,6 +215,15 @@ public void AddBrokerSource(Uri url,
(ushort)consumerVersionTags.Count);
}
+ ///
+ /// Configures the verifier to return an error when no pacts are found on the Pact Broker. By default, an error is returned.
+ ///
+ /// return error or not
+ public void SetNoPactsIsError(bool isError)
+ {
+ NativeInterop.VerifierSetNoPactsIsError(this.handle, isError);
+ }
+
///
/// Verify the pact from the given args
///
diff --git a/src/PactNet/Verifier/PactBrokerOptions.cs b/src/PactNet/Verifier/PactBrokerOptions.cs
index 987fd1e3..77245cee 100644
--- a/src/PactNet/Verifier/PactBrokerOptions.cs
+++ b/src/PactNet/Verifier/PactBrokerOptions.cs
@@ -200,6 +200,17 @@ public IPactBrokerOptions PublishResults(bool condition, string providerVersion)
public IPactBrokerOptions PublishResults(bool condition, string providerVersion, Action configure)
=> condition ? this.PublishResults(providerVersion, configure) : this;
+ ///
+ /// Return an error when no pacts are found on the Pact Broker. By default, an error is returned.
+ ///
+ /// return error or not
+ /// Fluent builder
+ public IPactBrokerOptions NoPactsIsError(bool isError)
+ {
+ this.provider.SetNoPactsIsError(isError);
+ return this;
+ }
+
///
/// Finalise the configuration with the provider
///
diff --git a/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs b/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs
index 91d4b023..e59f12a5 100644
--- a/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs
+++ b/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs
@@ -50,6 +50,7 @@ public void HappyPathIntegrationTest()
"main",
new[] { @"{""branch"":""main""}" },
new[] { "consumer-tag" });
+ provider.SetNoPactsIsError(true);
Action action = () => provider.Execute();
diff --git a/tests/PactNet.Tests/Verifier/PactBrokerOptionsTests.cs b/tests/PactNet.Tests/Verifier/PactBrokerOptionsTests.cs
index 742cbf0f..fee1fbbb 100644
--- a/tests/PactNet.Tests/Verifier/PactBrokerOptionsTests.cs
+++ b/tests/PactNet.Tests/Verifier/PactBrokerOptionsTests.cs
@@ -177,6 +177,20 @@ public void PublishResults_ConditionNotMet_DoesNotAddPublishArgs()
Times.Never);
}
+ [Fact]
+ public void NoPactsIsError_WhenTrue_SetsNoPactsIsErrorTrue()
+ {
+ this.options.NoPactsIsError(true);
+ this.mockProvider.Verify(p => p.SetNoPactsIsError(true));
+ }
+
+ [Fact]
+ public void NoPactsIsError_WhenFalse_SetsNoPactsIsErrorFalse()
+ {
+ this.options.NoPactsIsError(false);
+ this.mockProvider.Verify(p => p.SetNoPactsIsError(false));
+ }
+
private void Verify(string username = null,
string password = null,
string token = null,