Using dependency injection with WebAPI in the RAW stack

In the previous blog post we added some unit tests that tested the WebAPI and also included the RavenDB storage behind it. As I explained the recommendation is not to use fakes or mocks but just to use the in memory variant of RavenDB during testing. However the WebAPI controller used a static RavenConfig.Store property to get to the RavenDB database. And that is the kind of hard coupling we would prefer not to have even if we don’t need to create a fake for our tests.   Adding Ninject to do our server side dependency injections There are many … Continue reading Using dependency injection with WebAPI in the RAW stack

Unit testing the WebAPI controller and RavenDB database in the RAW stack

In the previous post we added unit tests for the AngularJS code running on the client. And while these tests are important there is more to test. After all the client side code depends on a server side WebAPI controller and a RavenDB database. In this post we are going to add unit tests for those two.   To inject or not to inject dependencies Normally when one class depends on another it is best to use dependency injection to get one to use another. And the dependency is then based around interfaces so a dependency can be faked during … Continue reading Unit testing the WebAPI controller and RavenDB database in the RAW stack

Unit testing AngularJS HTTP requests in the RAW Stack

In the previous blog post we created some basic unit tests for the AngularJS movies controller. As I mentioned there was one set of tests missing and that was around the controller doing HTTP requests to the WebAPI backend. In a unit test typically don’t want to do those test for real. First of all we don’t want to take a dependency on some external state and equally important we don’t want the overhead of those requests. Fortunately AngularJS makes it easy to fake those requests and test the controller bits in isolation.   The $httpBackend service One of the … Continue reading Unit testing AngularJS HTTP requests in the RAW Stack

Unit testing the AngularJS code in the RAW Stack

In the previous post we refactored the JavaScript code for our AngularJS controller a bit to make it more testable. However we didn’t actually start writing any tests yet so lets create a few tests.   The AngularJS controller under test Just as a quick reminder the AngularJS controller in our previous code was as follows 1: (function () { 2: ‘use strict'; 3: var module = angular.module("myApp", []); 4:  5: module.controller("moviesCtrl", function ($scope, $http) { 6: $http.get("/api/movies").then(function (e) { 7: $scope.movies = e.data; 8: }); 9: 10: $scope.newMovie = { Title: "" }; 11: $scope.addMovie = function () { … Continue reading Unit testing the AngularJS code in the RAW Stack

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

To SPA or not to SPA

Index: Getting started with AngularJS Creating an AngularJS Controller The AngularJS $scope is not the MVC Model Using repeating elements in AngularJS Filtering the data in an AngularJS ngRepeat element Using the AngularJS FormController to control form submission Creating an AngularJS Directive Using the DOM in an AngularJS application To SPA or not to SPA   Creating Single Page Applications, usually abbreviated to SPA, is getting more and more popular these days. There are some popular applications like GMail or Outlook.com done this way and using frameworks like AngularJS or routing libraries like Director and Sammy it appears quite easy … Continue reading To SPA or not to SPA

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

DotNed Podcast: Peter Provost over unit testen

In deze podcast spreekt Hassan Fadili met Peter Provost over unit testen. Peter Provost is een senior program manager voor Microsoft Visual Studio waar hij aan de agile tools werkt. Tijdens Tech-Ed Europe was hij in Amsterdam voor diverse sessies over TDD en Agile development. Links: Blog: http://www.peterprovost.org/ Tech-Ed sessies: http://channel9.msdn.com/Events/TechEd/Europe/2012?s=peter%2Bprovost Team Test Blog: http://blogs.msdn.com/b/vstsqualitytools/ What’s new for MSTest Unit Tests in Visual Studio 11 Beta: http://blogs.msdn.com/b/visualstudioalm/archive/2012/03/13/what-s-new-for-mstest-unit-tests-in-visual-studio-11-beta.aspx Application Lifecycle Management resource center | SharePoint 2010 http://msdn.microsoft.com/en-us/sharepoint/dd552992.aspx Test Release Management Guidance: http://vsartestreleaseguide.codeplex.com/ Rangers Solutions by Version http://msdn.microsoft.com/en-us/vstudio/ee358787 Compare Visual Studio 2012 editions http://www.microsoft.com/visualstudio/11/en-us/products/compare Hassan’s Blog voor alle relevante VS ALM informatie: … Continue reading DotNed Podcast: Peter Provost over unit testen