Monday, December 31, 2012

My Top 5 Blog Posts from 2012

On this last day of 2012, I'd like to look back and share my top 5 most popular blog posts from this year.

5. On January 8, I introduced a CoffeeScript Assertion Library called ExpectThat. ExpectThat makes it easy to create expressive, self-documenting assertions in CoffeeScript with a syntax similar to that provided by FsUnit.

4. In September, an example of a Single Page Application with Backbone.js, ASP.NET Web API, and F# was provided. This was then added to the F# and C# ASP.NET MVC 4 project template.

3. At the end of January, an example was given for how to use ExpectThat with Mocha to test a jQuery plugin. This example builds on a nice post by Josh Bush entitled Testing jQuery plugins with Node.js and Jasmine and it includes examples for both browser and Node tests with Mocha and ExpectThat.

2. In March, I announced an addition to the F# and C# ASP.NET MVC 4 template that makes it easy to create modern HTTP services with ASP.NET Web API and F#.

1. And my most popular post from 2012 was an example of a Single Page Application with Knockout.js, ASP.NET Web API, and F# . This was later added as an option to the F# and C# ASP.NET MVC 4 project template.

Happy New Year!

Sunday, December 23, 2012

Buiilding Web, Cloud, and Mobile Solutions with F#

I'm happy to say that my book entitled Building Web, Cloud, and Mobile Solutions with F# is now available in both print and electronic formats. The description of the book is provided below and you can find the book examples on my GitHub.
Learn how to build key aspects of web, cloud, and mobile solutions by combining F# with various .NET and open source technologies. With helpful examples, this hands-on book shows you how to tackle concurrency, asynchrony, and other server-side challenges. You’ll quickly learn how to be productive with F#, whether you want to integrate the language into your existing web application or use it to create the next Twitter.
If you’re a mid- to senior-level .NET programmer, you’ll discover how this expressive functional-first language helps you write robust, maintainable, and reusable solutions that scale easily and target multiple devices.
  • Use F# with ASP.NET MVC, ASP.NET Web API, WCF, Windows Azure, HTML5, CSS3, jQuery Mobile, and other tools
  • Build next-generation ASP.NET MVC 4 web applications, using F# to do the heavy lifting on the server
  • Create WCF SOAP and HTTP web services
  • Develop F# web applications and services that run on Windows Azure
  • Build scalable solutions that allow reuse by mobile and web front-ends
  • Use F# with the WebSharper and Pit frameworks to build end-to-end web stacks

Monday, December 17, 2012

F# PowerPack NuGet Packages for F# 3.0, .NET 4.x, and Silverlight 5

There is a new version of each of the available F# PowerPack NuGet packages. These packages include the original F# PowerPack functionality recompiled for F# 3.0, .NET 4.x, and Silverlight 5 that were provided today on the F# PowerPack CodePlex site.

In order to use these updated NuGet packages in a .NET 4.x project, you will need to be using F# 3.0. If that is not an option for you, the previous version of each package can be installing using any of the following commands:

Install-Package FsPowerPack.Community.Sample -Version

Install-Package FsPowerPack.Community -Version

Install-Package FsPowerPack.Core.Community -Version

Install-Package FsPowerPack.Linq.Community -Version

Install-Package FsPowerPack.Metadata.Community -Version

Install-Package FsPowerPack.Parallel.Seq.Community -Version

Saturday, December 8, 2012

Using the New ASP.NET MVC 4 Template in MonoDevelop

In my last post, I showed an example of an ASP.NET MVC 4 application built in MonoDevelop. Since that time, an ASP.NET MVC 4 project template has been created for MonoDevelop that makes it very easy to create a similar app.

Here are the steps for using this template:

1. To get started, install version 3.0.2+ of Mono, the latest version of MonoDevelop, and the F# Language Binding (through the MonoDevelop Add-in Manager). If you've already installed each of these, make sure that the F# Language Binding version is 3.2.8+.

2. Create a new solution (File | New | Solution) and select F# | ASP.NET | F# ASP.NET MVC 4 (Razor) as shown here:
3. Add the desired solution name, click OK, and your done.

Well that was easy, but where do you go from here? Let's walk through a simple example of creating an app for keeping track of contacts. The end result will be similar to the screenshot shown in my post entitled A Single Page App with Backbone.js, ASP.NET Web API, and F#.

1. I've already followed the previous steps to create an ASP.NET MVC 4 application in MonoDevelop called MyContacts. To quickly add a decent look to the app, I'll use the responsive front-end framework from ZURB called Foundation. All that I really need is the CSS, so I add the foundation.min.css file to the Content folder in the project. I also add an app.css file for any custom styles that are needed. The content of the app.css file is shown below:

