Good morning :slightly_smiling_face: someone can s...
# pact-net
y
Good morning 🙂 someone can show me how can i verify contract on pact broker via the code ( i know how to do it on js but i didn't find how to set publishVerificationResult to be true)
I think there’s an example in here
y
maybe im missing something 😕 ConsumerTests are the tests that create the contract or the ones that verify against it? currently, my consumer is verifying against the broker and my provider creating the contract
t
The consumer tests create the contract (and sends it to the broker) The provider verification takes the contract from the broker, and checks that the provider satisfies the contract
The part I was trying to draw your attention to is this part:
Copy code
verifier.ServiceProvider("My Provider", this.fixture.ServerUri)
                .WithPactBrokerSource(new Uri("<https://broker.example.org>"), options =>
                {
                    options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true, Latest = true })
                           .PublishResults(version, results =>
                           {
                               results.ProviderBranch(branch)
                                      .BuildUri(new Uri(buildUri));
                           });
                })
                .WithProviderStateUrl(new Uri(this.fixture.ServerUri, "/provider-states"))
                .Verify();
☝️ 1
It looks to me like
.PublishResults
is the equivalent of
publishVerificationResult
. But I don’t know for sure - I don’t know .NET
y
My contract is event-driven via msgs :
Copy code
var messagePact = GetPactBuilder(contractName, provider, pactDir);
        var messageBuilderV3 = messagePact.ExpectsToReceive(description).Given(providerState);
        var configuredMessageVerifier = messageBuilderV3.WithJsonContent(data);

        await configuredMessageVerifier.VerifyAsync<object>(entityMessageHandler);
t
I think you might be confused by the
VerifyAsync
name - that verify isn’t the provider verification
y
i did (maybe too many examples) - will take a second look
t
it’s verifying that the consumer did work
So, in a consumer test, you don’t publish the verification result (because you’re not verifying a contract)
you publish the contract, because you’re creating a contract
m
I think you might be confused by the
VerifyAsync
name - that verify isn’t the provider verification
Yes, I think that’s the .NET “Async” feature (hence why in the example it’s `await`ed, nothing to do with Pact’s event driven model (unfortunate naming, but I can understand why)
I’m pretty sure Tim is right, the option is on the “source” that you fetch the contract from. In any place you contact a Pact Broker, this option should be available: https://github.com/pact-foundation/pact-net/blob/9eb58b3057eea281fbbd123880c7d327665d17bd/src/PactNet/Verifier/PactUriOptions.cs#L65
y
i understood i mixed between them 🙂 this one is for the consumer .VerifyAsync<object>(entityMessageHandler) , and this one is for the provider : .MessagingProvider(producerName, defaultSettings) .WithProviderMessages(scenarios => { scenarios.Add(description, retrieveScenariosActionMethod); }) .WithPactBrokerSource(new Uri(PactBrokerServiceUrl), options => { options.EnablePending() .ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }) .PublishResults(version, publish => publish.ProviderBranch(branch)); // 👈 enable publishing results }) .Verify(); - thanks for the clarification
t
It's hard to tell without the code formatting (you can use ``` on a new line each side of your code to format your code) , but I think you have it right
🙌 1