Verifying validity of Workflow Service in Unit Test


At work we’ve been having a little bit of trouble verifying that a Workflow Service still “works” after we change something. This is because our custom activities are in a separate assembly. When we change the activities and run MSBuild, we’ll notice that the unit tests still work and that the workflow still compiles. Only after we deploy the service and try to hit it, do we see errors that indicate that the workflow can not be instantiated, for instance because we removed a parameter from an activity. We need some kind of regression testing to prevent this.

To solve this, we now instantiate the workflow in a Unit Test as I will describe in this post.

Problem description

Suppose I have a very simple CodeActivity that takes two values and multiplies them:

public sealed class CodeActivity1 : CodeActivity
    public InArgument Input { get; set; }
    public InArgument Factor { get; set; }
    public OutArgument Result { get; set; }

    protected override void Execute(CodeActivityContext context)
        var input = Input.Get(context);
        var factor = Factor.Get(context);

        var result = input*factor;

        Result.Set(context, result);

I then have a Workflow Service which calls this activity with a value for Input that it gets from a service call, and a constant value of 3 for the Factor:

Continue reading

Upgrade a SharePoint 2010 solution with features using Power Shell

Having finished the first three SharePoint 2010 portals with our team, we have come across the inevitable need to change certain things in an already running website. Since we obviously cannot retract, uninstall, reinstall and redeploy our solutions (the data would be lost), we have started looking into the upgrade process in SharePoint 2010. After having gained a lot of knowledge from this blog post by Chris O’Brien, we were ready to deploy our upgrades.

In his blog, Chris describes his SharePoint Feature Upgrade Kit, which provides a very handy way to graphically upgrade features, as well as to do the same by using Power Shell. However, even using the Power Shell version of his tools requires installing a few things to the GAC, which we would prefer not to have to ask our maintenance team. So we have set out to make some simple Power Shell scripts of our own which we can just put in a .ps1 file to give to our administrators. As Chris notes, there are no built-in commands to upgrade features easily, so we have to do this the ‘hard’ way ;)

This script will upgrade one SharePoint solution and then upgrade all of the features (both site and web scoped) it contains on the given SPSite.
Continue reading

link_to_unless_current without request parameters

Not a really big thing, but I felt the need for a method like link_to_unless_current which ignores request parameters (you know, those things that come after the ‘?’ in the url). I couldn’t find it in the Rails api, so I wrote my own little snippet in a helper:

  # makes a link unless 'link' equals the current
  # page ignoring request parameters
  # e.g. this will not make a link:
  #   current page =
  #   link =
  # but this will:
  #   current page =
  #   link =
  def link_to_unless_current_ignore_parameters(title, link)
    link_to_unless(request.request_uri.gsub(/?.*/, '') == url_for(link), title, link)

If someone knows a better way, please let me know :) I thought about aliasing the original method and having an optional boolean parameter that defines whether to ignore the request parameters, but decided to go with this instead.

Coding font roundup

As a followup of the poll about “What coding font do you use?” on Rails Envy, here are the results and a PDF showing all the fonts for comparison:

  1. Monaco (37%)
  2. Bitstream Vera Sans Mono (20%)
  3. Consolas (14%)
  4. Deja Vu (5%)
  5. Inconsolata (4%)
  6. Liberation Mono (2%)
  7. Pro Font (2%)
  8. Courier New (1.5%)
  9. Lucida Console (1%)
  10. Monospace (1%)

Some old favourites in there, but they seem to be going out of style in favor of the new ones. Consolas is one of the new fonts that ships with Windows Vista (or was it Office 2007?), Bitstream Vera Sans Mono is the font Ryan Bates at Railscasts uses and (I think) Monaco is the default font in Textmate.

Check out the pdf here. I use Consolas ;)

Update: I’ve heard that some users can’t view all the fonts in the PDF, so here’s a PNG of all the pages put together.

First tutorial: Writing a blog in Rails 2.0.2

I’ve just finished my first tutorial, writing a blog in Rails 2.0.2. It’s of course inspired by the great 15 minute blog screencast by DHH, which convinced me to try Rails in the first place. This one is with some new Rails 2 conventions and explanations on why some things work.

Now, without further ado, go and read it:

How to write a blog in Rails 2.0.2 (not quite in 15 minutes)

Comments and criticisms are always welcome, it’s my first tutorial ;)

Conditional fragment caching

We were just wondering if it’s possible to provide a condition to fragment caching, in order to only cache certain fragments when no user is logged in to our site. This is to ensure anonymous users (the majority of visitors), who will see the same page anyway, will get it loaded from cache. People who log in will see their personalized site.

I was unable to find anything on Google about this, so I wrote my own helper. It looks so obvious that I’m probably not the first to write this, but I figured I’d share it anyway:

def cache_if (condition, name = {}, &block)
  if condition
    cache(name, &block)

Using this, you can write something like:

<% cache_if @current_user.blank?, 'navigation' do %>
  Navigation content here, including user specific navigation
<% end %>