Rhino Mocks: Anonymous method for Do Handler

I haven’t been doing a lot of unit tests lately – gasp! I’ve been doing a LOT of Javascript sorta stuff in the last year, which has been interesting for a change, but I’m really happy it’s over now.

I’m back to doing proper development, and I forgot how to use an anonymous method for a Do() handler!

Luckily I quickly stumbled on to this post by Igor Brejc: http://igorbrejc.net/development/c/rhinomocks-do-handler-using-anonymous-delegates.

I wanted to do something when a wrapper I developed for the WorkflowRuntime class adds the ExternalDataExchange service to the runtime, so I ended up with something like this in my test:

                Expect.Call(() => mockWorkflowRuntime.AddService(null))
                    .Constraints(Is.TypeOf(typeof (ExternalDataExchangeService)))
                    .Do((Action<ExternalDataExchangeService>)delegate(ExternalDataExchangeService service)
                                         //do my stuff here

~ by hendrikswan on November 26, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: