InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Rhino Mocks - Lambda Edition

Posted by Al Tenhundfeld on Oct 07, 2008

Sections
Development
Topics
Unit Testing ,
.NET Framework ,
.NET
Tags
Mocks
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
.NET 3.5 enhancements? lol by Eugene Tolmachev Posted
Re: .NET 3.5 enhancements? lol by Al Tenhundfeld Posted
Re: .NET 3.5 enhancements? lol by Eugene Tolmachev Posted
Re: .NET 3.5 enhancements? lol by Al Tenhundfeld Posted
  1. Back to top

    .NET 3.5 enhancements? lol

    by Eugene Tolmachev

    All these features are *language* features of C# 3.0 (as correctly stated in the features quote, not .NET features, Al.

  2. Back to top

    Re: .NET 3.5 enhancements? lol

    by Al Tenhundfeld

    All these features are *language* features of C# 3.0 (as correctly stated in the features quote, not .NET features, Al.

    Hi Eugene,


    You are completely correct.


    However, you'll notice I explicitly said .NET 3.5 language enhancements. Yes, it would have been more explicit for me to say, "C# 3.0 and VB.NET 9.0 language features," but it is extremely common to use the phrase .NET 3.5 language enhancements as a shorthand for new features common to the two primary .NET languages.



    I purposefully did not refer to lambda expressions or extension methods as .NET features; that would be incorrect and stupid.


    Thanks for your comment. I agree that specificity in terminology is important.

  3. Back to top

    Re: .NET 3.5 enhancements? lol

    by Eugene Tolmachev

    There reason I felt it warranted a comment is exactly in the fact that most people are not aware that you can use C# 3.0 even if you target 2.0 .NET framework. The distinction is important, because one might, for example, dismiss 3.5 RhinoMocks thinking that they can't use it if they are locked into .NET 2.0.

  4. Back to top

    Re: .NET 3.5 enhancements? lol

    by Al Tenhundfeld

    ... most people are not aware that you can use C# 3.0 even if you target 2.0 .NET framework...one might, for example, dismiss 3.5 RhinoMocks thinking that they can't use it if they are locked into .NET 2.0.


    Ah, that's a great point. Thanks for clarifying.

Educational Content

Jesper Boeg on Priming Kanban

In this interview, Jesper Boeg, author of the new InfoQ book – Priming Kanban, discusses the keys to using Kanban effectively, and how to get started if you are currently using other approaches.

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.