Skip to content

Commit

Permalink
test(449): Add a test to reproduce issue #449
Browse files Browse the repository at this point in the history
  • Loading branch information
adamrodger committed Apr 9, 2023
1 parent e7de8d4 commit d4b105b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PactNet/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ internal RequestBuilder Given(string providerState)
/// </summary>
/// <param name="providerState">Provider state description</param>
/// <param name="parameters">Provider state parameters</param>
/// <returns>Flient builder</returns>
/// <returns>Fluent builder</returns>
internal RequestBuilder Given(string providerState, IDictionary<string, string> parameters)
{
foreach (var param in parameters)
Expand Down
54 changes: 54 additions & 0 deletions tests/PactNet.Tests/Drivers/FfiIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,59 @@ public void MessageInteraction_v3_CreatesPactFile()
string expectedPactContent = File.ReadAllText("data/v3-message-integration.json").TrimEnd();
pactContents.Should().Be(expectedPactContent);
}

[Fact]
[Trait("issue", "449")]
public async Task HttpInteraction_NumericProviderStateParameter_CreatesPactFile()
{
var driver = new PactDriver();

try
{
IHttpPactDriver pact = driver.NewHttpPact("NativeDriverTests-Consumer-NumericProviderStateParam",
"NativeDriverTests-Provider",
PactSpecification.V3);

IHttpInteractionDriver interaction = pact.NewHttpInteraction("an interaction with a numeric provider state param");

interaction.GivenWithParam("state with param", "issue", "449");
interaction.WithRequest("GET", "/path");

interaction.WithResponseStatus((ushort)HttpStatusCode.OK);
interaction.WithResponseBody("application/json", @"{""foo"":42}");

using IMockServerDriver mockServer = pact.CreateMockServer("127.0.0.1", null, false);

var client = new HttpClient { BaseAddress = mockServer.Uri };

HttpResponseMessage result = await client.GetAsync("/path");
result.StatusCode.Should().Be(HttpStatusCode.OK);

string content = await result.Content.ReadAsStringAsync();
content.Should().Be(@"{""foo"":42}");

mockServer.MockServerMismatches().Should().Be("[]");

string logs = mockServer.MockServerLogs();
logs.Should().NotBeEmpty();

this.output.WriteLine("Mock Server Logs");
this.output.WriteLine("----------------");
this.output.WriteLine(logs);

pact.WritePactFile(Environment.CurrentDirectory);
}
finally
{
this.WriteDriverLogs(driver);
}

var file = new FileInfo("NativeDriverTests-Consumer-NumericProviderStateParam-NativeDriverTests-Provider.json");
file.Exists.Should().BeTrue();

string pactContents = File.ReadAllText(file.FullName).TrimEnd();
string expectedPactContent = File.ReadAllText("data/v3-server-numeric-provider-state-param.json").TrimEnd();
pactContents.Should().Be(expectedPactContent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"consumer": {
"name": "NativeDriverTests-Consumer-NumericProviderStateParam"
},
"interactions": [
{
"description": "an interaction with a numeric provider state param",
"providerStates": [
{
"name": "state with param",
"params": {
"issue": "449"
}
}
],
"request": {
"method": "GET",
"path": "/path"
},
"response": {
"body": {
"foo": 42
},
"headers": {
"Content-Type": "application/json"
},
"status": 200
}
}
],
"metadata": {
"pactRust": {
"ffi": "0.4.0",
"models": "1.0.4"
},
"pactSpecification": {
"version": "3.0.0"
}
},
"provider": {
"name": "NativeDriverTests-Provider"
}
}

0 comments on commit d4b105b

Please sign in to comment.