I think the stub calls are a bit confusing, here is the code rewritten, and
passes
[TestFixture]
public class RhinoBugMaybe
{
[Test]
public void Bug()
{
// Arrange
IService service = MockRepository.GenerateStub<IService>();
var msg1 = new Message1();
var msg2 = new Message2(2);
service.Stub(x => x.Send(msg2)).Return(2);
service.Stub(x => x.Send(msg1)).Return(1);
// Act
var actual1 = service.Send(msg1);
var actual2 = service.Send(msg2);
// Assert
Assert.AreEqual(1, actual1);
Assert.AreEqual(2, actual2);
}
}
public class Message2 : MessageBase
{
public Message2(int value)
{
Value = value;
}
public int Value { get; set; }
}
public class Message1 : MessageBase
{
}
public interface IService
{
int Send(MessageBase msg);
}
public class MessageBase
{
}
On Fri, Mar 6, 2009 at 7:43 AM, Thejuan <[email protected]> wrote:
>
> Hopefully today is a more fruitful posting day. Can anyone see why
> this test fails?
>
> If i stub a method to return different values based on incoming
> parameters and then the calls happen in a different order to the
> stubbing order it fails. (inheritance is involved and i beleive the
> problem)
>
> Heres the test
>
> using System;
> using NUnit.Framework;
> using Rhino.Mocks;
>
> namespace RhinoBug
> {
> [TestFixture]
> public class RhinoBugMaybe
> {
> [Test]
> public void Bug()
> {
> IService service = MockRepository.GenerateStub<IService>
> ();
>
> service.Stub(x => x.Send(Arg<Message2>.Matches(msg =>
> msg.Value == 2))).Return(2);
> service.Stub(x => x.Send(Arg<Message1>.Is.TypeOf)).Return
> (1);
>
> Assert.AreEqual(1, service.Send(new Message1()));
> Assert.AreEqual(2, service.Send(new Message2(2)));
>
> }
>
> }
>
> public class Message2 : MessageBase
> {
> public Message2(int value)
> {
> Value = value;
> }
>
> public int Value { get; set; }
> }
>
> public class Message1 : MessageBase
> {
> }
>
> public interface IService
> {
> int Send(MessageBase msg);
> }
>
> public class MessageBase
> {
> }
> }
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---