Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Moq/IInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ public interface IInvocation
/// Optional exception if the method invocation results in an exception being thrown.
/// </summary>
Exception Exception { get; }

/// <summary>
/// A number representing the order of this invocation in time with respect to all other invocations
/// </summary>
long SequenceNumber { get; }
}
}
20 changes: 20 additions & 0 deletions src/Moq/IVerifyResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Moq
{
/// <summary>
/// A collection of invocations verified by a call to mock.Verify() or one of its variations
/// </summary>
/// <typeparam name="T">The type being mocked and verified</typeparam>
public interface IVerifyResult<T> : IReadOnlyList<IInvocation> where T: class
{
/// <summary>
/// The mock that was verified
/// </summary>
Mock<T> Mock { get; }
}
}
7 changes: 6 additions & 1 deletion src/Moq/Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Text;

using System.Threading;
using Moq.Async;

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

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

public long SequenceNumber => this.sequenceNumber;

/// <summary>
/// Gets the method of the invocation.
/// </summary>
Expand Down
19 changes: 10 additions & 9 deletions src/Moq/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ internal void Verify(Func<ISetup, bool> predicate, HashSet<Mock> verifiedMocks)
}
}

internal static void Verify(Mock mock, LambdaExpression expression, Times times, string failMessage)
internal static IEnumerable<IInvocation> Verify(Mock mock, LambdaExpression expression, Times times, string failMessage)
{
Guard.NotNull(times, nameof(times));

Expand All @@ -326,14 +326,15 @@ internal static void Verify(Mock mock, LambdaExpression expression, Times times,
part.SetupEvaluatedSuccessfully(invocation);
invocation.MarkAsVerified();
}
return invocationsToBeMarkedAsVerified.Select(pair => (IInvocation)pair.Item1);
}
else
{
throw MockException.NoMatchingCalls(mock, expression, failMessage, times, invocationCount);
}
}

internal static void VerifyGet(Mock mock, LambdaExpression expression, Times times, string failMessage)
internal static IEnumerable<IInvocation> VerifyGet(Mock mock, LambdaExpression expression, Times times, string failMessage)
{
Guard.NotNull(expression, nameof(expression));

Expand All @@ -343,31 +344,31 @@ internal static void VerifyGet(Mock mock, LambdaExpression expression, Times tim
Guard.CanRead(property);
}

Mock.Verify(mock, expression, times, failMessage);
return Mock.Verify(mock, expression, times, failMessage);
}

internal static void VerifySet(Mock mock, LambdaExpression expression, Times times, string failMessage)
internal static IEnumerable<IInvocation> VerifySet(Mock mock, LambdaExpression expression, Times times, string failMessage)
{
Guard.NotNull(expression, nameof(expression));
Guard.IsAssignmentToPropertyOrIndexer(expression, nameof(expression));

Mock.Verify(mock, expression, times, failMessage);
return Mock.Verify(mock, expression, times, failMessage);
}

internal static void VerifyAdd(Mock mock, LambdaExpression expression, Times times, string failMessage)
internal static IEnumerable<IInvocation> VerifyAdd(Mock mock, LambdaExpression expression, Times times, string failMessage)
{
Guard.NotNull(expression, nameof(expression));
Guard.IsEventAdd(expression, nameof(expression));

Mock.Verify(mock, expression, times, failMessage);
return Mock.Verify(mock, expression, times, failMessage);
}

internal static void VerifyRemove(Mock mock, LambdaExpression expression, Times times, string failMessage)
internal static IEnumerable<IInvocation> VerifyRemove(Mock mock, LambdaExpression expression, Times times, string failMessage)
{
Guard.NotNull(expression, nameof(expression));
Guard.IsEventRemove(expression, nameof(expression));

Mock.Verify(mock, expression, times, failMessage);
return Mock.Verify(mock, expression, times, failMessage);
}

internal static void VerifyNoOtherCalls(Mock mock)
Expand Down
Loading