Skip to content

Commit 59a238b

Browse files
PatrickScottDSkzu
authored andcommitted
Record a global call order between all invocations to be used in sequence verification
1 parent 8316dc2 commit 59a238b

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/Moq/IInvocation.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@ public interface IInvocation
4141
/// Optional exception if the method invocation results in an exception being thrown.
4242
/// </summary>
4343
Exception Exception { get; }
44+
45+
/// <summary>
46+
/// A number representing the order of this invocation in time with respect to all other invocations
47+
/// </summary>
48+
long SequenceNumber { get; }
4449
}
4550
}

src/Moq/Invocation.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Diagnostics;
77
using System.Reflection;
88
using System.Text;
9-
9+
using System.Threading;
1010
using Moq.Async;
1111

1212
namespace Moq
@@ -20,6 +20,8 @@ abstract class Invocation : IInvocation
2020
object result;
2121
Setup matchingSetup;
2222
bool verified;
23+
long sequenceNumber;
24+
static long globalSequenceNumber = 0;//ONLY access with Interlocked.Increment()
2325

2426
/// <summary>
2527
/// Initializes a new instance of the <see cref="Invocation"/> class.
@@ -36,8 +38,11 @@ protected Invocation(Type proxyType, MethodInfo method, params object[] argument
3638
this.arguments = arguments;
3739
this.method = method;
3840
this.proxyType = proxyType;
41+
this.sequenceNumber = Interlocked.Increment(ref globalSequenceNumber);
3942
}
4043

44+
public long SequenceNumber => this.sequenceNumber;
45+
4146
/// <summary>
4247
/// Gets the method of the invocation.
4348
/// </summary>

0 commit comments

Comments
 (0)