GitHub
09/14/2023, 2:26 AMCamelCasePropertyNamesContractResolver, 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
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
"response": {
"body": {
"street": "Mock Street"
},
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"status": 200
}
Provider snippet
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-netGitHub
09/17/2023, 10:54 PM