2. I can now reference these CSS files in _Layout.cshtml. The modified file looks like this:

3. Now I modify the Index.cshtml file in the Home folder so that it will display the list of contacts. The result is shown below:

4. Lastly we make a few modifications to the HomeController. Here's the code:

5. That's it. We can now launch the site and see the following:

Monday, November 19, 2012

F#, ASP.NET MVC, and MonoDevelop

I often talk about creating web solutions with F# in Visual Studio. Today I'm going to switch things up a little and provide an example of an ASP.NET MVC solution built with MonoDevelop.


For those that aren't familiar with MonoDevelop, it's an open source IDE that runs on a variety of operating systems including Windows, Mac OSX, and Linux. MonoDevelop works hand-in-hand with Mono, which is "an open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET". This means that you can write the same .NET code that you would in Visual Studio and run it on any of the most popular operating systems.

Getting Setup for F# Development:

There are a number of resources out there that talk about how to get your environment setup with MonoDevelop and F#. Here's a quick set of steps:

1. Install MonoDevelop, .NET or Mono, and GTK# from

2. Launch MonoDevelop and open the Add-in Manager (MonoDevelop | Add-in Manager... on Mac OSX and Tools | Add-in Manager on Windows).

3. Switch to the Gallery tab and install "F# Language Binding".

That's it. You're now ready to start building F# applications with MonoDevelop.

An ASP.NET MVC Project with F# and MonoDevelop:

MonoDevelop also supports ASP.NET MVC. To see an example, clone and open the solution.

The solution includes 2 projects:

1. A web project that includes Views and Controllers.
2. A unit testing project.

A screenshot of the Solution window is shown below:

Saturday, November 10, 2012

Recording for Building Better Web Apps with F#

Last week, I provided the slides and examples used for my talk entitled Building Better Web Apps with F#. If you missed the presentation, you can watch it here:

2012-10 Building Better Web Apps with FSharp from Ryan Riley on Vimeo.

Presentation - CoffeeScript: Good, Bold, and with Sugar

Thanks to all who came out to the Nashville .NET User Group last Thursday. If you weren't able to make it, you can view the presentation here:


Monday, November 5, 2012

Presentation: Building Better Web Apps with F#

Thanks to all who attended the Community for F# presentation last Tuesday (10/30/2012). Here are the slides from the talk:

The end result of the examples that were built during the presentation can be downloaded from here.

Monday, October 29, 2012

Using F# Records with ASP.NET Web API

In the Knockout.js and Backbone.js examples that I provided over the last few weeks, the model was written as a class using the traditional syntax. Here's an example:

While this approach works well, it would be great if we could use F# records instead. It turns out that with a few tweaks, this is easy to accomplish. Let's see how to do this in the Knockout.js example.  

First, we'll change the model to be an F# record. The new model looks like this:

We'll also need to change how the example data is initialized. This code now looks like this:

Lastly, a small change is needed in the ContactsViewModel. This now looks like the following:

Wednesday, October 17, 2012

Rough Cut of Building Web, Cloud, and Mobile Solutions with F#

Back in May I talked about two books that were currently underway. Today I'm proud to say that one of those books is now available as a Rough Cut on Safari Books Online.

I hope you enjoy reading it as much as I enjoyed writing it! A huge thanks goes to Ryan Riley for his continued expertise and guidance as the technical reviewer.

Monday, October 15, 2012

Knockout.js Added to the F#/C# MVC 4 Single Page Application Template

Two weeks I announced a new Single Page Application (SPA) template with Backbone.js in the F# C# MVC 4 Visual Studio extension. Last week an example of a SPA with Knockout.js was provided. I bet you can guess what's coming...

Today, you can get version 1.13 of the F# C# MVC 4 extension, which gives you the option to choose between Backbone.js and Knockout.js when creating a F#/C# SPA.

The new project creation screen looks like this:

If you would like to see additional JavaScript frameworks included as options, let me know.

You can find information on the Knockout.js version in this post and information on the Backbone.js version in this post. Note: A C# only version and a PHP version of the Backbone.js example is available at

Monday, October 8, 2012

A Single Page App with Knockout.js, ASP.NET Web API, and F#

A few weeks ago, I posted a simple example of a Single Page Application (SPA) built with Backbone.js, ASP.NET Web API, F#, C#, and more. Today, I'm posting a similar example, but built with Knockout.js. Let's look at some of the code.


