将 NMock2 测试转换为 Moq
我是单元测试和模拟的新手。我必须使用 Moq 转换当前项目中的单元测试。目前测试使用Nmock2。您能帮我使用 Moq 转换此代码(使用 CollectAction)吗:
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>;
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回调是Moq的CollectAction:
Callback is Moq's CollectAction: