Skip to content

Commit d4644b3

Browse files
committed
refactor(interop): reorganize remaining interop methods and change visibility to internal
1 parent 0085b05 commit d4644b3

18 files changed

+128
-123
lines changed

src/PactNet.Extensions.Grpc/GrpcExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public static IGrpcPactBuilderV4 WithGrpcInteractions(this IPactV4 pact, int? po
2727

2828
private static PactHandle NewGrpcPact(string consumerName, string providerName)
2929
{
30-
PactHandle pact = NativeInterop.NewPact(consumerName, providerName);
31-
NativeInterop.WithSpecification(pact, PactSpecification.V4).ThrowExceptionOnFailure();
30+
PactHandle pact = PactInterop.NewPact(consumerName, providerName);
31+
PactInterop.WithSpecification(pact, PactSpecification.V4).ThrowExceptionOnFailure();
3232
return pact;
3333
}
3434
}

src/PactNet.Extensions.Grpc/GrpcPactBuilder.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void Verify(Action<IConsumerContext> interact)
9191
}
9292
finally
9393
{
94-
this.PrintLogs(mockServer);
94+
this.PrintLogs();
9595
}
9696
}
9797

@@ -119,7 +119,7 @@ public async Task VerifyAsync(Func<IConsumerContext, Task> interact)
119119
}
120120
finally
121121
{
122-
this.PrintLogs(mockServer);
122+
this.PrintLogs();
123123
}
124124
}
125125

@@ -165,10 +165,9 @@ private void VerifyInternal(IMockServerDriver mockServer)
165165
/// <summary>
166166
/// Print logs to the configured outputs
167167
/// </summary>
168-
/// <param name="mockServer">Mock server</param>
169-
private void PrintLogs(IMockServerDriver mockServer)
168+
private void PrintLogs()
170169
{
171-
string logs = NativeInterop.FetchLogBuffer(null);
170+
string logs = LoggingInterop.FetchLogBuffer(null);
172171

173172
this.config.WriteLine("Mock driver logs:");
174173
this.config.WriteLine(string.Empty);

src/PactNet.Extensions.Grpc/GrpcRequestBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal class GrpcRequestBuilder(InteractionHandle interaction) : IGrpcRequestB
5858
/// <returns>Fluent builder</returns>
5959
public IGrpcRequestBuilderV4 Given(string providerState)
6060
{
61-
NativeInterop.Given(interaction, providerState).ThrowExceptionOnFailure();
61+
PactInterop.Given(interaction, providerState).ThrowExceptionOnFailure();
6262
return this;
6363
}
6464

@@ -72,7 +72,7 @@ public IGrpcRequestBuilderV4 Given(string providerState, IDictionary<string, str
7272
{
7373
foreach (var param in parameters)
7474
{
75-
NativeInterop.GivenWithParam(interaction, providerState, param.Key, param.Value).ThrowExceptionOnFailure();
75+
PactInterop.GivenWithParam(interaction, providerState, param.Key, param.Value).ThrowExceptionOnFailure();
7676
}
7777

7878
return this;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("PactNet")]
2+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("PactNet.Extensions.Grpc")]

src/PactNet.Interop/HttpInterop.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace PactNet.Interop
5+
{
6+
/// <summary>
7+
/// Interop definitions to the Pact FFI library
8+
/// </summary>
9+
internal static class HttpInterop
10+
{
11+
private const string DllName = "pact_ffi";
12+
13+
[DllImport(DllName, EntryPoint = "pactffi_new_interaction")]
14+
public static extern InteractionHandle NewInteraction(PactHandle pact, string description);
15+
16+
[DllImport(DllName, EntryPoint = "pactffi_with_request")]
17+
public static extern bool WithRequest(InteractionHandle interaction, string method, string path);
18+
19+
[DllImport(DllName, EntryPoint = "pactffi_with_query_parameter_v2")]
20+
public static extern bool WithQueryParameter(InteractionHandle interaction, string name, UIntPtr index, string value);
21+
22+
[DllImport(DllName, EntryPoint = "pactffi_with_header_v2")]
23+
public static extern bool WithHeader(InteractionHandle interaction, InteractionPart part, string name, UIntPtr index, string value);
24+
25+
[DllImport(DllName, EntryPoint = "pactffi_response_status")]
26+
public static extern bool ResponseStatus(InteractionHandle interaction, ushort status);
27+
28+
[DllImport(DllName, EntryPoint = "pactffi_with_body")]
29+
public static extern bool WithBody(InteractionHandle interaction, InteractionPart part, string contentType, string body);
30+
}
31+
}

src/PactNet.Interop/InteropActionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace PactNet.Interop
55
/// <summary>
66
/// Extensions for checking interop action success
77
/// </summary>
8-
public static class InteropActionExtensions
8+
internal static class InteropActionExtensions
99
{
1010
/// <summary>
1111
/// Check the result of an interop action to ensure it succeeded

src/PactNet.Interop/LevelFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace PactNet.Interop
22
{
3-
public enum LevelFilter
3+
internal enum LevelFilter
44
{
55
Off = 0,
66
Error = 1,

src/PactNet.Interop/LogLevelExtensions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Runtime.InteropServices;
32

43
namespace PactNet.Interop;
54

@@ -36,14 +35,5 @@ public static void InitialiseLogging(this PactLogLevel level)
3635

3736
LogInitialised = true;
3837
}
39-
40-
}
41-
42-
private static class LoggingInterop
43-
{
44-
private const string DllName = "pact_ffi";
45-
46-
[DllImport(DllName, EntryPoint = "pactffi_log_to_buffer")]
47-
public static extern int LogToBuffer(LevelFilter levelFilter);
4838
}
4939
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace PactNet.Interop;
4+
5+
internal static class LoggingInterop
6+
{
7+
private const string DllName = "pact_ffi";
8+
9+
[DllImport(DllName, EntryPoint = "pactffi_log_to_buffer")]
10+
public static extern int LogToBuffer(LevelFilter levelFilter);
11+
12+
[DllImport(DllName, EntryPoint = "pactffi_fetch_log_buffer")]
13+
public static extern string FetchLogBuffer(string logId);
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace PactNet.Interop;
5+
6+
internal static class MessagingInterop
7+
{
8+
private const string DllName = "pact_ffi";
9+
10+
[DllImport(DllName, EntryPoint = "pactffi_with_message_pact_metadata")]
11+
public static extern void WithMessagePactMetadata(PactHandle pact, string @namespace, string name, string value);
12+
13+
[DllImport(DllName, EntryPoint = "pactffi_new_message_interaction")]
14+
public static extern InteractionHandle NewMessageInteraction(PactHandle pact, string description);
15+
16+
[DllImport(DllName, EntryPoint = "pactffi_message_expects_to_receive")]
17+
public static extern void MessageExpectsToReceive(InteractionHandle message, string description);
18+
19+
[DllImport(DllName, EntryPoint = "pactffi_message_with_metadata")]
20+
public static extern void MessageWithMetadata(InteractionHandle message, string key, string value);
21+
22+
[DllImport(DllName, EntryPoint = "pactffi_message_with_contents")]
23+
public static extern void MessageWithContents(InteractionHandle message, string contentType, string body, UIntPtr size);
24+
25+
[DllImport(DllName, EntryPoint = "pactffi_message_reify")]
26+
public static extern IntPtr MessageReify(InteractionHandle message);
27+
}

0 commit comments

Comments
 (0)