<#476 Pact verification with CamelCase model names...
# pact-net
g
#476 Pact verification with CamelCase model names Issue created by Nick-Sullivan I'm having trouble verifying a pact when the models use CamelCase structure, using pact-net version 4.5.0. The consumer runs successfully if I use the
CamelCasePropertyNamesContractResolver
, and generates a pact with lowercase model names, but the provider verification fails. The provider passes if I use lowercase model names. Is there a way to maintain capitalisation in the pact, or make the provider verification ignore capitalisation? Consumer snippet
Copy code
var config = new PactConfig
{
    PactDir = $"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName}{Path.DirectorySeparatorChar}pacts",
    LogLevel = PactLogLevel.Debug,
    DefaultJsonSettings = new JsonSerializerSettings
    {
        ContractResolver = new CamelCasePropertyNamesContractResolver(),  // Consumer passes because of this
    }
};

var pact = Pact.V3("Service.Consumer", "Service.Provider", config);
_pactBuilder = pact.WithHttpInteractions();
_pactBuilder
    .UponReceiving("ItShouldReturnAStreetName_IfAvailable")
        .Given("streets exist")
        .WithRequest(<http://HttpMethod.Post|HttpMethod.Post>, "/v1.0/street")
        .WithJsonBody(new { Name = "Mocky" })
    .WillRespond()
        .WithStatus(HttpStatusCode.OK)
        .WithHeader("Content-Type", "application/json; charset=utf-8")
        .WithJsonBody(new { Street = "Mock Street" });

await _pactBuilder.VerifyAsync(async ctx =>
{
    var client = new ApiClient(ctx.MockServerUri);
    var response = await client.GetStreetName(new StreetRequest { Name = "Mocky" });
    Assert.AreEqual("Mock Street", response.Street);
});
Pact snippet
Copy code
"response": {
  "body": {
    "street": "Mock Street"
  },
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "status": 200
}
Provider snippet
Copy code
var pactDir = $"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName}{Path.DirectorySeparatorChar}pacts";
_pactFile = new FileInfo($"{pactDir}{Path.DirectorySeparatorChar}Service.Consumer-Service.Provider.json");
_pactVerifier = new PactVerifier(new PactVerifierConfig());
_fixture = new WebServerFixture(); // this fixture is the class from the README
_pactVerifier.ServiceProvider("WhenGettingAStreet", _fixture.ServerUri)
    .WithFileSource(_pactFile)
    .WithProviderStateUrl(new Uri(_fixture.ServerUri, "/provider-states"))
    .Verify();
pact-foundation/pact-net