Questions tagged [rhino-mocks]

Rhino.Mocks is a dynamic mock object framework for the .NET platform. Rhino.Mock's purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing.

Rhino.Mocks is a dynamic mock object framework for the .NET platform. Rhino.Mock's purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing.

To get started, take a look at the useful manual full of examples for .NET version 3.5. For more information, see the wiki for Rhino.Mocks or the documentation (source code in GitHub).

Installation RhinoMocks can most easily be installed through its NuGet package.

Install-Package RhinoMocks 
1223 questions
18
votes
5 answers

How can I use Rhino Mocks to inspect what values were passed to a method

I'm new to mocking, and I'm having a hard time solving an issue with UnitTesting. Say I have this code: public class myClass{ private IDoStuff _doer; public myClass(IDoStuff doer){ _doer = doer; } public void Go(SomeClass…
andy
  • 8,775
  • 13
  • 77
  • 122
18
votes
3 answers

How to use Rhino.Mocks AssertWasCalled() correctly?

I call _mocks.ReplayAll(), then one or more _mockedObject.AssertWasCalled() and then _mocks.VerifyAll(). But it tells me that "This action is invalid when the mock object is in record state". [Test] public void…
HiveHicks
  • 2,294
  • 5
  • 28
  • 42
17
votes
5 answers

Mocking a method that returns a sealed class in RhinoMocks

Running this code: _foo = MockRepository.GenerateStub(); _foo.Stub(x => x.Foo()).Return("sdf"); When public interface IBar { string Foo(); } public class Bar : IBar { public string Foo() { throw new NotImplementedException(); …
ripper234
  • 222,824
  • 274
  • 634
  • 905
17
votes
7 answers

How to Mock a Static Singleton?

I have number of classes I've been asked to add some unit tests to with Rhino Mocks and having some issues. First off, I know RhinoMocks doesn't allow for the mocking of Static members. I'm looking for what options I have (besides using…
JamesEggers
  • 12,885
  • 14
  • 59
  • 86
16
votes
5 answers

What is wrong with Stubs for unit testing?

I just watched this funny YouTube Video about unit testing (it's Hitler with fake subtitles chewing out his team for not doing good unit tests--skip it if you're humor impaired) where stubs get roundly criticized. But I don't understand what wrong…
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
16
votes
2 answers

What is the difference between rhino-mocks stub and expect

What is the difference between rhino-mocks stub and expect here: Looks to me that they behave exact the same? mockContext.Stub(x => x.Find()) .Return(new List() { new Blog() { Id = 1, Title = "Test" } …
Nikos
  • 7,295
  • 7
  • 52
  • 88
16
votes
3 answers

How to mock a method call that takes a dynamic object

Say I have the following: public interface ISession { T Get(dynamic filter); } } And I have the following code that I want to test: var user1 = session.Get(new {Name = "test 1"}); var user2 = session.Get(new {Name = "test…
Chi Chan
  • 11,890
  • 9
  • 34
  • 52
15
votes
2 answers

Rhino Mocks: Repeat.Once() not working?

Can anyone tell me why in the world the following test is not failing? [Test] public void uhh_what() { var a = MockRepository.GenerateMock(); a.Expect(x => x.Notify()).Repeat.Once(); a.Notify(); a.Notify(); …
George Mauer
  • 117,483
  • 131
  • 382
  • 612
15
votes
2 answers

Rhino Mocks - How to assert a mocked method was called n-times?

How can i assert that a method on a mocked object was called exactly called n-times? Here is the code snippet from a controller action, i like to test: for (int i = 0; i <= newMatchCommand.NumberOfMatchesToCreate; i++) { …
Michael Wallasch
  • 2,499
  • 2
  • 17
  • 17
15
votes
1 answer

What is Rhino Mocks Repeat?

What is Rhino Mocks Repeat ? Repeat.Any(); Repeat.Once(); What does it mean and how it works ?
Yoann. B
  • 11,075
  • 19
  • 69
  • 111
14
votes
1 answer

How to Mock Indexed Property with Rhino Mocks?

How can I Mock Indexed Property with Rhino Mocks ?
Yoann. B
  • 11,075
  • 19
  • 69
  • 111
14
votes
7 answers

What are the real-world pros and cons of each of the major mocking frameworks?

see also "What should I consider when choosing a mocking framework for .Net" I'm trying to decide on a mocking framework to use on a .NET project I've recently embarked on. I'd like to speed my research on the different frameworks. I've…
BenAlabaster
  • 39,070
  • 21
  • 110
  • 151
14
votes
2 answers

What does Rhino Mocks mean by "requires a return value or an exception to throw"?

When mocking a call to a WCF Service, I get the following error: Method 'ICustomerEntities.GetCustomerFromPhoneNumber("01234123123");' requires a return value or an exception to throw. I've googled this and searched on here - all I can find is I…
Chris
  • 2,471
  • 25
  • 36
13
votes
2 answers

Rhino Mocks: How to stub a generic method to catch an anonymous type?

We need to stub a generic method which will be called using an anonymous type as the type parameter. Consider: interface IProgressReporter { T Report(T progressUpdater); } // Unit test arrange: Func returnArg = (x => x); //…
Tor Haugen
  • 19,509
  • 9
  • 45
  • 63
13
votes
2 answers

How to use the AAA syntax to do an AssertWasCalled but ignore arguments

I'm using the new AAA syntax and wanted to know the syntax to do the below and have the mock ignore the arguments: mockAccount.AssertWasCalled(account => account.SetPassword("dsfdslkj")); I think the below is how I would do this with the record/…
Toran Billups
  • 27,111
  • 40
  • 155
  • 268