It's not my test. It's a guy at work. I just isloated it.
Below is a method to be tested and it's test.
The problem seems to be when using matches for args into a polymorphic
method. Rhino seems to (haven't opened the source) loop the
constraints and cast blindly into the specified type for that
constraint.
using System;
using NUnit.Framework;
using Rhino.Mocks;
namespace RhinoBug
{
[TestFixture]
public class Class1
{
[Test]
public void Bug()
{
// Arrange
IServiceBus serviceBus =
MockRepository.GenerateStub<IServiceBus>();
serviceBus.Stub(x => x.Send(Arg<Message2>.Matches(arg =>
arg.Value == 2))).Return(2);
serviceBus.Stub(x => x.Send
(Arg<Message1>.Is.TypeOf)).Return(1);
ClassUnderTest cut = new ClassUnderTest(serviceBus);
cut.DoMyThing();
serviceBus.AssertWasCalled(x => x.Send
(Arg<Message1>.Matches(arg => arg.Value == "Succes")));
}
}
public class Message2 : MessageBase
{
public Message2(int value)
{
Value = value;
}
public int Value { get; set; }
}
public class Message1 : MessageBase
{
public string Value;
public Message1(string s)
{
Value = s;
}
}
public interface IServiceBus
{
int Send(MessageBase msg);
}
public class ClassUnderTest
{
private IServiceBus Bus;
public ClassUnderTest(IServiceBus bus)
{
Bus = bus;
}
public void DoMyThing()
{
if (Bus.Send(new Message1("Try")) == 1)
{
if (Bus.Send(new Message2(2)) == 2)
{
Bus.Send(new Message1("Success"));
}
}
}
}
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
-~----------~----~----~----~------~----~------~--~---