GithubHelp home page GithubHelp logo

Comments (10)

mefellows avatar mefellows commented on September 18, 2024 1

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" 😆 )

from pact-net.

Nick-Sullivan avatar Nick-Sullivan commented on September 18, 2024

Both the provider and consumer are expecting upper case, but the pact is generating it as lowercase.

from pact-net.

basdijkstra avatar basdijkstra commented on September 18, 2024

If they're expecting upper case, why are the models you use using camel casing?

from pact-net.

Nick-Sullivan avatar Nick-Sullivan commented on September 18, 2024

Sorry, both are expecting camel case, but its a single word so the only difference is that the first letter is uppercase

from pact-net.

basdijkstra avatar basdijkstra commented on September 18, 2024

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?

from pact-net.

Nick-Sullivan avatar Nick-Sullivan commented on September 18, 2024

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

from pact-net.

adamrodger avatar adamrodger commented on September 18, 2024

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.

from pact-net.

basdijkstra avatar basdijkstra commented on September 18, 2024

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.

from pact-net.

Nick-Sullivan avatar Nick-Sullivan commented on September 18, 2024

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.

from pact-net.

mefellows avatar mefellows commented on September 18, 2024

Awesome, thanks for confirming - thanks all for your help. Will close this one off.

from pact-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.