Closed Nick-Sullivan closed 9 months ago
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.
I can't make sense of this as it seems to contradict itself. What does the provider need to pass - lower case or upper case? What does the consumer need (the correct answer is "the same as the provider" 😆 )
Both the provider and consumer are expecting upper case, but the pact is generating it as lowercase.
If they're expecting upper case, why are the models you use using camel casing?
Sorry, both are expecting camel case, but its a single word so the only difference is that the first letter is uppercase
Maybe I'm reading your response wrong but if the first letter is / should be uppercase, that's not camel casing.
Can you give an example of the model (or one of it properties) and how it appears in the contract vs. how it is expected by the consumer / should be returned by the provider?
Here is the Consumer model:
public class StreetResponse
{
public string Street { get; set; }
}
Here is the Provider model:
public class StreetResponse
{
public string Street { get; set; }
}
Here is what is being saved in the contract:
"response": {
"body": {
"street": "Mock Street"
},
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"status": 200
}
Both the consumer and provider have an uppercase 'S', but the contract uses a lowercase 's', which is causing the pact verification to fail
Your consumer tests have a camel case property resolver set in the serialisation options, which will lower case the first letter and then upper case each word after that, like firstName
So, if you don't want the contract to publish with a lower case leading character then you'll need to stop telling it to do that by removing that from the serialisation options.
I can confirm this, just tested this in my own project and changing
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
}
};
to
var config = new PactConfig
{
PactDir = $"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.FullName}{Path.DirectorySeparatorChar}pacts",
LogLevel = PactLogLevel.Debug,
DefaultJsonSettings = new JsonSerializerSettings()
};
will generate a contract with Pascal-cased elements / model names.
The CamelCasePropertyNamesContractResolver change has done the trick. Also, the way I was using the HttpClient was making requests become lowercase, which complicated things.
It's working now. Thanks for the help all, I really appreciate it.
Awesome, thanks for confirming - thanks all for your help. Will close this one off.
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
Pact snippet
Provider snippet