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

DotNed podcast: Matt Milner over REST, de ASP.NET Web API en meer

In deze podcast spreekt Maurice de Beijer met Matt Milner over zijn TechDays presentaties. Ze hebben het onder meer over REST service en waarom je die wil gebruiken ipv SOAP services. Daarnaast komt Windows Workflow Foundation aan bod en wat daar allemaal nieuw is. Verder spreken ze over Windows Azure en de Azure Service Bus. Links: TechDays presentaties: http://www.techdays.nl/SprekerDetail.aspx?cid=2229 Blog: http://mattmilner.com/blog/ Met dank aan onze sponsor RedGate.   Hij is hier te downloaden.   Enjoy!

Query composition with the ASP.NET Web API

Having the ASP.NET Web API as a REST service returning data is kind of nice but to be efficient on the wire we don’t want to return more data that required only to discard it in the client.   As we have seen in a previous post just returning a collection data was real easy.   As it turns out changing the service so the client can filter data is almost just as easy. In the previous example we returned an IEnumerable<Product>. All we need to do is change this to return an IQueryable<Product> instead of an IEnumerable<Product> and most … Continue reading Query composition with the ASP.NET Web API