Skip to content

Commit dedfecf

Browse files
committed
refactor: Make AbstractPactBuilder public so it can be extended by plugin libraries
1 parent e139e82 commit dedfecf

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

src/PactNet/Drivers/ICompletedPactDriver.cs renamed to src/PactNet.Abstractions/Drivers/ICompletedPactDriver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace PactNet.Drivers
55
/// <summary>
66
/// Driver for writing completed pact files containing interactions
77
/// </summary>
8-
internal interface ICompletedPactDriver
8+
public interface ICompletedPactDriver
99
{
1010
/// <summary>
1111
/// Write the pact file to disk

src/PactNet/Drivers/IMockServerDriver.cs renamed to src/PactNet.Abstractions/Drivers/IMockServerDriver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace PactNet.Drivers
55
/// <summary>
66
/// Driver for managing a HTTP mock server
77
/// </summary>
8-
internal interface IMockServerDriver : IDisposable
8+
public interface IMockServerDriver : IDisposable
99
{
1010
/// <summary>
1111
/// Mock server port
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
using System;
2+
using PactNet.Drivers;
23

34
namespace PactNet;
45

56
public interface ISynchronousPluginPactBuilderV4 : IPactBuilder, IDisposable
67
{
8+
/// <summary>
9+
/// Add a new interaction to the pact
10+
/// </summary>
11+
/// <param name="description">Interaction description</param>
12+
/// <returns>Fluent builder</returns>
713
ISynchronousPluginRequestBuilderV4 UponReceiving(string description);
14+
15+
/// <summary>
16+
/// Driver for writing completed pact files containing interactions
17+
/// </summary>
18+
ICompletedPactDriver CompletedPactDriver { get; }
819
}

src/PactNet/AbstractPactBuilder.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
namespace PactNet;
99

10-
internal abstract class AbstractPactBuilder : IPactBuilder
10+
/// <summary>
11+
/// Abstract pact builder that contains shared functionality of different types of pact interactions.
12+
/// </summary>
13+
public abstract class AbstractPactBuilder : IPactBuilder
1114
{
1215
private readonly ICompletedPactDriver pact;
13-
protected readonly PactConfig config;
14-
protected readonly int? port;
15-
protected readonly IPAddress host;
16+
private readonly PactConfig config;
17+
private readonly int? port;
18+
private readonly IPAddress host;
1619
private readonly string transport;
1720

1821
/// <summary>
@@ -38,7 +41,7 @@ protected AbstractPactBuilder(ICompletedPactDriver pact, PactConfig config, int?
3841
/// </summary>
3942
/// <param name="interact">Action to perform the real interactions against the mock driver</param>
4043
/// <exception cref="PactFailureException">Failed to verify the interactions</exception>
41-
public void Verify(Action<IConsumerContext> interact)
44+
public virtual void Verify(Action<IConsumerContext> interact)
4245
{
4346
Guard.NotNull(interact, nameof(interact));
4447

@@ -61,7 +64,7 @@ public void Verify(Action<IConsumerContext> interact)
6164
/// </summary>
6265
/// <param name="interact">Action to perform the real interactions against the mock driver</param>
6366
/// <exception cref="PactFailureException">Failed to verify the interactions</exception>
64-
public async Task VerifyAsync(Func<IConsumerContext, Task> interact)
67+
public virtual async Task VerifyAsync(Func<IConsumerContext, Task> interact)
6568
{
6669
Guard.NotNull(interact, nameof(interact));
6770

src/PactNet/PactBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace PactNet
99
internal class PactBuilder : AbstractPactBuilder, IPactBuilderV2, IPactBuilderV3, IPactBuilderV4
1010
{
1111
private readonly IHttpPactDriver pact;
12+
private readonly PactConfig config;
1213

1314
/// <summary>
1415
/// Initialises a new instance of the <see cref="PactBuilder"/> class.
@@ -21,6 +22,7 @@ internal PactBuilder(IHttpPactDriver pact, PactConfig config, int? port = null,
2122
IPAddress host = IPAddress.Loopback) : base(pact, config, port, host, "http")
2223
{
2324
this.pact = pact;
25+
this.config = config;
2426
}
2527

2628
/// <summary>

src/PactNet/SynchronousPluginPactBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using PactNet.Drivers;
12
using PactNet.Drivers.Plugins;
23
using PactNet.Models;
34

@@ -16,5 +17,10 @@ public ISynchronousPluginRequestBuilderV4 UponReceiving(string description)
1617
return new SynchronousPluginRequestBuilder(pact.NewSyncInteraction(description));
1718
}
1819

20+
/// <summary>
21+
/// Driver for writing completed pact files containing interactions
22+
/// </summary>
23+
public ICompletedPactDriver CompletedPactDriver { get { return pact; } }
24+
1925
public void Dispose() => pact?.Dispose();
2026
}

0 commit comments

Comments
 (0)