开发者

Convert NMock2 test to Moq

开发者 https://www.devze.com 2023-01-26 18:04 出处:网络
I\'m new to unit testing and mocking. I have to convert unit tests in my current project with using Moq. Currently tests are using Nmock2. Can you help me with 开发者_高级运维converting this code (usi

I'm new to unit testing and mocking. I have to convert unit tests in my current project with using Moq. Currently tests are using Nmock2. Can you help me with 开发者_高级运维converting this code (using of CollectAction) with using Moq:

Action<IScanFolder> publish;
Mockery mocks = new Mockery();
this.mockChannel= mocks.NewMock<IChannel>();
...
CollectAction collect = new CollectAction(1);
Expect.Once.On(mockChannel).Method("Subscribe").
    With(p1, NMock2.Is.NotNull).
    Will(collect);

...

mocks.VerifyAllExpectationsHaveBeenMet();
publish = collect.Parameter as Action<ISomeInterface>;

Thanks in advance.


Callback is Moq's CollectAction:

Action<ISomeInterface> publish;    
mockChannel.Setup(c => c.Subscribe(p1, It.IsAny<TArg2>())).Callback((arg1, arg2) => publish = arg2)
0

精彩评论

暂无评论...
验证码 换一张
取 消