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

How to Construct IdentityResult With Success == true

I have a class with Microsoft.AspNet.Identity.UserManager injected, and I want to expect the userManager.CreateAsync(user, password) method to return a Task where the IdentityResult.Succeeded = true. However, the only available constructors for…
jakejgordon
  • 4,008
  • 7
  • 36
  • 45
38
votes
3 answers

RhinoMocks - Stub a Method That Returns a Parameter

I am using RhinoMocks, I need to stub a method, and always have it return the third parameter, regardless of what is passed in: _service.Stub(x => x.Method(parm1, parm2, parm3)).Return(parm3); Obviously, it ain't that easy. I don't always know…
Martin
  • 11,031
  • 8
  • 50
  • 77
37
votes
1 answer

RhinoMocks - Not specifying all parameters in AssertWasCalled

I am using RhinoMocks. Now I want to assert that some function was called, but I only care about one of the arguments. Can I do a AssertWasCalled where I only specify one argument? In the following example I'd like the ignore what was sent to the…
stiank81
  • 25,418
  • 43
  • 131
  • 202
36
votes
1 answer

Rhino Mocks - Difference between GenerateStub & GenerateMock

Can any of the Rhino experts explain me by giving a suitable example of the difference between the above methods on the MockRepository class (Rhino Mocks framework). Where should one use Stub over Mock method or otherwise?
chugh97
  • 9,602
  • 25
  • 89
  • 136
35
votes
2 answers

Using Rhino Mocks to mock an out parameter, which is created within the method I am testing

Trying to mock the following method: bool IsLoginValid(LoginViewModel viewModel, out User user); Tried this initially: dependency() .Stub(serv => serv.IsLoginValid( …
ctrlplusb
  • 12,847
  • 6
  • 55
  • 57
34
votes
3 answers

Rhino Mocks - Stub .Expect vs .AssertWasCalled

OK, I know there has been a lot of confusion over the new AAA syntax in Rhino Mocks, but I have to be honest, from what I have seen so far, I like. It reads better, and saves on some keystrokes. Basically, I am testing a ListController which is…
Rob Cooper
  • 28,567
  • 26
  • 103
  • 142
28
votes
1 answer

Raising events from a mock/stub using Rhino Mocks

How can I raise an event from a mock/stub using Rhino Mocks? I've found some answers to this question on the web, but they all seem to use the Record/Replay-syntax, but I'm using the Arrange/Act/Assert syntax. Any suggestions? A little…
haagel
  • 2,646
  • 10
  • 36
  • 53
28
votes
7 answers

Asserting that a method is called exactly one time

I want to assert that a method is called exactly one time. I'm using RhinoMocks 3.5. Here's what I thought would work: [Test] public void just_once() { var key = "id_of_something"; var source =…
Christopher Bennage
  • 2,578
  • 2
  • 22
  • 32
28
votes
3 answers

Using RhinoMocks, how do you mock or stub a concrete class without an empty constructor?

Mocking a concrete class with Rhino Mocks seems to work pretty easy when you have an empty constructor on a class: public class MyClass{ public MyClass() {} } But if I add a constructor that takes parameters and remove the one that doesn't…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
28
votes
3 answers

Stubbing or Mocking ASP.NET Web API HttpClient

I am using the new Web API bits in a project, and I have found that I cannot use the normal HttpMessageRequest, as I need to add client certificates to the request. As a result, I am using the HttpClient (so I can use WebRequestHandler). This all…
Erick T
  • 7,009
  • 9
  • 50
  • 85
26
votes
4 answers

How to set the Expect call to check that a method is not called in Rhino Mocks

Using Rhino Mocks, how do I ensure that a method is not called while setting up the Expectations on the mock object. In my example, I am testing the Commit method and I need to ensure that the Rollback method is not called while doing the commit.…
Santhosh
  • 6,547
  • 15
  • 56
  • 63
26
votes
6 answers

Rhino mock vs Typemock vs JustMock vs

I need to choose mock framework to new project. What are the pros and cons for those frameworks? Any comparison table? I know that JustMock is i beta stage but it's look very good right now (very similar to TypeMock) Edit: I'v What about MS Mole?…
Adiel
  • 331
  • 1
  • 4
  • 10
26
votes
2 answers

Stubbing a read only property with Rhino Mocks

I have a class with a private set property that I want to stub out with rhino mocks. When I try to do this, though, it gives me a compile time error saying I can't set a read only property. I'm new to using Rhino Mocks so I must be missing…
JChristian
  • 4,042
  • 5
  • 29
  • 34
25
votes
3 answers

How can I replace an already declared stub call with a different stub call?

If I have a Rhino Mock object that has already has a stub call declared on it like this: mockEmploymentService.Stub(x => x.GetEmployment(999)).Return(employment); Is there anyway I can remove this call to replace it with something different…
Simon Keep
  • 9,886
  • 9
  • 63
  • 78
24
votes
3 answers

download link for latest Rhino mocks binaries (googling didn't help)

can someone share the link to download the latest version of Rhino mocks binaries (binaries only, I don't need source)? the link http://ayende.com/projects/rhino-mocks/downloads.aspx, doesn't seem to work anymore. it gets redirected to the blog. I…
RKP
  • 5,285
  • 22
  • 70
  • 111
1
2
3
81 82