Your code works as-is. Here's a complete test case that fails because I
changed your code to pass "b" to Method3() instead of "a". If you change
it to pass "a", it passes (as expected):
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var provider = MockRepository.GenerateStub<IProv>();
var a = MockRepository.GenerateStub<IObj>();
var b = MockRepository.GenerateStub<IObj>();
provider.Stub(x => x.Method1()).Return(a);
provider.Stub(x => x.Method2()).Return(b);
var consumer = MockRepository.GenerateMock<ICon>();
consumer.Expect(x => x.Method3(Arg<IObj>.Is.Equal(a)));
var sut = new Sut(provider, consumer);
sut.DoWork();
consumer.VerifyAllExpectations();
}
}
public class Sut
{
private readonly IProv provider;
private readonly ICon consumer;
public Sut(IProv provider, ICon consumer)
{
this.provider = provider;
this.consumer = consumer;
}
public void DoWork()
{
var a = provider.Method1();
var b = provider.Method2();
consumer.Method3(b);
}
}
public interface ICon
{
void Method3(IObj obj);
}
public interface IObj
{
}
public interface IProv
{
IObj Method1();
IObj Method2();
}
---
Patrick Steele
http://weblogs.asp.net/psteele
On Fri, Nov 8, 2013 at 9:43 AM, mike wardle <[email protected]> wrote:
> I am trying to determine if the return from a stubbed method is used as the
> parameter for another method. The problem I have is that I have multiple
> stubbed objects of the same type in the same scope tat could all potentially
> be used as the parameter, so I do not see how to determine which object is
> actually being used:
>>>
>>> var provider = MockRepository.GenerateStub<IProv>();
>>> var a = MockRepository.GenerateStub<IObj>();
>>> var b = MockRepository.GenerateStub<IObj>();
>>> prov.Stub(x => x.Method1()).Return(a);
>>> prov.Stub(x => x.Method2()).Return(b);
>>> var consumer = MockRepository.GenerateMock<ICon>();
>>> consumer.Expect(x => x.Method3(Arg<IObj>.Is.Equal(a));
>>> var sut = new Sut(provider, consumer);
>>> sut.DoWork();
>>> consumer.VerifyAllExpectations();
>>>
>>> where Sut.DoWork()
>>> {
>>> var a = provider.Method1();
>>> var b = provider.Method2();
>>> consumer.Method3(a);
>>> }
>>>
>>> Given this, it does not confirm if a or b is passed into Method3 on the
>>> consumer...
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Rhino.Mocks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/rhinomocks.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/groups/opt_out.