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
13
votes
5 answers

Stub one method of class and let other real methods use this stubbed one

I have a TimeMachine class which provides me current date/time values. The class looks like this: public class TimeMachine { public virtual DateTime GetCurrentDateTime(){ return DateTime.Now; }; public virtual DateTime GetCurrentDate(){…
Buthrakaur
  • 1,821
  • 3
  • 23
  • 35
12
votes
3 answers

Unittesting Url.Action (using Rhino Mocks?)

I'm trying to write a test for an UrlHelper extensionmethod that is used like this: Url.Action(x => x.TestAction()); However, I can't seem set it up correctly so that I can create a new UrlHelper and then assert that the returned…
Kristoffer Ahl
  • 1,661
  • 2
  • 18
  • 36
12
votes
3 answers

RhinoMocks: Correct way to mock property getter

I'm new to RhinoMocks, and trying to get a grasp on the syntax in addition to what is happening under the hood. I have a user object, we'll call it User, which has a property called IsAdministrator. The value for IsAdministrator is evaluated via…
steve_c
  • 6,235
  • 4
  • 32
  • 42
12
votes
3 answers

Out parameters with RhinoMocks

I'm obviously confused - this is a task I've accomplished with several other frameworks we're considering (NMock, Moq, FakeItEasy). I have a function call I'd like to stub. The function call has an out parameter (an object). The function call is…
Jason Buxton
  • 153
  • 1
  • 8
12
votes
5 answers

Mocking HttpSessionState in ASP.net for nunit testing

I've see n a lot of discussions surrounding HttpSessionState and asp.net MVC. I'm trying to write tests for an asp.net application and wondering if it's possible to mock the HttpSessionState and if so, how? I'm currently using Rhino Mocks and Nunit
Gilbert Liddell
  • 1,203
  • 4
  • 14
  • 21
12
votes
3 answers

Return different instances for each call using rhino mocks

I've got this code: Expect.Call(factory.CreateOrder()) .Return(new Order()) .Repeat.Times(4); When this is called four times, every time the same instance is returned. I want difference instances to be returned. I would like to be able to…
Allrameest
  • 4,364
  • 2
  • 34
  • 50
12
votes
2 answers

Rhino Mocks - AssertWasCalled: How to improve unclear diagnostic message when incorrect arguments

IMHO, Rhino Mocks produces an unclear diagnostic message when AssertWasCalled is used in order to verify that a method has been called with a specific argument. Example: interface ISomeInterface { void Write(string s); } [TestFixture] public…
Chris
  • 885
  • 8
  • 19
12
votes
3 answers

Mocking GetEnumerator() method of an IEnumerable types

The following test case fails in rhino mocks: [TestFixture] public class EnumeratorTest { [Test] public void Should_be_able_to_use_enumerator_more_than_once() { var numbers =…
programmer
  • 4,342
  • 4
  • 24
  • 21
12
votes
1 answer

Rhino Mock Stub Async Method

I have a ViewModel which, in the constructor, makes a call to an async void method to add to a collection public MyViewModel(ICommandHandler commandHandler) { _commandHandler = commandHandler; SetupCollection(); } private async void…
gleng
  • 6,185
  • 4
  • 21
  • 35
11
votes
2 answers

Can you explain difference between StrictMock and Partialmock?

As I am using RhinoMocks version 3.6 and as I am not using Record-Replay and as I do not call Verify methods for asserting on mocks; Can you explain what is the difference between very…
pencilCake
  • 51,323
  • 85
  • 226
  • 363
11
votes
2 answers

Simulating CancellationToken.IsCancellationRequested when unit testing

I would like to test a task that is supposed to run continuously until killed. Suppose the following method is being tested: public class Worker { public async Task Run(CancellationToken cancellationToken) { while…
Sergii Gryshkevych
  • 4,029
  • 1
  • 25
  • 42
11
votes
2 answers

Rhino Mocks - Verify Property Set when Property has no Get

If you have a property: public class Fred { public string UserName { set { userName=value; } } } how do you use Rhino Mocks to check that fred= new Fred(); fred.UserName="Jim"; is…
hayrob
11
votes
2 answers

Render a View during a Unit Test - ControllerContext.DisplayMode

I am working on an ASP.NET MVC 4 web application that generates large and complicated reports. I want to write Unit Tests that render a View in order to make sure the View doesn't blow up depending on the Model: [Test] public void ExampleTest(){ …
Philip Pittle
  • 11,821
  • 8
  • 59
  • 123
11
votes
4 answers

Rhino Mocks AAA Quick Start?

I've been looking around for some decent information on using Rhino Mocks 3.5+ with the AAA syntax. I find a lot of blogs that have a mix of things from the old and new which seem to make it more difficult to figure out how to use it. Would would be…
Bill Campbell
  • 2,413
  • 6
  • 27
  • 32
11
votes
2 answers

RhinoMocks - Fetching parameters of called functions

Using RhinoMocks - can I fetch the parameters of a called function? I mean; can I get some of the unknown parameters from the function call out? I have a mock, and I expect some function to be called on this. I know one of the parameters, but the…
stiank81
  • 25,418
  • 43
  • 131
  • 202