Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions src/PactNet.Abstractions/Verifier/IPactVerifierSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public interface IPactVerifierSource
/// <returns>Fluent builder</returns>
IPactVerifierSource WithCustomHeader(string name, string value);

/// <summary>
/// Return an error or not if no pacts were found when looking up from a broker. Default value is true.
/// </summary>
/// <param name="fail">fail or not</param>
/// <returns>Fluent builder</returns>
IPactVerifierSource FailIfNoPactsFound(bool fail);

/// <summary>
/// Verify provider interactions
/// </summary>
Expand Down
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
}
}
8 changes: 8 additions & 0 deletions src/PactNet/Verifier/IVerifierProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ void AddBrokerSource(Uri url,
ICollection<string> consumerVersionSelectors,
ICollection<string> consumerVersionTags);

/// <summary>
/// Configures the verifier to return an error
/// if no pacts were found when looking up from a broker
/// </summary>
/// <param name="isError"></param>
/// <returns>Fluent builder</returns>
void SetNoPactsIsError(bool isError);

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

/// <summary>
/// Configures the verifier to return an error
/// if no pacts were found when looking up from a broker
/// </summary>
/// <param name="isError"></param>
/// <returns>Fluent builder</returns>
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/PactVerifierSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public IPactVerifierSource WithCustomHeader(string name, string value)
return this;
}

/// <summary>
/// Return an error or not if no pacts were found when looking up from a broker. Default value is true.
/// </summary>
/// <param name="fail">fail or not</param>
/// <returns>Fluent builder</returns>
public IPactVerifierSource FailIfNoPactsFound(bool fail)
{
this.provider.SetNoPactsIsError(fail);
return this;
}

/// <summary>
/// Verify provider interactions
/// </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
18 changes: 18 additions & 0 deletions tests/PactNet.Tests/Verifier/PactVerifierSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,23 @@ public void Verify_VerificationError_ThrowsPactFailureException()

action.Should().Throw<PactFailureException>();
}

[Fact]
public void FailIfNoPactsFound_WhenTrue_SetsNoPactsIsErrorTrue()
{
this.verifier.FailIfNoPactsFound(true);
this.verifier.Verify();

this.mockProvider.Verify(p => p.SetNoPactsIsError(true));
}

[Fact]
public void FailIfNoPactsFound_WhenFalse_SetsNoPactsIsErrorFalse()
{
this.verifier.FailIfNoPactsFound(false);
this.verifier.Verify();

this.mockProvider.Verify(p => p.SetNoPactsIsError(false));
}
}
}