Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created January 17, 2013 08:28
Show Gist options
  • Save dtchepak/4554546 to your computer and use it in GitHub Desktop.
Save dtchepak/4554546 to your computer and use it in GitHub Desktop.
Ordering samples
[Test]
public void Check_across_different_types() {
var a = Substitute.For<IFoo>();
var b = Substitute.For<IBaz>();
var c = Substitute.For<IFoo>();
a.Zap();
c.Zap();
b.Gloop(1);
a.Bar();
Received.InOrder(() => {
a.Zap();
b.Gloop(1);
c.Zap();
a.Bar();
});
}
/*
>>> Number each instance of type <<<
Expected to receive these calls in order:
IFoo#1.Zap()
IBaz#1.Gloop(1)
IFoo#2.Zap()
IFoo#1.Bar()
Actually received matching calls in this order:
IFoo#1.Zap()
IFoo#2.Zap()
IBaz#1.Gloop(1)
IFoo#1.Bar()
**** Disadvantage:
**** what to do with subs that implement multiple interfaces?
**** Number is overloaded - number of calls or instance number?
**** e.g. Sub.For<IFoo,IBaz>();
>>> Identify substitutes in order <<<
Expected to receive these calls in order:
sub0: IFoo.Zap()
sub1: IBaz.Gloop(1)
sub2: IFoo.Zap()
sub0: IFoo.Bar()
Actually received matching calls in this order:
sub0: IFoo.Zap()
sub2: IFoo.Zap()
sub1: IBaz.Gloop(1)
sub0: IFoo.Bar()
**** Advantage: Get to use "subzero" in an exception. Flawless, victory.
**** Disadvantage: difficult to compare?
>>> Identify substitutes in order with descriptive message <<<
Expected to receive these calls in order:
IFoo.Zap() called on substitute 0
IBaz.Gloop(1) called on substitute 1
IFoo.Zap() called on substitute 2
IFoo.Bar() called on substitute 0
Actually received matching calls in this order:
IFoo.Zap() called on substitute 0
IFoo.Zap() called on substitute 2
IBaz.Gloop(1) called on substitute 1
IFoo.Bar() called on substitute 0
**** Disadvantage: awful
>>> Identify substitutes in order via a non-numeric reference <<<
Expected to receive these calls in order:
IFoo a.Zap()
IBaz b.Gloop(1)
IFoo c.Zap()
IFoo a.Bar()
Actually received matching calls in this order:
IFoo a.Zap()
IFoo c.Zap()
IBaz b.Gloop(1)
IFoo a.Bar()
**** Advantage/Disadvantage: I don't even know
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment