Mon, Nov 25, 2013

Octopus XML Transformation in Services

We use Octopus Deploy at work and its a superb tool for deploying your applications whether they be websites or *.exes.

One of the great things it also provides is the ability to use Microsoft’s Transformation process for config files. However, when deploying a exe application its a bit trickier than a website. Unfortunately the documentation doesn’t mention the steps needed to get this working so read on!

Typically a web application will have web.config and a web.Release.config as well as other derivations you may use. Octopus also supports web.[Environment].config.

Thu, Nov 7, 2013

Using Git to update YouTrack via TeamCity

This post is mainly a reminder for me as I keep forgetting the command in Git to integrate commits to YouTrack items. YouTrack uses TeamCity to get the information about the commits and then scans the commit comment for a YouTrack item id and any commands that it can apply such as item status or time spent on said item. There is some documentation here but its not the greatest in terms of clarity and I’ve spoken to Hadi Hariri from JetBrains about improving this so hopefully they’re working on it.

Mon, Oct 21, 2013

Running Mocha tests within Sublime Text

I spend most of my day in Visual Studio with lots of the goodies an IDE can offer. One of them being able to run your tests from a keystroke.

In a bid to expand my mind I’m working on a little project that is made up of JS entirely so I’ve dug out Sublime Text. It has lots of plugins that are very handy, especially Sublime-HTMLPrettify which will tidy your HTML, CSS & JS for you.

When writing tests for JS there are many libraries you can use but I’ve chosen Mocha for now. The one thing I couldn’t work out was to run my tests within Sublime Text until now.

Build System

Sublime allows you to have build systems a bit like an IDE so you can tell it what to do when you invoke it via cmd+B.

To get Mocha to run we need to create a new build system. To do this click Tools - Build System - New Build System and paste in the below:

Tue, Oct 1, 2013

Blogging with Markdown & Deploying via Git - Introducing Sandra.Snow

There are many markdown blogging engines out there such as Calepin, Scriptogram and even WordPress allows you to write blog posts in Markdown but Sandra.Snow tries to add something different. Firstly, it is written in .Net and Nancy, secondly its a static blog generator and finally it supports Git deployment.

Even if you don’t want to use Git deployment you can use FTP, its a great tool. To write your blog post in Markdown you need a custom header in your file so it knows some information about your post.

layout: post
category: Azure
title: Setting up a ServiceStack Service

It then parses this information along with your Markdown into its engine, uses a Markdown view engine to convert the file content into HTML, assign model properties based on the header and creates a HTML file using the model via a Razor viewengine.

The “layout” refers to the Razor file it uses to render the final HTML file. This allows you to style your pages and blog posts whichever way you’d prefer. These “layout” files should exist in the “_layouts” folder for your site template. The site template is a set of files and folders that Sandra.Snow uses to produce the final static website.

The “category” or “categories” property, you can use both for singular or multiple comma-seperated values that refer to the category/categories of your blog post.

The “title” should hopefully be self explanatory!

You can optionally add an author and email properties to override the global config settings for example, if you wanted to allow guest author blog posts. There is also an optional metadescription property you can use for SEO.

Fri, Sep 20, 2013

Returning multiple fake objects with FakeItEasy

I was recently writing some unit tests where I needed to test that multiple calls to an interface returned different objects.

With FakeItEasy this is easy:

A.CallTo(() => myInterface.GetSomething(1)).Returns(new Something())

All very nice, but now if I have multiple calls to myInterface I have to execute the above statement ‘x’ amount of times:

public void Should_Do_Something()
  var myInterface = A.Fake<IApplication>();
  A.CallTo(() => myInterface.GetSomething(1)).Returns(new Something());
  A.CallTo(() => myInterface.GetSomething(2)).Returns(new Something());
  A.CallTo(() => myInterface.GetSomething(3)).Returns(new Something());
  var result = sut.DoSomething(myInterface);
  Assert.Equal("Super Duper", result);

Mon, Sep 16, 2013

Enabling CORS in IISExpress

I was playing around with swagger-ui and was trying to point it to a local endpoint that I started with IIS Express. I was getting an error saying that it needed the endpoint to accept Access-Control-Allow-Origin requests. I went Googling and it couldn’t find anything specific to IIS Express but managed to use some guidance for full blown IIS. The solution is to go to C:\Program Files (x86)\IIS Express\AppServer and open the applicationhost.

Thu, Sep 12, 2013

Keeping SQL Data Organised in Integration Tests

In my latest project I had kept my solution tidy with my main app project, my unit test project and integration test project. I tend to stick with a naming convention such as MainApp, MainApp.Tests.Unit & MainApp.Tests.Integration.

I had begun writing my integration tests for a repository that hits the database and returns data. Currently it was one method being called in the repository. xUnit allows you to setup any test dependencies in the constructor of your test class. It also allows you to do any tidying up in a Dispose method if you implement IDisposable although this is frowned upon. However I felt for my needs I would implement this.

I was creating data in the database in the constructor which will get called before the test runs, retrieving data in the test, asserting and then deleting all data and resetting the auto-incrementing from the tables in the Dispose method.

This was working perfectly until I wanted to test another method on my repository.

I now needed to add data for my new method but realised if I added different data to the database in the constructor, I would be creating unnecessary data unrelated to the test.

My options were to move the constructor logic into separate methods and then call the methods in the test or have separate test classes per method in the repo. Both were a not an ideal solution and quite frankly verbose, ugly and not best practice.