Knockout.js supports binding of model data directly to DOM elements, so the first thing that we will look at is one of the templates that are used for the views. Here's what this example uses for the contacts list view template:

The main thing to notice in this markup is the use of the data-bind attributes to bind specific model data to the appropriate DOM elements.


The example defines a single ViewModel that is used for both of the available views. The code, which is fairly similar to that described at, is shown below:


Another thing to notice is the routing mechanism used in this example. Since Knockout.js doesn't provide built in URL routing, I've used Sammy.js to accommodate the need. Here's what the router looks like:


Lastly, we'll get a quick look at the API Controller that is written in F#. Here's the code:

That's pretty much it. You can find the full solution at

Sunday, September 30, 2012

Single Page Application Template Now Available

Version 1.12 of the F# C# MVC 4 Visual Studio extension now includes a Single Page Application (SPA) template with the Backbone.js JavaScript framework. The template works in VS2010 as well as VS2012 (including VS2012 Express for Web).

To use the new template, simply pull down the latest by following the direction from one of my previous posts or by clicking the download button on Visual Studio Gallery. Once you have installed the Visual Studio extension, you will see the following screen when creating a new F# and C# Web Application (ASP.NET MVC 4) from the Visual F# | ASPNET project template category.

Highlights of the F# and C# project structure are shown below:

If you wish to learn more about the solution that is generated from this new template, see my previous post.

Thursday, September 27, 2012

A Single Page App with Backbone.js, ASP.NET Web API, and F#

In this post, I introduce a simple example of a single page application built with Backbone.js, ASP.NET Web API, F#, and more. The example is an overly simple contacts app that allows you to view contacts and create new ones. It uses the Foundation 3 framework for styling and responsive design.

Here's a screenshot of the simple contact list view:

Solution Organization:

The C# project contains the following:

  • A single Index.cshtml file. 
  • All images, CSS, and JavaScript.
  • A "Templates" folder that contains 2 .htm files that hold the markup for each view. The templating feature of underscore.js is used to allow placeholders in the templates to be replaced with the desired data.

The heart of the client-side code is broken into 3 folders within the Scripts folder of the C# project:

  • The "app" folder contains a main.js, a utility.js, and a file containing route definitions using Backbone.Router.
  • The "models" folder contains the Backbone models and collections.
  • The "views" folder contains Backbone views.

The F# project contains the following:

  • ASP.NET MVC and Web API routes.
  • Definitions of JS and CSS bundles.
  • ASP.NET MVC and Web API Controllers.
  • A Model class.

Getting the Code:

You can find the full source at

EDIT: You can find a C# version at

Thursday, September 20, 2012

Adding NuGet Support to F# Interactive in VS2012

About a year ago, I posted an approach for adding basic NuGet support to VS2010. This post provides an updated script for adding this support in VS2012.

There may be times when you wish to use NuGet from the F# Interactive, such as when you are creating F# scripts. Since NuGet focuses on Visual Studio projects, this functionality is not supported out-of-the-box; however, it’s fairly simple to get things up and running.

The first step that we’ll need to do is create an F# script that is able to interact with the official NuGet package source. The script found here does the trick. I won’t spend too much time explaining the code in this script, but at a high level this allows you to use the F# Interactive window to talk to the NuGet package source, pull down packages, and automatically add a reference to the F# script file that has focus. 

The last step to accomplish our goal, is to tell F# Interactive to run our script each time that it launches. This is pretty easy to do thanks to the functionality provided by Visual Studio for adding F# Interactive options. To set the applicable option, go to Tools | Options | F# Tools | F# Interactive. You can then add the following information to the F# Interactive options setting.


 The F# Interactive options window looks like the following after making this change:

Once this is in place you can do something like this:

- Create a new F# Library project and build it. 
- Open the Script.fsx file.
- Navigate to the F# Interactive window.
- Execute InstallPackage “FSPowerPack.Core.Community”;; in the F# Interactive.

This will cause the package to be pulled down from the official NuGet repository and will automatically add the appropriate references to the Script.fsx file. 

Here's what the screen should look like after completing these steps.

Disclaimer: There are a few known issues with this approach.

Wednesday, September 12, 2012

F# Templates and F# Tools for VS2012 Express for Web

It's been a great day in the world of F# + web development. Today the F# team announced the F# Tools for Visual Studio 2012 Express for Web. This tool set now makes it easier than ever to create web applications that use F# for the server-side heavy lifting. Congrats to the F# team on this great accomplishment!

Currently, I've updated 4 of the more common F# web project templates to support this new version. These include:

