There seems to be a bug in the code below however I am not sure what the
"appropriate" behavior should be. (I came across this about a month ago
digging into a problem on this board). I am willing to attempt a fix if
there is one needed and I know what the proper behavior should be. The code
is very simple and provided below.
I'm testing what the difference between Stub and Expect calls are on mocks
and what happens when you call. The output for the code below returns
(you'll notice a "hole) where "mockFoo called" should be printed:
mockFoo called
>
> mockFoo2 called
> mockFoo2 called
> mockFoo2 called
> mockFoo2 called
*At this point I'm not sure what the "correct" behavior should be. Should
Expect(<method) only set up a single-use return? Is there a bug here?*
[Test]
public void HowManyTimesCanAFakeBeCalledAndReturnTheSameValue()
{
// The interesting thing here is that the first mock (mockFoo) does is
only good for one call.
// Something about the Arg<string>.Is.Anything causes the return value
to be good for only one call
// this seems to be a bug when compared to other implementations (Stub
allows multiple calls on the object
// while returning the same value)
var mockFoo = MockRepository.GenerateMock<IFoo>();
var mockFoo2 = MockRepository.GenerateMock<IFoo>();
var mockFoo3 = MockRepository.GenerateMock<IFoo>();
mockFoo.Expect(x => x.Method(Arg<string>.Is.Anything)).Return("mockFoo
called");
mockFoo2.Expect(x => x.Method(null)).IgnoreArguments().Return("mockFoo2
called");
mockFoo3.Expect(x => x.Method(Arg<string>.Is.Anything)).Return("mockFoo3
called").Repeat.Any();
Debug.WriteLine(mockFoo.Method("hello"));
Debug.WriteLine(mockFoo.Method("hello"));
Debug.WriteLine(mockFoo2.Method("hello"));
Debug.WriteLine(mockFoo2.Method("hello"));
Debug.WriteLine(mockFoo2.Method("hello"));
Debug.WriteLine(mockFoo2.Method("hello"));
}
public interface IFoo
{
string Method(string arg);
}
--
Tim Barcz
ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---