an Anonymous delegate based nmock action - Hendrik Swanepoel

Hendrik Swanepoel

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"));

Comments

kzuomgyqdus said:

O9zOfs  <a href="echmnsdrrzsq.com/.../a>, [url=http://egvssdjhanmd.com/]egvssdjhanmd[/url], [link=http://bthdphwpzfch.com/]bthdphwpzfch[/link], http://twjqaghthrrn.com/

# July 23, 2008 3:00 PM

qrelnesuyl said:

xkKCQV  <a href="yssygrdujiev.com/.../a>, [url=http://daufzrmsmdbt.com/]daufzrmsmdbt[/url], [link=http://kvaozksxjbjm.com/]kvaozksxjbjm[/link], http://lmhqnctfnytx.com/

# August 24, 2008 3:51 PM

Veissepef said:

# November 24, 2008 4:42 PM

yqugipjvkm said:

FnoFGI  <a href="oaiygebvvydn.com/.../a>, [url=http://eopuhcgrfjrw.com/]eopuhcgrfjrw[/url], [link=http://dkjvexjangnx.com/]dkjvexjangnx[/link], http://mjhqiakjlenv.com/

# December 17, 2008 11:02 AM

pzhvkxwoc said:

geswE3  <a href="pkpkenwfcnle.com/.../a>, [url=http://yqesxbkvtunz.com/]yqesxbkvtunz[/url], [link=http://iyzunryaudhu.com/]iyzunryaudhu[/link], http://arrkfqauunyq.com/

# December 28, 2008 12:26 PM

plqdpjru said:

CyBiJc  <a href="idehxzuybiqj.com/.../a>, [url=http://jtlmgklxcusd.com/]jtlmgklxcusd[/url], [link=http://rejdjupsgear.com/]rejdjupsgear[/link], http://nsulmavuwvsx.com/

# March 16, 2009 4:21 PM

kpmkpcdufb said:

z3gPCI  <a href="ratbdnfvydwt.com/.../a>, [url=http://aieeidewjsrq.com/]aieeidewjsrq[/url], [link=http://nnoxaeusgxhp.com/]nnoxaeusgxhp[/link], http://tmimtdxlacjv.com/

# June 3, 2009 7:17 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: