From a technical point of view i would dare to say that they will be able to support the same set of features because they’re both based on Castle’s DynamicProxy. Rhino Mocks has the advantages that it, unlike Moq, supports the mocking of Delegates and can be used in a .Net 2.0 only environment. Whether or not we should care about these differences is a question i will leave unanswered.
From a user point of view i find the Moq API a bit cleaner because
it frees me from thinking about the record-replay model and Rhino Mocks wants me to make assertions on a stub. Apart from that the differences are rather small given for the use-cases i presented in Getting started with Moq.
// Rhino var productDetailView = MockRepository.GenerateStub<iproductDetailView>();
// Moq var productDetailViewMock = new Mock<iproductDetailView>();
// Rhino Mocks productRepository .Stub(repository => repository.GetCategory(0)).IgnoreArguments() .Do((Delegates.Function<icategory, int>)(categoryId => return category;));
// Moq productRepositoryMock .Setup(repository => repository.GetCategory(It.IsAny<int>())) .Returns<int>(categoryId => return category.Object;});
csharp // Rhino Mocks // Nothing to do
// Moq // Nothing to do
// Rhino Mocks productDetailView.Raise(view => view.EditClick += null).Raise(sender, EventArgs.Empty);
// Moq productDetailViewMock.Raise(view => view.EditClick += null, sender, EventArgs.Empty);
// Rhino Mocks -- Odd that i'm asserting on a Stub. productRepository.AssertWasCalled( repository => repository.FindCategories( Arg<ispecification<icategory>>.Matches(Is.TypeOf(typeof(All<icategory>)))));
// Moq productRepositoryMock.Verify( repository => repository.FindCategories( It.Is<ispecification<icategory>>(specification => specification.GetType() == typeof(All<icategory>))));
// Rhino Mocks productDetailView.BackToRecord(); productDetailView .Stub(view => view.CategoryId) .Returns(2);
// Moq productDetailViewMock .Setup(view => view.CategoryId).Returns(2);
Editted code to take advantage of the new AAA syntax that comes with Rhino Mocks 3.5 If only someone could show me how i can override a Stubbed result…