The Typestate Pattern in C# - Redesigning PactNet

The typestate pattern uses the static type system of a language to move potential runtime errors to compile time errors instead. This article discusses the redesign of PactNet v4.0.0 to use that pattern to make code which would create invalid conditions impossible to compile instead of erroring at runtime. Pact creates a contract between a consumer and a provider which can be verified during Continuous Integration to ensure that both components are compatible before they’re deployed to an environment.

Unit Testing with Mocks

When unit testing classes that have followed SOLID principles, we often find classes take on the responsibility of a co-ordinator rather than implementing any specific logic themselves. When testing these classes it makes perfect sense to use mocks (e.g. the Moq library) to control the dependencies being co-ordinated. However, I sometimes see instances where people have misunderstood how these mocks work and why the test ends up not testing what it appears to.

Service Evolution with Consumer Driven Contracts and Pact

In a microservices architecture with a suite of inter-dependent services, ensuring fast feedback when API changes cause incompatibility becomes a key problem. Any time that incompatible services are deployed to an environment you will have caused a preventable outage that should be detected as part of your usual Continuous Integration solution. At dunnhumby, we use a squad based approach to application development which sees small ‘vertical’ teams form with team members representing all of the ‘horizontals’, such as API, UI and QA.