Skip to content

Commit e6c73e7

Browse files
authored
Merge pull request #8 from pactflow/dotnet6_pactnet450
Dotnet6 pactnet450
2 parents 951aff4 + 377aa86 commit e6c73e7

File tree

9 files changed

+104
-140
lines changed

9 files changed

+104
-140
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
strategy:
1919
matrix:
20-
dotnet-version: ["3.1.x"]
20+
dotnet-version: ["6.0.x"]
2121
pact_provider:
2222
[
2323
# "pactflow-example-bi-directional-provider-dredd",
@@ -27,9 +27,9 @@ jobs:
2727
'pactflow-provider-dotnet'
2828
]
2929
steps:
30-
- uses: actions/checkout@v2
30+
- uses: actions/checkout@v3
3131
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
32-
uses: actions/setup-dotnet@v1.7.2
32+
uses: actions/setup-dotnet@v3.0.3
3333
with:
3434
dotnet-version: ${{ matrix.dotnet-version }}
3535
- name: test for ${{ matrix.pact_provider }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode/
22
bin/
3-
obj/
3+
obj/
4+
.DS_Store

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ restore:
2424
dotnet restore src
2525
dotnet restore tests
2626

27+
run:
28+
cd src && dotnet run
29+
2730
ci: clean restore test publish_pacts can_i_deploy $(DEPLOY_TARGET)
2831

2932
# Run the ci target from a developer machine with the environment variables
@@ -36,7 +39,7 @@ fake_ci:
3639
make ci
3740

3841
publish_pacts:
39-
@"${PACT_CLI}" publish ${PWD}/pacts --consumer-app-version ${GIT_COMMIT} --tag ${GIT_BRANCH}
42+
@"${PACT_CLI}" publish ${PWD}/pacts --consumer-app-version ${GIT_COMMIT} --branch ${GIT_BRANCH}
4043

4144
## =====================
4245
## Build/test tasks
@@ -50,7 +53,7 @@ test:
5053
## Deploy tasks
5154
## =====================
5255

53-
deploy: deploy_app tag_as_prod
56+
deploy: deploy_app record_deployment
5457

5558
no_deploy:
5659
@echo "Not deploying as not on master branch"
@@ -59,15 +62,15 @@ can_i_deploy:
5962
@"${PACT_CLI}" broker can-i-deploy \
6063
--pacticipant ${PACTICIPANT} \
6164
--version ${GIT_COMMIT} \
62-
--to prod \
65+
--to-environment production \
6366
--retry-while-unknown 0 \
6467
--retry-interval 10
6568

6669
deploy_app:
6770
@echo "Deploying to prod"
6871

69-
tag_as_prod:
70-
@"${PACT_CLI}" broker create-version-tag --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --tag prod
72+
record_deployment: .env
73+
@"${PACT_CLI}" broker record-deployment --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --environment production
7174

7275
## =====================
7376
## PactFlow set up tasks

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The project uses a Makefile to simulate a very simple build pipeline with two st
2525
* Docker
2626
* A [PactFlow](https://pactflow.io) account
2727
* A [read/write API Token](https://docs.pactflow.io/#configuring-your-api-token) from your PactFlow account
28-
* .NET 3.1.201 installed. You can install it from here: https://docs.microsoft.com/en-us/dotnet/core/install/macos
28+
* .NET 6.x installed. You can install it from here: https://docs.microsoft.com/en-us/dotnet/core/install/macos
2929

3030
## Usage
3131

pacts/pactflow-example-consumer-dotnet-pactflow-example-provider-dotnet.json

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,57 @@
22
"consumer": {
33
"name": "pactflow-example-consumer-dotnet"
44
},
5-
"provider": {
6-
"name": "pactflow-example-provider-dotnet"
7-
},
85
"interactions": [
96
{
107
"description": "A request to get products",
11-
"providerState": "products exist",
8+
"providerStates": [
9+
{
10+
"name": "products exist"
11+
}
12+
],
1213
"request": {
13-
"method": "get",
14+
"method": "GET",
1415
"path": "/products"
1516
},
1617
"response": {
17-
"status": 200,
18-
"headers": {
19-
"Content-Type": "application/json; charset=utf-8"
20-
},
2118
"body": [
2219
{
2320
"id": "27",
2421
"name": "burger",
2522
"type": "food"
2623
}
2724
],
25+
"headers": {
26+
"Content-Type": "application/json; charset=utf-8"
27+
},
2828
"matchingRules": {
29-
"$.body": {
30-
"min": 1
29+
"body": {
30+
"$": {
31+
"combine": "AND",
32+
"matchers": [
33+
{
34+
"match": "type",
35+
"min": 1
36+
}
37+
]
38+
}
3139
},
32-
"$.body[*].*": {
33-
"match": "type"
34-
}
35-
}
40+
"header": {}
41+
},
42+
"status": 200
3643
}
3744
}
3845
],
3946
"metadata": {
47+
"pactRust": {
48+
"ffi": "0.4.0",
49+
"models": "1.0.4"
50+
},
4051
"pactSpecification": {
41-
"version": "2.0.0"
52+
"version": "3.0.0"
4253
}
54+
},
55+
"provider": {
56+
"name": "pactflow-example-provider-dotnet"
4357
}
4458
}

src/consumer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

tests/ConsumerPactClassFixture.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.

tests/ConsumerPactTests.cs

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,69 @@
11
using System;
2+
using System.IO;
23
using Xunit;
3-
using PactNet.Mocks.MockHttpService;
4-
using PactNet.Mocks.MockHttpService.Models;
4+
using Xunit.Abstractions;
5+
using PactNet;
56
using Consumer;
67
using System.Collections.Generic;
7-
using PactNet.Matchers.Type;
8+
using System.Net.Http;
9+
using System.Net;
10+
using PactNet.Matchers;
811
using FluentAssertions;
12+
using PactNet.Infrastructure.Outputters;
13+
using PactNet.Output.Xunit;
14+
using System.Threading.Tasks;
915

1016
namespace tests
1117
{
12-
public class ConsumerPactTests : IClassFixture<ConsumerPactClassFixture>
18+
public class ConsumerPactTests
1319
{
14-
private IMockProviderService _mockProviderService;
15-
private string _mockProviderServiceBaseUri;
20+
private IPactBuilderV3 pact;
21+
// private readonly int port = 9222;
1622

17-
public ConsumerPactTests(ConsumerPactClassFixture fixture)
23+
private readonly List<object> products;
24+
25+
public ConsumerPactTests(ITestOutputHelper output)
1826
{
19-
_mockProviderService = fixture.MockProviderService;
20-
_mockProviderService.ClearInteractions(); //NOTE: Clears any previously registered interactions before the test is run
21-
_mockProviderServiceBaseUri = fixture.MockProviderServiceBaseUri;
27+
28+
products = new List<object>()
29+
{
30+
new { id = "27", name = "burger", type = "food" }
31+
};
32+
33+
var Config = new PactConfig
34+
{
35+
PactDir = Path.Join("..", "..", "..", "..", "pacts"),
36+
Outputters = new List<IOutput> { new XunitOutput(output), new ConsoleOutput() },
37+
LogLevel = PactLogLevel.Debug
38+
};
39+
40+
pact = Pact.V3("pactflow-example-consumer-dotnet", "pactflow-example-provider-dotnet", Config).WithHttpInteractions();
2241
}
2342

2443
[Fact]
25-
public async void RetrieveProducts()
44+
public async Task RetrieveProducts()
2645
{
2746
// Arrange
28-
_mockProviderService.Given("products exist")
29-
.UponReceiving("A request to get products")
30-
.With(new ProviderServiceRequest
31-
{
32-
Method = HttpVerb.Get,
33-
Path = "/products",
34-
})
35-
.WillRespondWith(new ProviderServiceResponse {
36-
Status = 200,
37-
Headers = new Dictionary<string, object>
38-
{
39-
{ "Content-Type", "application/json; charset=utf-8" }
40-
},
41-
Body = new MinTypeMatcher(new
42-
{
43-
id = "27",
44-
name = "burger",
45-
type = "food"
46-
}, 1)
47-
});
48-
49-
// Act
50-
var consumer = new ProductClient();
51-
List<Product> result = await consumer.GetProducts(_mockProviderServiceBaseUri);
52-
53-
// Assert
54-
result.Should().NotBeNull();
55-
result.Should().HaveCount(1);
56-
result[0].id.Should().Equals("27");
57-
result[0].name.Should().Equals("burger");
58-
result[0].type.Should().Equals("food");
47+
pact.UponReceiving("A request to get products")
48+
.Given("products exist")
49+
.WithRequest(HttpMethod.Get, "/products")
50+
.WillRespond()
51+
.WithStatus(HttpStatusCode.OK)
52+
.WithHeader("Content-Type", "application/json; charset=utf-8")
53+
.WithJsonBody(Match.MinType(products[0],1));
54+
55+
await pact.VerifyAsync(async ctx =>
56+
{
57+
// Act
58+
var consumer = new ProductClient();
59+
List<Product> result = await consumer.GetProducts(ctx.MockServerUri.ToString().TrimEnd('/'));
60+
// Assert
61+
result.Should().NotBeNull();
62+
result.Should().HaveCount(1);
63+
Assert.Equal("27",result[0].id);
64+
Assert.Equal("burger",result[0].name);
65+
Assert.Equal("food",result[0].type);
66+
});
5967
}
6068
}
6169
}

tests/tests.csproj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -11,12 +11,13 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
15-
<PackageReference Include="PactNet.OSX" Version="2.5.5" />
16-
<PackageReference Include="PactNet.Windows" Version="2.5.5" />
17-
<PackageReference Include="PactNet.Linux.x64" Version="2.5.5" />
18-
<PackageReference Include="xunit" Version="2.3.1" />
19-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
15+
<PackageReference Include="PactNet" Version="4.5.0" />
16+
<PackageReference Include="PactNet.Output.Xunit" Version="1.0.0" />
17+
<PackageReference Include="xunit" Version="2.4.1" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"/>
19+
</ItemGroup>
20+
<ItemGroup>
21+
<None Remove="XUnitHelpers\" />
2022
</ItemGroup>
21-
2223
</Project>

0 commit comments

Comments
 (0)