Versioning

Testing Versioned API’s in ASP.Net Web API

I recently wrote about a framework for Versioning ASP.Net Web API. Continuing on the theme of versioning API’s, I researched how to test the different versions of a Web API, both for unit tests and SpecFlow acceptance tests.

Overview

As a quick review, the SDammann.WebApi.Versioning package was used for versioning the API and provides methods for selecting the controller that is active for a particular version of the API. At the code level the controller is selected by the name space of the particular version of the controller, e.g. Appname.Controllers.Version1. As mentioned in the last post, care must be taken to avoid unnecessary duplication in the controllers. Likewise the same duplication concerns apply for testing and relevant techniques will be reviewed in this post.

Versioning ASP.Net Web API

One of the important things to consider when building an API is a strategy for versioning the API to manage changes. There are several reasons this is important:

  • To support users (developers) of the API that are using an existing version so as not to force breaking changes on them.
  • To prevent breaking existing versions of the client applications that are using an existing version of the API.

Previous versions of the API will normally be maintained for either a period to allow developers and client applications to upgrade or indefinitely.