10 月 23 - 25 日,QCon 上海站即将召开,现在购票,享9折优惠 了解详情
写点什么

Rhino Mocks 的 Lambda 版本

  • 2008-10-12
  • 本文字数:399 字

    阅读完需:约 1 分钟

Ayende Rahien 最近

发布了流行的Mock 框架“Rhino Mocks”的3.5 版本。这个版本在API 方面做了很大改变。除了原有的“Record-Replay”语法外,框架依托

Lambda 表达式

扩展方法引入了一个

新的“Arrange,Act,Assert”语法。Rhino Mocks 的此次增强给

Moq 带来了许多革新,后者是另一个较为流行的.NET Mock 框架。

Rhino Mocks 3.5 版本的例子:

[Test]

public void WhenUserForgetPasswordWillSendNotification_UsingExpect()

{

var userRepository = MockRepository.GenerateStub();

var notificationSender = MockRepository.GenerateMock();

userRepository.Stub(x => x.GetUserById(5)).Return(new User { Id = 5, Name = “ayende” });

notificationSender.Expect(x => x.Send(null)).Constraints(Text.StartsWith(“Changed”));

new LoginController(userRepository, notificationSender).ForgotMyPassword(5);

notificationSender.VerifyAllExpectations();

}

2008-10-12 22:281200
用户头像

发布了 157 篇内容, 共 60.8 次阅读, 收获喜欢 6 次。

关注

评论

发布
暂无评论
发现更多内容
Rhino Mocks的Lambda版本_.NET_Al Tenhundfeld_InfoQ精选文章