F# C# MVC 4 - Which includes ASP.NET MVC 4 (Razor and ASPX) and ASP.NET Web API
- F# C# ASP.NET MVC 3 - Which includes ASP.NET MVC 3 (Razor and ASPX)
- F# and C# Web Services (ASP.NET, WSDL)
- F# MsTest Project

Happy coding!

Monday, July 9, 2012

A Few New NoSQL Helper Libraries

I've been working on a few new libraries lately that focus on providing functional wrappers around various NoSQL options.


FSharpCouch is something that I wrote about a little over two years ago. At the time, it was more of an educational exercise, but I have since revised it and found aspects of it to be useful. This is now available on NuGet as package ID FSharpCouch.

Here's an example:

You can find additional examples and the full source at


MongoFs currently has a primary focus on function composition as it relates to setting up the MongoDB client aspects of server, database, and collection. It simply wraps functions around the necessary methods of the C# Mongo Driver and auto opens the encompassing module.

Here's an example:

You can get it from NuGet as package ID MongoFs and find more examples and source at

Thursday, July 5, 2012

CoffeeScript Presentation Now Available on InfoQ

The presentation that I did at Code PaLOUsa entitled CoffeeScript: Good, Bold, and with Sugar is now available on InfoQ at

You can find an HTML version of the slides here and various examples on my GitHub.

Sunday, June 24, 2012

Functional JavaScript with LiveScript, Mocha, and ExpectThat

I've been playing with LiveScript a bit lately and have really been enjoying it! If you haven't heard of LiveScript, it's a "...fork of Coco, which is in turn derived from CoffeeScript..."  (LiveScript Overview Page). It provides more features than Coco and CoffeeScript including several that assist in writing code in a more functional style.

Here's a quick example of a test written in LiveScript for Mocha and ExpectThat:

This shows off a couple of the features that help you write in a functional style with LiveScript. The first is the use of pattern matching within the isWeekend function. The second is the use of the pipe-forward operator when calling the isWeekend function.

The pattern matching syntax gives you a concise way of defining a basic switch statement in JavaScript. The pipe-forward operator allows you to compose things together. In the example above, the string 'sun' (which also could have been written in LiveScript as \sun) is being passed into the isWeekend function. This becomes even more powerful when the value to be passed into the next function is coming from another function, as shown in this example:

F# has these same concepts and many more, which makes LiveScript + F# a compelling combination!

There are a number of additional LiveScript features that assist in using a functional style. For more examples of LiveScript with Mocha and ExpectThat visit To learn more about LiveScript, see a number of examples, and/or get setup for use, visit the LiveScript site at

Saturday, June 16, 2012

CodeStock 2012 F# and CoffeeScript Presentations

Thanks to all who attended my talks at CodeStock this year!

You can find the CoffeeScript slides here and the examples on my GitHub.

The examples from the F# talk can be found here and the slides are provided below:

Monday, June 4, 2012

F#/C# ASP.NET MVC 4 Template for Visual Studio 2012 RC

The F#/C# ASP.NET MVC 4 template has been updated to support ASP.NET MVC 4 RC and Visual Studio 2012 RC. You will need to install the release candidate of ASP.NET MVC 4 to use this updated version of the template. The install can be found at

As with the previous release, the F#/C# ASP.NET MVC project template supports ASPX and Razor versions of an empty ASP.NET MVC 4 project template as well as a Razor version of the ASP.NET Web API project template. The templates work on both VS2010 and VS2012 RC.

Wednesday, May 23, 2012

Fog Released

A new release of Fog is now available. The primary enhancement included in this release is support for Windows Azure Caching. Several bug fixes have also been included.

The caching functions are available in the Fog.Caching module. You can use them with code such as the following:
type TestRecord = 
    { [<DataMember>] mutable Id : Guid
      [<DataMember>] mutable Name : string }

let testRecord = { Id = Guid.NewGuid(); Name = "Dan" }

let key = testRecord.Id.ToString()  
Put key testRecord |> ignore

let result = Get<TestRecord> key

Fog is available via NuGet as ID Fog and the full source can be found on my GitHub.

Sunday, May 20, 2012

Two Books in the Making

A few weeks ago I mentioned that my blog has been suffering due to a few other ongoing activities. Today, I'm going to tell you about what I've been working on.

A few months ago I had the opportunity to start working on a few different books:

The first is called jQuery Mobile Cookbook. This book is a collaborative effort between appendTo, O'Reilly, and the jQuery community. The effort is coming along nicely and from what I've seen so far, you're going to love it!

