Skip to content

Commit

Permalink
refactor: Overhaul the sample project
Browse files Browse the repository at this point in the history
The old sample was confusing because it tried to do too much for one,
and also because the concepts of HTTP and message interactions were
split across multiple examples. There was also a separate Readme sample
which effectively just did the same thing as the canonical example.

Now there's one combined sample which demonstrates the most commonly
used features of both HTTP and message interactions, matchers and
provider states. It's presented in a much more realistic scenario of a
fulfilment component which responds to orders being created via pubsub
and then updates the order, so should be easier to intuitively
understand.
  • Loading branch information
adamrodger committed Jun 28, 2023
1 parent 3d72f08 commit 9a4aea9
Show file tree
Hide file tree
Showing 94 changed files with 1,175 additions and 2,696 deletions.
136 changes: 5 additions & 131 deletions PactNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{547DB478-460A-428F-9371-1D653CE85DB5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EventApi", "EventApi", "{6663C12E-9912-40D0-9310-D119D1F6B023}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OrdersApi", "OrdersApi", "{6663C12E-9912-40D0-9310-D119D1F6B023}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Consumer", "samples\EventApi\Consumer\Consumer.csproj", "{1B9BAF2F-906B-4358-A1EF-AC79F7966B75}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Consumer", "samples\OrdersApi\Consumer\Consumer.csproj", "{1B9BAF2F-906B-4358-A1EF-AC79F7966B75}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Consumer.Tests", "samples\EventApi\Consumer.Tests\Consumer.Tests.csproj", "{0A442FF6-4B8D-4E7E-8FE7-F7F37EB034B0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Consumer.Tests", "samples\OrdersApi\Consumer.Tests\Consumer.Tests.csproj", "{0A442FF6-4B8D-4E7E-8FE7-F7F37EB034B0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CF67D7A1-AE96-420B-9971-65E535B903E8}"
EndProject
Expand All @@ -23,29 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PactNet.Abstractions.Tests"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PactNet.Tests", "tests\PactNet.Tests\PactNet.Tests.csproj", "{B8C8934E-9581-46D6-A728-BC5EAB9C06DD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Provider", "samples\EventApi\Provider\Provider.csproj", "{5E915D66-917B-4730-B31A-C9727C196346}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Provider", "samples\OrdersApi\Provider\Provider.csproj", "{5E915D66-917B-4730-B31A-C9727C196346}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Provider.Tests", "samples\EventApi\Provider.Tests\Provider.Tests.csproj", "{D8B75E48-6E45-468B-8049-B73823C14CB8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Messaging", "Messaging", "{9BA1DB3F-BD05-4E6A-861F-E1FEE63DC76F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Consumer", "samples\Messaging\Consumer\Consumer.csproj", "{1D977F8E-D3C1-4730-BE46-B2F916761CF4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Consumer.Tests", "samples\Messaging\Consumer.Tests\Consumer.Tests.csproj", "{AED4E706-6E99-47B8-BE17-A3503275DB3E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ReadMe", "ReadMe", "{87FC5A4B-1977-4FBA-AA71-63F48B28C3B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Readme.Consumer", "samples\ReadMe\Consumer\Readme.Consumer.csproj", "{B7363201-F52A-49C4-A299-C9B459827C04}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Readme.Consumer.Tests", "samples\ReadMe\Consumer.Tests\Readme.Consumer.Tests.csproj", "{B180E079-9392-44F8-BF44-EB2E0D205FA1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Readme.Provider", "samples\ReadMe\Provider\Readme.Provider.csproj", "{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Readme.Provider.Tests", "samples\ReadMe\Provider.Tests\Readme.Provider.Tests.csproj", "{172916A7-5913-4389-8F58-A774036C9566}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Provider", "samples\Messaging\Provider\Provider.csproj", "{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Provider.Tests", "samples\Messaging\Provider.Tests\Provider.Tests.csproj", "{16429FC0-67A5-4089-98A9-CBD72D9DB910}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Provider.Tests", "samples\OrdersApi\Provider.Tests\Provider.Tests.csproj", "{D8B75E48-6E45-468B-8049-B73823C14CB8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E2C86290-F39C-4854-A7D2-D6C44CB1C65F}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -163,102 +143,6 @@ Global
{D8B75E48-6E45-468B-8049-B73823C14CB8}.Release|x64.Build.0 = Release|Any CPU
{D8B75E48-6E45-468B-8049-B73823C14CB8}.Release|x86.ActiveCfg = Release|Any CPU
{D8B75E48-6E45-468B-8049-B73823C14CB8}.Release|x86.Build.0 = Release|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Debug|x64.ActiveCfg = Debug|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Debug|x64.Build.0 = Debug|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Debug|x86.ActiveCfg = Debug|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Debug|x86.Build.0 = Debug|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Release|Any CPU.Build.0 = Release|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Release|x64.ActiveCfg = Release|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Release|x64.Build.0 = Release|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Release|x86.ActiveCfg = Release|Any CPU
{1D977F8E-D3C1-4730-BE46-B2F916761CF4}.Release|x86.Build.0 = Release|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Debug|x64.ActiveCfg = Debug|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Debug|x64.Build.0 = Debug|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Debug|x86.ActiveCfg = Debug|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Debug|x86.Build.0 = Debug|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Release|Any CPU.Build.0 = Release|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Release|x64.ActiveCfg = Release|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Release|x64.Build.0 = Release|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Release|x86.ActiveCfg = Release|Any CPU
{AED4E706-6E99-47B8-BE17-A3503275DB3E}.Release|x86.Build.0 = Release|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Debug|x64.ActiveCfg = Debug|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Debug|x64.Build.0 = Debug|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Debug|x86.ActiveCfg = Debug|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Debug|x86.Build.0 = Debug|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Release|Any CPU.Build.0 = Release|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Release|x64.ActiveCfg = Release|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Release|x64.Build.0 = Release|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Release|x86.ActiveCfg = Release|Any CPU
{B7363201-F52A-49C4-A299-C9B459827C04}.Release|x86.Build.0 = Release|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Debug|x64.ActiveCfg = Debug|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Debug|x64.Build.0 = Debug|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Debug|x86.ActiveCfg = Debug|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Debug|x86.Build.0 = Debug|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Release|Any CPU.Build.0 = Release|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Release|x64.ActiveCfg = Release|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Release|x64.Build.0 = Release|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Release|x86.ActiveCfg = Release|Any CPU
{B180E079-9392-44F8-BF44-EB2E0D205FA1}.Release|x86.Build.0 = Release|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Debug|x64.ActiveCfg = Debug|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Debug|x64.Build.0 = Debug|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Debug|x86.ActiveCfg = Debug|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Debug|x86.Build.0 = Debug|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Release|Any CPU.Build.0 = Release|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Release|x64.ActiveCfg = Release|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Release|x64.Build.0 = Release|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Release|x86.ActiveCfg = Release|Any CPU
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB}.Release|x86.Build.0 = Release|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Debug|Any CPU.Build.0 = Debug|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Debug|x64.ActiveCfg = Debug|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Debug|x64.Build.0 = Debug|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Debug|x86.ActiveCfg = Debug|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Debug|x86.Build.0 = Debug|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Release|Any CPU.ActiveCfg = Release|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Release|Any CPU.Build.0 = Release|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Release|x64.ActiveCfg = Release|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Release|x64.Build.0 = Release|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Release|x86.ActiveCfg = Release|Any CPU
{172916A7-5913-4389-8F58-A774036C9566}.Release|x86.Build.0 = Release|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Debug|x64.ActiveCfg = Debug|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Debug|x64.Build.0 = Debug|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Debug|x86.ActiveCfg = Debug|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Debug|x86.Build.0 = Debug|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Release|Any CPU.Build.0 = Release|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Release|x64.ActiveCfg = Release|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Release|x64.Build.0 = Release|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Release|x86.ActiveCfg = Release|Any CPU
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311}.Release|x86.Build.0 = Release|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Debug|x64.ActiveCfg = Debug|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Debug|x64.Build.0 = Debug|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Debug|x86.ActiveCfg = Debug|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Debug|x86.Build.0 = Debug|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Release|Any CPU.Build.0 = Release|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Release|x64.ActiveCfg = Release|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Release|x64.Build.0 = Release|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Release|x86.ActiveCfg = Release|Any CPU
{16429FC0-67A5-4089-98A9-CBD72D9DB910}.Release|x86.Build.0 = Release|Any CPU
{02E265A1-A7A2-4106-8F6A-5027FDC3FC50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02E265A1-A7A2-4106-8F6A-5027FDC3FC50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02E265A1-A7A2-4106-8F6A-5027FDC3FC50}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -285,16 +169,6 @@ Global
{B8C8934E-9581-46D6-A728-BC5EAB9C06DD} = {A117BBC6-60BB-4282-BF10-E616DE0AFAD0}
{5E915D66-917B-4730-B31A-C9727C196346} = {6663C12E-9912-40D0-9310-D119D1F6B023}
{D8B75E48-6E45-468B-8049-B73823C14CB8} = {6663C12E-9912-40D0-9310-D119D1F6B023}
{9BA1DB3F-BD05-4E6A-861F-E1FEE63DC76F} = {547DB478-460A-428F-9371-1D653CE85DB5}
{1D977F8E-D3C1-4730-BE46-B2F916761CF4} = {9BA1DB3F-BD05-4E6A-861F-E1FEE63DC76F}
{AED4E706-6E99-47B8-BE17-A3503275DB3E} = {9BA1DB3F-BD05-4E6A-861F-E1FEE63DC76F}
{87FC5A4B-1977-4FBA-AA71-63F48B28C3B0} = {547DB478-460A-428F-9371-1D653CE85DB5}
{B7363201-F52A-49C4-A299-C9B459827C04} = {87FC5A4B-1977-4FBA-AA71-63F48B28C3B0}
{B180E079-9392-44F8-BF44-EB2E0D205FA1} = {87FC5A4B-1977-4FBA-AA71-63F48B28C3B0}
{C0666A04-90F2-4C58-A165-6ADB4C71BBBB} = {87FC5A4B-1977-4FBA-AA71-63F48B28C3B0}
{172916A7-5913-4389-8F58-A774036C9566} = {87FC5A4B-1977-4FBA-AA71-63F48B28C3B0}
{1CE30FC5-1439-4FB3-85ED-B2D4E70FB311} = {9BA1DB3F-BD05-4E6A-861F-E1FEE63DC76F}
{16429FC0-67A5-4089-98A9-CBD72D9DB910} = {9BA1DB3F-BD05-4E6A-861F-E1FEE63DC76F}
{02E265A1-A7A2-4106-8F6A-5027FDC3FC50} = {CF67D7A1-AE96-420B-9971-65E535B903E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ Watch our [series](https://www.youtube.com/playlist?list=PLwy9Bnco-IpfZ72VQ7hce8

## Usage

In the sections below, we provide a brief sample of the typical flow for Pact testing, written in the XUnit framework. To see the complete example and run it, check out the `Samples/ReadMe` folder.
In the sections below, we provide a brief sample of the typical flow for Pact testing using HTTP interactions, written in
the XUnit framework.

A more comprehensive example which uses both HTTP and message interactions, provider states, matchers and more can be
found in the [`samples/OrdersApi`](samples/OrdersApi) folder.

### Writing a Consumer test

Expand Down Expand Up @@ -197,7 +201,8 @@ public class SomethingApiTests : IClassFixture<SomethingApiFixture>
"Something API Consumer-Something API.json");

// Act / Assert
IPactVerifier pactVerifier = new PactVerifier("Something API", config);
using var pactVerifier = new PactVerifier("Something API", config);

pactVerifier
.WithHttpEndpoint(fixture.ServerUri)
.WithFileSource(new FileInfo(pactPath))
Expand Down
Loading

0 comments on commit 9a4aea9

Please sign in to comment.