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