Sorry to be that late, I was in holiday :-)
Arg is designed to take the arguments type as generic argument. So you
have to use Arg<MessageBase>. But then, you can't use the lamda for
the property constraint.
With the classic property constraint it works:
// Arrange
IServiceBus serviceBus = MockRepository.GenerateStub<IServiceBus>();
serviceBus.Stub(
x => x.Send(Arg<MessageBase>.Matches(
Property.Value("Value", 2)
&& Is.TypeOf<Message2>())))
.Return(2);
serviceBus.Stub(x => x.Send(Arg<Message1>.Is.TypeOf))
.Return(1);
serviceBus.Expect(
x => x.Send(Arg<MessageBase>.Matches(
Property.Value("Value", "Success")
&& Is.TypeOf<Message1>())));
ClassUnderTest cut = new ClassUnderTest(serviceBus);
cut.DoMyThing();
serviceBus.VerifyAllExpectations();
AssertWasCalled also didn't work. I don't know why, probably it does
not consider the constraints correctly.
So there are two separate problems.
- Arg<T> should implicitly constrain for TypeOf<T>, and the lamda will
most probably work.
- AssertWasCalled should probably consider the constraints.
On 6 Mrz., 17:48, Thejuan <[email protected]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---