Coder Social home page Coder Social logo

kolluri-rk / contract-testing-dotnetcore-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ddubson/contract-testing-dotnetcore-example

0.0 1.0 0.0 243 KB

Contract Testing example in .NET 5 and C# with PactNET Contract testing framework

License: MIT License

C# 95.06% Shell 4.94%

contract-testing-dotnetcore-example's Introduction

๐Ÿ“œ Contract Testing example in .NET 5 and C# 8

.NET Core Build Status Build Status Maintainability

Contract testing example with two API consumers and one API provider using PactNET. Use this repo as a guide to kick off a conversation about how to write and honor contracts between an API and consumers of that API.

Run ship-it.sh to create and verify contracts between parties. Take a look for more info on parties below in the Scenario section.

โœณ๏ธ Scenario

There is an Address Book API that serves all things related to a person's basic information. This API is popular and now has demand from many vendors that would want to connect to it and use it seamlessly. Our goal is to make sure that all the consumers of the API are using it without issue, and we, as maintainers of the API can modify it, upgrade it, maintain it flawlessly. If we can create a contract between all (or some) of the vendors using this API, we can get feedback immediately if the changes we make to the API break some consumers (or even all of them).

๐Ÿ† Goal: Satisfy the demands of all the API consumers, or get feedback immediately if the contract between a consumer and an API is broken.

Navigating the code of this example

  • Provider (i.e. API): AddressBook.API
  • Provider Verification (i.e. API contract verification tests): AddressBook.API.Tests
  • Consumer 1 (i.e. user of the API): AddressBook.API.Consumer1.Pact
  • Consumer 2 (i.e. another user of the API): AddressBook.API.Consumer2.Pact

๐Ÿค” Gotchas

  • Launching a Test server but no endpoints are loaded When launching a test server in your test cases with PactNet, we use Kestrel as a standalone Http server that hosts your provider, but we register a TestStartup class instead of Startup in AddressBook.API. The Kestrel test server does not automatically register the controllers in the main project so it is very important to make sure that controllers are explicitly registered in Startup.cs. Refer to ConfigureServices method in Startup.cs and point your attention to AddApplicationPart(..) method that makes sure the controllers are registered.

๐Ÿ“ TODO or what's not covered (yet)

  • Contract Testing an OAuth-protected API
  • Publishing Pact contract files to a Pact Broker
  • Non-.NET Core Consumers

contract-testing-dotnetcore-example's People

Contributors

ddubson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.