Hendrik Swanepoel

September 2007 - Posts

an Anonymous delegate based nmock action

I always find it tiring writing IAction implementations for nmock2 tests, so I wrote the following thingy, which basically allows you to specify anonymous delegates for an action.

public delegate void ActionPerformer(Invocation invocation);

public class DelegateAction : IAction
{
  private readonly ActionPerformer _actionPerformer;
  private readonly string _actionDescription;
  public DelegateAction(ActionPerformer actionPerformer, string actionDescription)
  {
    _actionPerformer = actionPerformer;
    _actionDescription = actionDescription;
  }

  public void Invoke(Invocation invocation)
  {
    _actionPerformer(invocation);
  }
  public void DescribeTo(TextWriter writer)
  {
    writer.Write(_actionDescription);
  }
}

You use it as such:

 

Expect.Once.On(_scheduler).Method("GetNext").WithNoArguments().Will(new DelegateAction(delegate(Invocation   invocation)
{
//whatever you want to do - even asserts
invocation.Result = whateveryou want to return, even variables before this statement;
},
"Whatvever you are performing with the action"));

Blogging again

Wow, I'm amazed that my blog hasn't been removed from the site.

I'd like to get started again, because it seems that I might be going to some interesting conferences in the near future, including tech-ed europe 2007 in Barcelona.

At the moment I'm working for a software consultancy company in London using netfx3 technologies like WCF and WF using agile methodologies. The project is due for a next phase and I'd like to introduce a federated security implementation as well as rethinking the stuff we exposed as services.

I'll try and post some WCF related stuff as I stumble across it.

<shamelessRecruiting>The company I'm working for is always looking for talented .Net devs, and they are willing to sponsor ZA candidates for a work permit as well as assist with relocation. So if you are interested in coming to the U.K, send your CV to hendrik@novarank.com </shamelessRecruiting>