Why checking call corder with ReceivedWithAnyArgs failed?

378 views
Skip to first unread message

Jeffrey Zhao

unread,
Jan 25, 2017, 12:37:08 PM1/25/17
to NSubstitute
public interface ITarget
{
 
void Call(string s);
}



[Test]
public void CallOrderReceiveWithAnyArgs()
{
 
var target1 = Substitute.For<ITarget>();
 
var target2 = Substitute.For<ITarget>();

  target1
.Call("A");
  target2
.Call("B");

 
// Pass
  target1
.ReceivedWithAnyArgs().Call(null);
  target2
.ReceivedWithAnyArgs().Call(null);

 
// Pass
 
Received.InOrder(() =>
 
{
    target1
.Received().Call(Arg.Any<string>());
    target2
.Received().Call(Arg.Any<string>());
 
});

 
// Fail
 
Received.InOrder(() =>
 
{
    target1
.ReceivedWithAnyArgs().Call(null);
    target2
.ReceivedWithAnyArgs().Call(null);
 
});
}

Why we have to use argument matcher instead of using ReceivedWithAnyArgs which is much simpler when there's a complex argument type involved?

David Tchepak

unread,
Jan 26, 2017, 10:15:55 PM1/26/17
to nsubs...@googlegroups.com
Hi,
You shouldn't need to use `Received()` within a `Received.InOrder` block.

Received.InOrder(() => {
    target1.Call(Arg.Any<string>());
    target2.Call(Arg.Any<string>());
});

The two ways of asserting received calls aren't really compatible (which is admittedly quite confusing). Unfortunately this means there is no "ForAnyArgs" type of behaviour available in a `Received.InOrder` block.

Regards,
David

--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nsubstitute+unsubscribe@googlegroups.com.
To post to this group, send email to nsubs...@googlegroups.com.
Visit this group at https://groups.google.com/group/nsubstitute.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages