Missing the Stub (extension) method of result of MockRepository.GenerateStub<T>()

StackOverflow https://stackoverflow.com/questions/19885994

  •  30-07-2022
  •  | 
  •  

Question

I have been trying to resurrect an old .NET project that uses Rhino Mocks in its tests. I am referencing latest 3.6 version, but I seem to be missing a reference to extensions/helpers... or...?

I've added code similar to the following code - which comes from their "documentation" and is also referenced in numerous places. Problem is that "Stub" is not a method nor an extension method (won't compile with this message):

var stubUserRepository = MockRepository.GenerateStub<IUserRepository>();
var stubbedSmsSender = MockRepository.GenerateStub<ISmsSender>();

var theUser = new User{HashedPassword = "this is not hashed password"};    

// following Stub method does not exist.
stubUserRepository.Stub(x => x.GetUserByName("ayende")).Return(theUser);

From looking at the return result T of MockRepository.GenerateStub, Stub must an extension method. What am I missing?

Était-ce utile?

La solution

D'oh! I was fully qualifying other references to classes in Rhino.Mocks namespace - which ofcourse doesn't work well with the extension methods :-)

I was missing "using" statement.

using Rhino.Mocks // ... was missing
var foo = Rhino.Mocks.MockRepository.GenerateStub<IFoo>();

// following Stub method does not exist.
foo.Stub(x => x.bar())...

I hope this helps someone else.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top