The second is a book on building web, cloud, and mobile solutions with F#. I've partnered with O'Reilly to create this collection of examples, tips, guidance, architectural approaches, functional+OO patterns and practices, and more. Subjects that are expected to be covered include, but are certainly not limited to, ASP.NET MVC 4, ASP.NET Web API, other frameworks for building HTTP services, using F# to build Windows Azure web and worker roles, WebSharper, and Pit.

If there is something that you would really like to see in either of these books, let me know!

Sunday, May 13, 2012

Introducing Fog: A Library for Interacting with Azure from F#

Fog is a library that makes it easier to use F# to interact with Windows Azure through the Windows Azure SDK for .NET. It provides functions for many of the common activities related to table storage, blob storage, and queue storage as well as service bus queues and topics. Provided functions include both course and fined-grained approaches that remove boiler plate code and make it easier to use various functional patterns and techniques. The course grained functions currently use config settings with specific names to allow most operations to only require a single function call.

The syntax of Fog is pretty straight forward. The following examples use the course grained approach. To see how to use the fined-grained functions, which match almost one to one with the Azure SDK for .NET methods, see the Fog integration tests.

Blob Storage

With Fog all you have to do to interact with Azure blob storage is to add the connection string information in the config with a name of "BlobStorageConnectionString". Once that is done, you can use syntax like the following:
UploadBlob "testcontainer" "testblob" "This is a test" |> ignore 
DeleteBlob "testcontainer" "testblob"
UploadBlob "testcontainer" "testblob" testBytes |> ignore 
DownloadBlob<byte[]> "testcontainer" "testblob"
Table Storage

The simplest way to interact with Azure table storage is to add the connection string information in the config with a name of "TableStorageConnectionString". Once that is done, you can use syntax like the following:
[<DataServiceKey("PartitionKey", "RowKey")>] 
type TestClass() = 
    let mutable partitionKey = "" 
    let mutable rowKey = "" 
    let mutable name = "" 
    member x.PartitionKey with get() = partitionKey and set v = partitionKey <- v 
    member x.RowKey with get() = rowKey and set v = rowKey <- v 
    member x.Name with get() = name and set v = name <- v 

let originalClass = 
    TestClass(PartitionKey = "tprt", RowKey = Guid.NewGuid().ToString(), Name = "test") 
CreateEntity "testtable" originalClass |> ignore 

let newClass = originalClass 
newClass.Name <- "test2" 

UpdateEntity "testtable" newClass |> ignore 
DeleteEntity "testtable" newClass 
Queue Storage

For queue storage, add the connection string configuration value with setting name "QueueStorageConnectionString".
AddMessage "testqueue" "This is a test message" |> ignore 
let result = GetMessages "testqueue" 20 5 
for m in result do 
    DeleteMessage "testqueue" m 
Service Bus

There are a few service bus related config entries. Here's the list of expected names: ServiceBusIssuer, ServiceBusKey, ServiceBusScheme, ServiceBusNamespace, ServiceBusServicePath

To send a message do this:
type TestRecord = { Name : string } 
let testRecord = { Name = "test" } 

SendMessage "testQueue" testRecord 
To receive a message, pass the queue name, a function to handle successful message retrieval, and another function to handle errors.
HandleMessages "testQueue" 
    <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name
    <| fun ex m -> raise ex 
To use topics in a pub/sub type of scenario, use something like the following to subscribe:
Subscribe "topictest2" "AllTopics4" 
    <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name 
    <| fun ex m -> raise ex 
Message publishing can be accomplished like this:
Publish "topictest2" testRecord 
A few other handy functions include Unsubscribe and DeleteTopic:
Unsubscribe "topictest2" "AllTopics4" 
DeleteTopic "topictest2"
How to get it

The easiest way to get Fog is to install the Fog NuGet package. You can also find the full source as well as integration tests on the Fog GitHub site.

Monday, April 23, 2012

F#, MSTest, and FsUnit

I've been very busy with a few side projects that I plan to talk more about soon. Sadly, my blog has suffered due to these other activities, but I wanted to take a few minutes to talk about a new MSTest project template available on Visual Studio Gallery as well as some activity going on with FsUnit.

MSTest Project Template:

In the first week of March I released a new project template that helps in the creation of unit tests with MSTest and VS11. You can find it at or by searching for "fsharp mstest" in the Visual Studio Gallery online templates.


FsUnit has also had a few enhancements.

1. Support for MsTest has been added for VS11 and made available through a new NuGet package named Fs30Unit.MsTest.

