Posts

Showing posts from June, 2014

Getting Your TFS Builds To Run Your Jasmine JavaScript Unit Tests

A month or so ago I was setting up an automated build and deployment using TFS 2013. I set my build up to run my unit tests, and to consider the build a failure if they didn't pass. If the build fails (either due to compilation failure or unit test failure), the deployment step shouldn't take place. The application in question uses Angular.js and I've written a good number of unit tests to test my Angular controllers, services, etc. For these tests, I used Jasmine (instead of Karma, which is the most often recommended test framework for Angular -- long story). In Visual Studio, I make use of the awesome Chutzpah extension to allow my Jasmine unit tests to be integrated into the Test Explorer right-click context menu just like my MSTest unit tests of .NET code. But how to get these to run as part of my automated build from TFS? It took a little digging, but thanks to an extremely helpful blog post and a little trial-and-error, I found the answer. Here's how: 1. Add

A Generic Method Using HttpClient to Make a Synchronous Get Request

A while back I wrote  a post  on how to make an HTTP Get request using the HttpWebRequest object in .NET, implemented in a Generic method. Last week I had two occasions during which to revisit this code, but using the HttpClient class introduced in .NET 4.5 instead. The code below is functionally similar to the code in my  earlier post , but uses HttpClient instead of HttpWebRequest. A few points of interest: The HttpClient. GetAsync() method  returns a Task that is executed asynchronously (hence the name), however, calling the  Result  property of that Task ensures that the asynchronous operation is complete before returning. By accessing it off of the GetAsync() return value as shown below, we are essentially blocking and changing the call into a synchronous one. The  EnsureSuccessStatusCode()  method of the HttpResponseMessage class will throw an exception of the response does not indicate success.          public  T ExecuteGet ( string  url)         {              if