Mocking method with Action parameter

后端 未结 2 608
陌清茗
陌清茗 2021-01-11 21:09

[unit testing newbie] [c#]

Consider the following scenario:

I\'m using Silverlight and calling a WCF service. Silverlight can only call WCF services

2条回答
  •  不要未来只要你来
    2021-01-11 21:35

    You could use an AutoResetEvent to handle async calls.

    Just initialize it as unset and configure your mock service to set it in the callback. (IE: var mockService = new Mock(); mockService.SetUp(x => x.MyMethod()).Returns(someStuff).Callback(() => handle.Set()); )

    After that I use hadle.WaitOne(1000) to check if it was called. (IMHO 1000 miliseconds are more than enough to run the async code).

    Sorry: This was supposed to go as a reply to the post above... I can't for the life of me figure out how to reply :)

提交回复
热议问题