2. A few new assertions have been added for NUnit including NaN, instanceOfType, and unique.

3. FsUnit has long supported a function named "not". While this is a nice feature, the fact that it overwrites an F# operator is not ideal. Because of this, version renames this function to not'. For the purpose of backward compatibility, you can open the module named FsUnitDepricated to make the "not" function available.

One last thing. If you're using FsUnit with NUnit, MbUnit, or xUnit in VS11 Beta, you will need to add binding redirects from previous versions of FSharp.Core to version The easiest way to do this is to use the Add-BindingRedirect PowerShell cmdlet provided by NuGet ( Here are the steps:

1. After installing one of the FsUnit NuGet packages, create an App.config file (if one doesn't already exist).

2. In the NuGet Package Manager Console, run the following command "Add-BindingRedirect projectname" after replacing projectname with the name of your test project.

Monday, March 26, 2012

A Nice Addition to the Empty WPF F# Template

A few days ago Steffen Formann announced a Xaml type provider that he and Johann Deneux have created that makes writing WPF apps in F# very easy. This type provider allows strongly typed access to the XAML, effectively providing the missing piece to allowing full F# WPF designer support. I've now updated the Empty WPF F# Template to include this type provider.

To use it, all you have to due is download/install the latest version of the F# Empty Windows App (WPF) template in VS11. This will generate an F# project with all the needed WPF assembly references. It also automatically installs the FSharpx.TypeProviders NuGet package and provides the starting point for creating WPF apps with the new Xaml type provider.

Here's a screenshot that's pretty similar to what Steffen showed in the announcement post. Note: The button and label were manually added after creating the project from the updated template.

One other piece that can be helpful when creating WPF apps in F# is the XAML related item templates (i.e. Page, User Control, Window, etc). Item templates are provided via the F# XAML Item Templates extension found at

Saturday, March 17, 2012

Presentation - CoffeeScript: Good, Bold, and with Sugar

Thanks to all who came out to my talk yesterday at Code PaLOUsa. As mentioned, the slides for the presentation are provided below. You can find the slides + examples at and navigate the deck at Slides

Monday, March 5, 2012

F# and ASP.NET Web API

A few weeks ago the ASP.NET team announced the release of ASP.NET MVC 4 Beta. You can read about it here. One of the exciting features that was announced is ASP.NET Web API. ASP.NET Web API provides an excellent programming model for building HTTP services.

One of the sweet spots for F# is in the services layer and this makes ASP.NET Web API + F# great friends. To make it easy to get started with F# and ASP.NET Web API, I've added an ASP.NET Web API template to the already existing F#/C# ASP.NET MVC 4 Visual Studio extension. Note: The template requires that ASP.NET MVC 4 Beta is installed.

To install the template, do the following:

1. Launch the project creation wizard (Ctrl+Shift+N), select Online in the left hand nav, search for "fsharp mvc4", and click OK. In VS11 Beta, it looks something like the following. Note: It may take a few seconds to download.

2. After clicking OK and installing the extension, you will see a dialog that allows the creation of a new ASP.NET Web API solution with an F# project that contains the server-side code.

3. Once the project has been created, you can run it however you desire and hit the service via http://localhost:###/api/values.

Monday, February 27, 2012

Razor Added to the F#/C# ASP.NET MVC 3 Internet Project Template

There's a new version of the F#/C# ASP.NET MVC 3 internet Project Template. This version allows you to choose between the ASPX and Razor view engines.

Here's how to use it:

1. Install version 1.6+ of the project template by searching for it on Visual Studio Gallery and/or updating a version that you had previously installed.

2. Create a new project.

3. You will now see a dialog box similar to what is shown below:

While it's certainly not required in order to use this template, you can see the full source on my GitHub.

Monday, February 20, 2012

ExpectThat with CoffeeScript, Zombie, Mocha, and Node

A few posts ago, I showed how to use ExpectThat with Mocha and Node.js. Today, I'll show a simple example of using ExpectThat with Zombie.js--a full-stack testing framework.


Zombie.js is a fast, headless testing framework that provides various functionality to write tests that hit your full technology stack. While I generally prefer to write more fine-grained, isolated tests, it's important to also have a few smoke tests and/or integration tests to verify end-to-end functionality. Zombie makes these kinds of tests easy, while allowing me to still use ExpectThat and Mocha.

The Example

Here's a simple example that populates two input elements and then verifies that the values of those input fields contain the expected text.

You can find the full example here.

After a few commands such as " coffee --output lib/ specs/ " and " mocha 'lib/example.spec.js' --reporter spec ", you should see an output that looks something like this:

To learn more about ExpectThat, visit

Monday, February 6, 2012

Another Way To Kick-start F# WPF Apps

Over the last few years I've announced a number of project templates that are available on Visual Studio Gallery. A few of these have provided ways to kick-start F# WPF apps. I talked about one of these templates here. While these are nice for getting acquainted with building WPF apps in F# and/or F#+C#, the files needed for the included sample app may become a bother once you have a few of these apps under your belt. Because of this, I've released an F# only Empty WPF project template (an F#/C# Empty WPF template will likely be coming soon).

To get the new template, do the following:

1. In Visual Studio 2010 or 11, navigate to File -> New and select Online Templates (or just Online if using VS11).

2. Search for "Daniel Mohl" or "F# Empty Windows App" as shown below:

3. Select the template, click OK, and agree to the install.

While it's certainly not required to use the template, you can find the full source on my GitHub.

Monday, January 30, 2012

Testing a jQuery Plugin with ExpectThat and Mocha

A couple of weeks ago, I announced a CoffeeScript/JavaScript assertion library called ExpectThat. In this post, I'll provide a more real-world example of how ExpectThat can be used. For this example, I'll be using the jQuery plugin and tests from one of Josh Bush's posts entitled "Testing jQuery Plugins with Node.js and Jasmine".

The jQuery plugin

The code that follows is a re-write (in CoffeeScript) of the simple jQuery plugin that Josh provided in his post.

This jQuery plugin provides a basic watermark type of feature for an input box.

The specs

Since Josh has already done the work of writing the specs for this jQuery plugin, all that I need to do is port this to CoffeeScript and add in ExpectThat. To mix things up a bit, I've chosen to use Mocha instead of Jasmine (though ExpectThat works just as well for Jasmine). For simplicity, I've combined the spec files from Josh's post.

Apples to apples 

Here's a quick before and after comparison (with both examples in CoffeeScript):

Before ExpectThat:
    describe "when calling placeholder plugin", ->
      it "should show placeholder value", ->
After ExpectThat:
    describe "when calling placeholder plugin", ->
      expectThat -> input.val().should equal "foo"
Josh's tests are already very readable, but by adding ExpectThat, I'm able to eliminate 1 line from every test and allow each to be self-documenting.

An example of the result of running the specs in the browser is shown below:

Wait, what about Node?

"So", you say, "this is great, but Josh's post was all about using the same code and specs from the browser in Node.js". Ah, yes, thanks for reminding me. It's pretty simple to run these same specs in Node.

Here are the steps:

1. Use NPM to install mocha at a global level (i.e. npm install mocha -g) then install jsdom, jquery, and expectThat.mocha at the local level (i.e. npm install <package name>).

2. Create a file called with the code shown below and compile it however you choose (i.e. "coffee --compile --output lib/ specs/").

3. Run the tests with a command such as "mocha 'lib/runspecs.js' --reporter spec" and you should see something like the following:
In future posts, I'll show how to do similar testing with other tools such as Jasmine-Node and Zombie.js. To learn more about ExpectThat, get involved, and/or keep an eye on its progress, go to

Monday, January 23, 2012

Making F# Windows Phone Development a Little Easier

About a month ago, I announced that most of the existing F# project templates on Visual Studio Gallery had been updated to include support for Visual Studio 11. In that post, I mentioned some new item templates that had been included in the update to the F# XAML Item Templates extension. This post provides a bit more information related to that update.

The F# XAML Item Templates extension was designed to make working with F# + WPF and Silverlight a little eaiser. I provided a brief overview of these features back in June. However, Windows Phone XAML related development was still lacking. The previous approach to adding XAML files was to either create a blank file, change the extension, and manually add the appropriate starting XAML or create the XAML from one of the C# item templates, remove the code-behind files, and tweak the resulting XAML. While neither of these options is extremely time consuming, it can quickly become annoying.

The latest update to this Visual Studio extension reduces this annoyance by providing F# Windows Phone 7 XAML item templates. Once this VSIX is installed, you can add a Windows Phone 7 XAML file by doing the following:

1. In a Windows Phone F# project, proceed with adding a new item as you normally would (i.e. Ctrl+Shift+A).

2. The resulting wizard (shown below) includes several new item templates starting with "F#..." that match the C# versions, but that do not generate C# code-behind files. 

While you still have to write the small amount of F# code to wire this up, it makes life a little bit easier.

Monday, January 16, 2012

developerFusion Article: An Introduction to FSharpx

My article entitled "An Introduction to FSharpx" was published a few days ago. You can find it at

As mentioned in the article, FSharpx is continually evolving and several new features have been added since I submitted this article. Be sure to head over to the FSharpx GitHub site to see what's new.

Sunday, January 8, 2012

Introducing ExpectThat: A CoffeeScript Assertion Library

I'm a big fan of automated testing. In fact, on the rare occasions that I don't write tests, I find that I can't shake the thought that something has been missed.

As with all aspects of my coding efforts, I am constantly looking for ways to improve the process, make tests more readable, and reduce room for error. With these goals in mind, I'd like to introduce ExpectThat.

What is ExpectThat?

ExpectThat is an expressive, self-documenting, assertion library for CoffeeScript, that seeks to improve testing efforts with your favorite testing framework. It does this by providing a syntax similar to FsUnit (a library for F#) that makes assertions more readable and then automatically translates that readable code into descriptive test output. This ensures that your test names always stay in sync with your tests and allows your code to speak for itself. ExpectThat currently supports Pavlov, QUnit, and Jasmine. Overtime, support for additional testing frameworks will be added.

Let's See it in Action

The following example shows how to write tests with ExpectThat for Pavlov in CoffeeScript:
pavlov.specify "Example Specifications", ->
    foo = "bar"
    describe "When testing 'should equal'", ->
        expectThat -> foo.should equal "bar"
    describe "When testing 'shouldnt equal'", ->
        expectThat -> foo.shouldnt equal "baz"
    describe "When testing for 'true'", ->
        expectThat -> (foo is "bar").should be true
        expectThat -> (foo is "baz").shouldnt be true
    describe "When testing for 'false'", ->
        expectThat -> (foo is "baz").should be false
        expectThat -> (foo is "bar").shouldnt be false
    describe "When testing 'greater than'", ->
        expectThat -> (9.1).should be greaterThan 9
        expectThat -> (9.1).shouldnt be greaterThan 10
        expectThat -> 10.shouldnt be greaterThan 10
Here's a screenshot of the result:
Other Testing Frameworks

As I mentioned, ExpectThat currently supports QUnit and Jasmine in addition to Pavlov. The following are examples for each of these.

module "Example QUnit Specifications"

foo = "bar"

module "When testing should equal"

expectThat -> foo.should equal "bar"

module "When testing shouldnt equal"

expectThat -> foo.shouldnt equal "baz"

module "When testing for true"

expectThat -> (foo is "bar").should be true
expectThat -> (foo is "baz").shouldnt be true

module "When testing for false"

expectThat -> (foo is "baz").should be false
expectThat -> (foo is "bar").shouldnt be false
describe "Example Jasmine Specifications", ->
    foo = "bar"
    describe "When testing should equal", ->
        expectThat -> foo.should equal "bar"
    describe "When testing shouldnt equal", ->
        expectThat -> foo.shouldnt equal "baz"
    describe "When testing for throw", ->
        expectThat -> (-> throw "test exception").should throwException
        expectThat -> (-> throw "test").should throwException "test"
    describe "When testing for less than", ->
        expectThat -> 10.should be lessThan 11
        expectThat -> (10.1).shouldnt be lessThan 10
Getting Started with ExpectThat

There are a couple of ways to get started with ExpectThat. First, head over to the ExpectThat GitHub site and browse through the documentation. You can then clone the repo and grab any of the examples from the example folder. If you are writing an ASP.NET app in Visual Studio, another option is to install one of the available NuGet packages.

Available Assertions

ExpectThat currently provides the following assertions:

- equal
- stictlyEqual
- false
- true
- greaterThan
- greaterThanOrEqual
- lessThan
- lessThanOrEqual
- throwException
- 'to' and 'be' can be used in most cases to make tests more readable.

In addition to the out-of-the-box assertions, ExpectThat allows for the creation of custom assertions. Examples of this for each of the supported testing frameworks are available in the example folder on GitHub.

ExpectThat in JavaScript

While the syntax of ExpectThat works best with CoffeeScript, you can certainly use it in JavaScript as well. Simply add in the missing braces, parens, semi-colons, function keywords, etc. The following provides a simple example for Pavlov:
pavlov.specify("expectThat Specifications", function() {
    describe("When testing should equal", function() {
        var foo = "bar";
        expectThat(function() {
        expectThat(function() {
            (foo + "test").should(equal("bartest"));
Getting Involved

There are a lot of things left to do for ExpectThat and I'd love to hear your thoughts on direction, enhancements, etc. as well as have any help that anyone would like to offer. If you want to get involved, fork me on GitHub.