Unit testing a ASP.NET WebAPI 2 controller

Earlier this year I wrote a blog post about how to unit test ASP.NET WebAPI controllers. It turned out that in order to do a good job of testing the public ApiController methods you would need to quite a bit of setup. Most of the time this was just about providing a HttpConfiguration object but sometimes, like in the case of responding to a post request, quite a bit more would be required. One of the goals of the ASP.NET WebAPI 2 was to make testing of controllers easier. This has been achieved by adding a new response interface named … Continue reading Unit testing a ASP.NET WebAPI 2 controller

Displaying local times using the HTML5 <time> element and Moment.js

One common problem with displaying local dates an times in a browser is that you get no information about the current time zone a browser is in. The browser will tell you the preferred language through the Accept-Language HTTP header but there is no such header for the users time zone. This means that it is easy enough to display a DateTime in the servers time zone but not in the users time zone. Now if your server is in the same time zone as your users this isn’t much of an issue.. However that is quite often not the … Continue reading Displaying local times using the HTML5 <time> element and Moment.js

On versioning WebAPI REST services

When you develop REST services you are going to run into the little matter of versioning, there is just no way to avoid it if you want to make any change to your REST service. Now there are lots of different ways to go about this and these different ways have their pro’s and con’s. What your version strategy is also depends on if your REST services are read-only or read-write with read-only services being somewhat simpler due to their smaller API surface. In these examples I am using the ASP.NET WebAPI but these same principles apply to REST services … Continue reading On versioning WebAPI REST services

Integrating the #WebAPI HttpClient and ApiController in a single test

In the two previous blog posts I showed how to unit test and ASP.NET WebAPI controller and how to unit test the client side code depending on the HttpClient class. Both unit tests are perfectly valid but as so often just adding unit tests can be deceptive. After all testing an ApiController by just calling the methods makes it perfectly possible to call them in such a way that would never be possible using a real HTTP request. So in order to complete out testing we should test the integration of the client and server parts using an integration test. … Continue reading Integrating the #WebAPI HttpClient and ApiController in a single test

Unit testing code depending on the ASP.NET WebApi HttpClient

In a previous post I showed how to unit test an ASP.NET WebAPI Controller. But with a REST service there is both a client and a service component. Assuming for a moment the client part is also written in C# we should test that as well. In this case the client application contains the following class to load books from the REST WebAPI controller: 1: public class BooksClient 2: { 3: private readonly HttpClient _httpClient; 4:  5: public BooksClient(HttpClient httpClient) 6: { 7: _httpClient = httpClient; 8: BaseUrl = new Uri("http://localhost:63895/api/books/"); 9: } 10:  11: public Uri BaseUrl { get; … Continue reading Unit testing code depending on the ASP.NET WebApi HttpClient

Unit testing a ASP.NET WebAPI controller

  Update: If you are using the ASP.NET WebAPI 2 see the new post here.   One of he goals of the ASP.NET WebAPI is to make REST style API controllers more testable than more traditional WCF services where in the past. For the most part that is true but there are cases where an ApiController depends on the actual incoming request and its data and things can become a bit more difficult. Testing a simple ApiController that gets data Suppose we have the following ASP.NET WebAPI Controller with two Get methods, the first returns the complete list of books … Continue reading Unit testing a ASP.NET WebAPI controller

Enabling Tincr on Windows 8

Some time ago I posted a blog post on Tincr and live reloading of CSS/JavaScript in Google Chrome. This works really well with one exception, on Windows 8 it will not install. When you try Chrome shows the following error message: This application is not supported on this computer. Installation has been disabled. The Chromium team has acknowledged this as a bug but it still needs to be fixed.   The interim solution Fortunately Lauricio Su came up with a nice workaround and posted it in the Tincr discussion group. Basically his solution is to run Chrome in Windows 7 … Continue reading Enabling Tincr on Windows 8

Tincr and live reloading of CSS/JavaScript in Google Chrome

The standard workflow with web development is run the web application, make some changes to your CSS in Visual Studio, flip back to the browser and reload the page to see the effect. While this works relatively well it can be somewhat slow at times.   One improvement is make changes to your CSS in the browser. I use Google Chrome as my main browser and it’s CSS and JavaScript viewer is actually an editor so you can make changes there. The nice thing is you see the effect of your changes immediately making for a much faster feedback loop. … Continue reading Tincr and live reloading of CSS/JavaScript in Google Chrome