Ayende Rahien recently released version 3.5 of Rhino Mocks, the popular .NET mocking framework. This version marks a major change in the API. A new Arrange, Act, Assert syntax, which utilizes Lamba Expressions and Extension Methods. These additions bring to Rhino Mocks many of the innovations of Moq, another .NET mocking framework gaining popularity. Rhino Mocks 3.5 Example:
[Test]
public void WhenUserForgetPasswordWillSendNotification_UsingExpect()
{
var userRepository = MockRepository.GenerateStub<IUserRepository>();
var notificationSender = MockRepository.GenerateMock<INotificationSender>();
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();
}
New features in version 3.5:
- Arrange, Act, Assert model
- Lambda and C# 3.0 extensions
- Inline constraints
- Support for mocking interface in C++ that mix native and managed types.
- Allow a mock object to return to record mode without losing its expectations
- CreateMock was deprecated in favor of StrictMock
- Better error handling in edge cases.
- Fixed an issue with mocking internal classes and interfaces
- New event raising syntax