Contract testing on dictionary of objects

335 views Asked by At

I'm trying to write contract tests for an object that contains a dictionary of objects. I want to verify the entries respect my contract. The keys are changing between the consumer and provider. Right now, the matching rules of my contract are trying to find specific keys in the body of my message such as "$.properties.desired.deploymentsRemovals['4JgEA5GCeqwVsu6Qada9XS'].appId" Is it possible to write contract tests in my situation? I'm using the PactNet nuget version 4.0.0-beta.3. Using a matcher on the key such as

deployments = new Dictionary<object, object> {
                            {Match.Type("6XKISmGMWynbwM52mxov6S"),  
                                new {...

produces a contract searching for "pactNet.Matchers.TypeMatcher" as the key

"deployments": {
          "pactNet.Matchers.TypeMatcher": {
1

There are 1 answers

1
YOU54F On

I'm Yousaf, A developer advocate here at Pact https://pact.io/ and Pactflow - https://pactflow.io/

We have an open forum about contract testing in our Pact Foundation Slack, you can join over at https://slack.pact.io

You may find the pact-net channel of particular interest.

.NET isn't my forte, and I haven't spend much time on StackOverflow in past, I hope to now!

You should be able to use matchers in your pact-net library, they were designed in V2 Pact specification onwards to solve that exact problem

Which particular version and library are you using, there are various implementations, both official and community supported.

There should be examples of their implementation in your respective libraries readme, but let me know if there isn't, and we can look to resolve.

We plan to display these matcher implementations across the various languages very soon