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
188
votes
10 answers

How to mock the Request on Controller in ASP.Net MVC?

I have a controller in C# using the ASP.Net MVC framework public class HomeController:Controller{ public ActionResult Index() { if (Request.IsAjaxRequest()) { //do some ajaxy stuff } return…
Nissan
  • 1,985
  • 2
  • 13
  • 11
149
votes
5 answers

What are the differences between mocks and stubs on Rhino Mocks?

I haven't play enough with this and usually use mocks, but I wonder what are the differences between this two and when to use one or the other on Rhino Mocks. Update: I also found the answer to my question in Ayende's words: The difference between…
Rismo
  • 6,487
  • 11
  • 37
  • 33
88
votes
7 answers

Best Practices of Test Driven Development Using C# and RhinoMocks

In order to help my team write testable code, I came up with this simple list of best practices for making our C# code base more testable. (Some of the points refer to limitations of Rhino Mocks, a mocking framework for C#, but the rules may apply…
Kevin Albrecht
  • 6,974
  • 7
  • 44
  • 56
70
votes
7 answers

Mocking Asp.net-mvc Controller Context

So the controller context depends on some asp.net internals. What are some ways to cleanly mock these up for unit tests? Seems like its very easy to clog up tests with tons of setup when I only need, for example, Request.HttpMethod to return…
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
68
votes
1 answer

Castle DynamicProxy - Failure when creating proxy involving a GTP used as a GTR

OK, now I'm really confused. I originally had this problem, which is, according to posters, an issue with the version of Castle.DynamicProxy that's ILMerged into the latest Rhino.Mocks library. It has, according to several authorities on the…
KeithS
  • 70,210
  • 21
  • 112
  • 164
63
votes
3 answers

How to clear previous expectations on an object?

I would like to set up a return value _stubRepository.Stub(Contains(null)).IgnoreArguments().Return(true); but then in a specific test, override that expectation to return false. Something like: _stubRepository.ClearExpectations(); //<- this…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
57
votes
1 answer

What is the difference between Version and 'Runtime Version' in .Net?

When I open the properties window of one of the referenced dlls in my project in Visual Studio I see a Version and also a runtime version . Actually it is Rhino.Mocks library I am checking. And I see Runtime Version : v2.0.50727 Version :…
pencilCake
  • 51,323
  • 85
  • 226
  • 363
53
votes
6 answers

Rhino Mocks AssertWasCalled (multiple times) on property getter using AAA

I have a mocked object that is passed as a constructor argument to another object. How can I test that a mocked object's property has been called? This is code I am using currently: INewContactAttributes newContact =…
Confused
  • 869
  • 1
  • 7
  • 16
53
votes
6 answers

Is it possible to create a mock object that implements multiple interfaces with EasyMock?

Is it possible to create a mock object that implements several interfaces with EasyMock? For example, interface Foo and interface Closeable? In Rhino Mocks you can provide multiple interfaces when creating a mock object, but EasyMock's createMock()…
Daniel Fortunov
  • 43,309
  • 26
  • 81
  • 106
51
votes
1 answer

How to Mock a Task<> Result?

I'm setting up some unit tests and using Rhino Mocks to populate the object being tested. One of the things being mocked is a Task, since the logic being tested includes a call to an HttpClient to get an async response. So I've…
David
  • 208,112
  • 36
  • 198
  • 279
46
votes
6 answers

Mocking Static methods using Rhino.Mocks

Is it possible to mock a static method using Rhino.Mocks? If Rhino does not support this, is there a pattern or something which would let me accomplish the same?
abhilash
  • 5,605
  • 3
  • 36
  • 59
44
votes
5 answers

What are the capabilities of Moq and Rhino.mocks?

I cannot find a specific feature-by-feature comparison of Moq and Rhino. All the questions are "which do you like better and why", or "here's how you do a simple mock in rhino and how it's done in moq". I cannot find a deep comparison anywhere. …
womp
  • 115,835
  • 26
  • 236
  • 269
43
votes
2 answers

Rhino Mocks receive argument, modify it and return?

I'm trying to write something like this: myStub.Stub(_ => _.Create(Arg.It.Anything)).Callback(i => { i.Id = 100; return i; }); I want to get actual object that passed to mock, modify it and return back. Is this scenario possible with Rhino…
Alexander Beletsky
  • 19,453
  • 9
  • 63
  • 86
41
votes
4 answers

How do I mock IQueryable

I am creating a repository that exposes IQueryable. What is the best way to mock this out for my unit testing? Since I am using RhinoMocks for the rest of my mock objects, I tried to do the following: IQueryable QueryObject = …
Aaron Weiker
  • 2,523
  • 2
  • 21
  • 22
40
votes
8 answers

Is there an in-memory provider for Entity Framework?

I am unit testing code written against the ADO .NET Entity Framework. I would like to populate an in-memory database with rows, and make sure that my code retrieves them properly. I can mock the Entity Framework using Rhino Mocks, but that would not…
Michael L Perry
  • 7,327
  • 3
  • 35
  • 34
1
2 3
81 82