Thu, Nov 29, 2012

ASP.NET Web API Testing

As the need arose to implement some kind of Web Service/HTTP API I thought I would evaluate NancyFX, ASP.NET Web API and ServiceStack.

Suffice to say all performed as expected and I was actually surprised to find that implementing ASP.NET Web API was easier than ServiceStack (I know that might be a bit of a statement to make to the ServiceStack followers, sorry). I found Nancy easiest to implement. The very simple API demos can be found on my Github page.

When it came to testing ASP.NET Web API I found it to be wanting slightly in comparison to Nancy. With WebAPI I could make direct calls to the controller methods to make sure data was returned correctly and I could mock a repository and test that the methods in the repository were being called but there was nothing I could see to test the HTTP response I would get.

Fri, Nov 23, 2012

The For Loop is the devil in disguise

I recently spoke to someone about the ‘for’ loop who opened my eyes to how unstructured the ‘for’ loop is.

I have only ever used it in the traditional sense of:

for(int i = 0; i < 10; i++)
{

}

I looked into some more and thought I’d show anybody else who may not have known about this innocent little thing in the C# language. It may exist in other languages but I am explicitly talking about C#.

for (; ; )
{
  Console.WriteLine("Hi");
}

For some reason this compiles and executes! Who knew? Smarter people than me obviously. What do you expect it to output?

The answer is it outputs “Hi” forever as there is nothing to determine when the loop should end however there is nothing to determine when it should start either.

Sun, Nov 18, 2012

.gitignore not working – fixed!

This happens to me too often and I always end up googling the answer so this post is probably more of a location I know I can come to find the answer, although by writing it down hopefully it may sink in that I should stop getting too excited on a new project.

New project scenario

You’re all very excited about your new project and you think its about time you committed this to source control. Obviously you’re using Git so you initialise a new repository and commit your files. You then setup a remote repository at Github and it asks you whether you want it create a .gitignore file – you do. So now you have a repository remotely and locally. Easiest thing to do is pull from the remote, setup your remote and push to it. The other scenario might be you’ve committed locally and then realise you need to add a .gitignore file which you do and then commit.

Tue, Nov 6, 2012

Publishing to Windows Azure from Github

Back in July 2012 Microsoft announced improvements to Azure Web Sites. One of those improvements was to Git publishing so when you pushed changes to your Github repository Azure would automatically pick that up and deploy the project. I even mentioned it in my DinnerParty blog post but have only just looked at implementing it.

Preparation

As I said in my previous post Azure supported Git publishing but it was a two step process. You push to Github and then push to Azure and it gets deployed. If you already have Git setup on your Azure account there is nowhere in the dashboard that allows to you setup Github integration. I thought I was going to have reset my deployment credentials and set it all up again when I asked the question on Jabbr. Luckily David Fowler was online. Why is that lucky? He wrote the Github integration feature of Azure.

To setup your Azure account to enable Github integration you have to FTP into your Azure account and delete the deployment history by deleting all contents in the /site/deployments folder.

Deployment History

Deployment History

Thu, Oct 25, 2012

Simple .Net Twitter,Google,Facebook Authentication

Logging into websites is no longer a matter of typing in your username and password and clicking the login button. If you already have an account with the main social networks you can log into a site using your credentials from that website saving you having to register your details again. This obviously makes things a bit easier as you don’t have to remember another password. (Although you should all be using a password manager such as LastPass.)

Current Social Login Providers

There are currently providers out there that allow you to use their services to integrate into your website to provide authentication via the social networks. The main two that I know of are Janrain and DotNetOpenAuth. I’ve not worked with DotNetOpenAuth but I have with Janrain when building DinnerParty.

The process was reasonably easy but not as simple as it could be.

Thu, Oct 25, 2012

Testing your application’s email logic

If you’ve ever written an application that sends out email you may have written the code and executed it numerous times to check that the logic works and that the email appears as you hope. This obviously means you have to hit your SMTP server each time, open your email client and check your emails each time.

Papercut

Reading through my Twitter timeline I saw @TheCodeJunkie asking about the app that you can use to test sending emails from your application.

TheCodeJunkie Tweet

Intrigued, I kept an eye on my timeline and found that the application in question was Papercut

Mon, Oct 8, 2012

Node.js, Express, Hello World Formula 1 Style

In my ongoing efforts to be a better developer (plus I just like tinkering) I thought I would take a look at node.js.

I did play with node.js about a year ago where I setup a TCP listener to listen to a TCP Server on the network broadcasting XML messages, I then took these, formatted them to JSON and passed it to a browser using Socket.IO. It was pretty cool but the project never came to anything.

However, I thought I would re-visit and setup a proper development environment on my Mac at home.

Editors

There are many editors/IDE’s that you can use for node.js development such as Vim, Eclipse, WebStorm, Aptana Studio, Emacs and Cloud9 IDE. As I have used Sublime Text 2 (ST2) before I thought I would use this because I like it and all the cool kids use it!!

Coming from a mainly IDE based background I started to find things a bit hard going however ST2 allows plugins to be used to make the user experience a lot nicer. Below are a list of plugins I have installed:

Menu