Convert this delegate to an anonymous method or lambda

后端 未结 4 961
忘掉有多难
忘掉有多难 2020-12-28 16:01

I am new to all the anonymous features and need some help. I have gotten the following to work:

public void FakeSaveWithMessage(Transaction t)
{
    t.Messa         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 16:48

    Try something like:

    Expect.Call(delegate { _dao.Save(t); }).Do(new EventHandler(delegate(Transaction t2) { t2.CheckInInfo.CheckInMessage = "I drink goats blood"; }));
    

    Note the added EventHandler around the delegate.

    EDIT: might not work since the function signatures of EventHandler and the delegate are not the same... The solution you added to the bottom of your question may be the only way.

    Alternately, you could create a generic delegate type:

    public delegate void UnitTestingDelegate(T thing);
    

    So that the delegate is not Transaction specific.

提交回复
热议问题