Hi all! Is there any parameter to publish results ...
# pact-net
a
Hi all! Is there any parameter to publish results in pact broker after the provider verification?
For now, I could perform the following code without problem: pactVerifier .ServiceProvider(ProviderName, _httpClient) .HonoursPactWith(ClientName) .PactUri(string.Format("http://localhost:9851/padcts/provider/Userservice/consumer/Userclient/latest", ClientName, ProviderName)) .Verify();
The verification is begin performed, but I would like to publish the results in pact-broker. Any tips? thanks.
m
There is, I couldn't tell you off the top of my head. I think there's a bug in the latest version. Check the recent GitHub issues and you'll see an example
(sorry on mobile rn)
a
😞 So, for now... The unique way for that is calling pact-broker by command line?
And... in the last versions, did it work well? or not too?
m
A fix in the core went out yesterday, so should be resolved soon.
And... in the last versions, did it work well? or not too?
I don’t know when the regression appeared in Pact .NET sorry
a
@Matt (pactflow.io / pact-js / pact-go) could you share this github issue to me? Just to check and share with my team . I cant find it :/
Appearly none of these can solve the problem to publish results to broker in .net code...
m
I didn’t say they resolved it
417 has some code in there that shows how to publish
a
Ah ok @Matt (pactflow.io / pact-js / pact-go) great! I'll wait looking forward to it because is the unique thing that I still need to show one poc in my company... Without it, its impossible to use... because we need to use pactbroker to verify all results. So, please if you have any news or any workaround to publish results to broker in .net.. let me know in this thread 🙏
👍 1
m
a
Ok, I did some adjustments in my POC and I can to publish results for pactBroker normally by code in .net: verifier.ServiceProvider("Something-API", this.fixture.ServerUri) .WithPactBrokerSource(new Uri("http://localhost:9851"), options => { options.ConsumerVersionSelectors(new ConsumerVersionSelector { Latest = true }) .PublishResults(version); }) .WithProviderStateUrl(new Uri(this.fixture.ServerUri, "/provider-states")) .Verify();
@Matt (pactflow.io / pact-js / pact-go) I don´t know if this issue is related to this same problem but I could solve and results have being published to broker 🙂 .:
🙌 1
m
I think the issue was when publishing the branch details as well (or something similar) so if you're not using branches and environments you might be ok
a
Yes, not for now 😉 But at some moment I will need... therefore, Im gonna follow this issue 🙂
👍 1
Hello @Matt (pactflow.io / pact-js / pact-go). I saw some examples related to pactnet in official github but I still have some doubts regarding the recommendation to create pact files. The best practice is to publish (create a contract) unique pact file between 2 services (provider and consumer, with all interactions and endpoints) or is more recommended to create one pact file by each interaction? In my opinion, I think that the best is to create a unique file between 2 services... However, this doubt appeared me when I saw some examples in .net publishing pact by each test case.
Example pactnet in official github repo:
Copy code
[Fact]
        public async Task GetSomething_WhenTheTesterSomethingExists_ReturnsTheSomething()
        {
            // Arrange
            this.pactBuilder
                .UponReceiving("A GET request to retrieve the something")
                    .Given("There is a something with id 'tester'")
                    .WithRequest(HttpMethod.Get, "/somethings/tester")
                    .WithHeader("Accept", "application/json")
                .WillRespond()
                    .WithStatus(HttpStatusCode.OK)
                    .WithHeader("Content-Type", "application/json; charset=utf-8")
                    .WithJsonBody(new
                    {
                        id = "tester",
                        firstName = "Totally",
                        lastName = "Awesome"
                    });

            await this.pactBuilder.VerifyAsync(async ctx =>
            {
                // Act
                var client = new SomethingApiClient(ctx.MockServerUri);
                var something = await client.GetSomething("tester");

                // Assert
                Assert.Equal("tester", something.Id);
            });
        }