Skip to content

Commit 4e8fc89

Browse files
committed
refactor(ffi-interop): Encapsulate PluginInterop methods
1 parent 9b8251c commit 4e8fc89

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

samples/Grpc/GrpcGreeterClient.Tests/GrpcGreeterClientTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public async Task ReturnsMismatchWhenNoGrpcClientRequestMade()
3838
""message"": ""matching(type, 'Hello foo')""
3939
}}
4040
}}";
41-
NativeInterop.PluginAdd(pact, "protobuf", "0.4.0");
42-
NativeInterop.PluginInteractionContents(interaction, 0, "application/grpc", content);
41+
PluginInterop.PluginAdd(pact, "protobuf", "0.4.0");
42+
PluginInterop.PluginInteractionContents(interaction, 0, "application/grpc", content);
4343

4444
using var driver = MockServer.CreateMockServer(pact, host, 0, "grpc", false);
4545
var port = driver.Port;
@@ -58,7 +58,7 @@ public async Task ReturnsMismatchWhenNoGrpcClientRequestMade()
5858
ErrorString.Should().Be("Did not receive any requests for path 'Greeter/SayHello'");
5959
ExpectedPath.Should().Be("Greeter/SayHello");
6060

61-
NativeInterop.PluginCleanup(pact);
61+
PluginInterop.PluginCleanup(pact);
6262
await Task.Delay(1);
6363
}
6464
[Fact]
@@ -81,8 +81,8 @@ public async Task WritesPactWhenGrpcClientRequestMade()
8181
}}
8282
}}";
8383

84-
NativeInterop.PluginAdd(pact, "protobuf", "0.4.0");
85-
NativeInterop.PluginInteractionContents(interaction, 0, "application/grpc", content);
84+
PluginInterop.PluginAdd(pact, "protobuf", "0.4.0");
85+
PluginInterop.PluginInteractionContents(interaction, 0, "application/grpc", content);
8686

8787
using var driver = MockServer.CreateMockServer(pact, host, 0, "grpc", false);
8888
var port = driver.Port;
@@ -105,7 +105,7 @@ public async Task WritesPactWhenGrpcClientRequestMade()
105105
MismatchesString.Should().Be("[]");
106106

107107
PactFileWriter.WritePactFileForPort(port, "../../../../pacts");
108-
NativeInterop.PluginCleanup(pact);
108+
PluginInterop.PluginCleanup(pact);
109109
}
110110

111111
}

src/PactNet.Interop/NativeInterop.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,6 @@ public static class NativeInterop
1313
[DllImport(DllName, EntryPoint = "pactffi_log_to_buffer")]
1414
public static extern int LogToBuffer(LevelFilter levelFilter);
1515

16-
#region Plugin Support
17-
18-
[DllImport(DllName, EntryPoint = "pactffi_using_plugin")]
19-
public static extern uint PluginAdd(PactHandle pact, string name, string version);
20-
21-
[DllImport(DllName, EntryPoint = "pactffi_interaction_contents")]
22-
public static extern uint PluginInteractionContents(uint interaction, InteractionPart part, string contentType, string body);
23-
24-
[DllImport(DllName, EntryPoint = "pactffi_cleanup_plugins")]
25-
public static extern void PluginCleanup(PactHandle pact);
26-
27-
#endregion
28-
2916
#region Http Interop Support
3017

3118
[DllImport(DllName, EntryPoint = "pactffi_fetch_log_buffer")]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace PactNet.Interop;
4+
5+
public class PluginInterop
6+
{
7+
private const string DllName = "pact_ffi";
8+
9+
[DllImport(DllName, EntryPoint = "pactffi_using_plugin")]
10+
public static extern uint PluginAdd(PactHandle pact, string name, string version);
11+
12+
[DllImport(DllName, EntryPoint = "pactffi_interaction_contents")]
13+
public static extern uint PluginInteractionContents(uint interaction, InteractionPart part, string contentType, string body);
14+
15+
[DllImport(DllName, EntryPoint = "pactffi_cleanup_plugins")]
16+
public static extern void PluginCleanup(PactHandle pact);
17+
}

0 commit comments

Comments
 (0)