Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion samples/OrdersApi/Provider.Tests/ProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ProviderTests(ITestOutputHelper output)
.Build();

this.server.Start();

this.verifier = new PactVerifier("Orders API", new PactVerifierConfig
{
LogLevel = PactLogLevel.Debug,
Expand Down
7 changes: 7 additions & 0 deletions src/PactNet.Abstractions/Verifier/IPactBrokerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,12 @@ public interface IPactBrokerOptions
/// <param name="configure">Configure the publish options</param>
/// <returns>Fluent builder</returns>
IPactBrokerOptions PublishResults(bool condition, string providerVersion, Action<IPactBrokerPublishOptions> configure);

/// <summary>
/// Return an error when no pacts are found on the Pact Broker. By default, an error is returned.
/// </summary>
/// <param name="isError">return error or not</param>
/// <returns>Fluent builder</returns>
IPactBrokerOptions NoPactsIsError(bool isError);
}
}
3 changes: 3 additions & 0 deletions src/PactNet/Interop/NativeInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 6 additions & 0 deletions src/PactNet/Verifier/IVerifierProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ void AddBrokerSource(Uri url,
ICollection<string> consumerVersionSelectors,
ICollection<string> consumerVersionTags);

/// <summary>
/// Configures the verifier to return an error when no pacts are found on the Pact Broker. By default, an error is returned.
/// </summary>
/// <param name="isError">return error or not</param>
void SetNoPactsIsError(bool isError);

/// <summary>
/// Verify the pact from the given args
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/PactNet/Verifier/InteropVerifierProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ public void AddBrokerSource(Uri url,
(ushort)consumerVersionTags.Count);
}

/// <summary>
/// Configures the verifier to return an error when no pacts are found on the Pact Broker. By default, an error is returned.
/// </summary>
/// <param name="isError">return error or not</param>
public void SetNoPactsIsError(bool isError)
{
NativeInterop.VerifierSetNoPactsIsError(this.handle, isError);
}

/// <summary>
/// Verify the pact from the given args
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/PactNet/Verifier/PactBrokerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ public IPactBrokerOptions PublishResults(bool condition, string providerVersion)
public IPactBrokerOptions PublishResults(bool condition, string providerVersion, Action<IPactBrokerPublishOptions> configure)
=> condition ? this.PublishResults(providerVersion, configure) : this;

/// <summary>
/// Return an error when no pacts are found on the Pact Broker. By default, an error is returned.
/// </summary>
/// <param name="isError">return error or not</param>
/// <returns>Fluent builder</returns>
public IPactBrokerOptions NoPactsIsError(bool isError)
{
this.provider.SetNoPactsIsError(isError);
return this;
}

/// <summary>
/// Finalise the configuration with the provider
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void HappyPathIntegrationTest()
"main",
new[] { @"{""branch"":""main""}" },
new[] { "consumer-tag" });
provider.SetNoPactsIsError(true);

Action action = () => provider.Execute();

Expand Down
14 changes: 14 additions & 0 deletions tests/PactNet.Tests/Verifier/PactBrokerOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down