Skip to content

Commit

Permalink
Merge HandleTracking into RecordInvocation (#723)
Browse files Browse the repository at this point in the history
The first of these two interception aspects basically has the same
purpose as the latter: recording that an invocation happened. For this
reason, it would make sense to do combine the former into the latter,
and thus to speed up the interception pipeline.

There's one possible BUT against moving the logic of `HandleTracking`
into `RecordInvocation`: In `RecordInvocation`, we no longer have the
chance to record invocations of "well-known methods" (such as those
defined by `System.Object`) because the interception pipeline might
already have stopped at that point.

Fortunately, this doesn't matter as we are typically not interested in
those well-known methods when making use of `AmbientObserver`: they
don't have signatures that allow chaining or assignment, nor are they
matchers.
  • Loading branch information
stakx authored Nov 11, 2018
1 parent ce4240a commit c5ffae8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
17 changes: 2 additions & 15 deletions src/Moq/Interception/InterceptionAspects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,15 @@ public override InterceptionAction Handle(Invocation invocation, Mock mock)
}
}

internal sealed class HandleTracking : InterceptionAspect
{
public static HandleTracking Instance { get; } = new HandleTracking();

public override InterceptionAction Handle(Invocation invocation, Mock mock)
{
if (AmbientObserver.IsActive(out var observer))
{
observer.OnInvocation(mock, invocation);
}
return InterceptionAction.Continue;
}
}

internal sealed class RecordInvocation : InterceptionAspect
{
public static RecordInvocation Instance { get; } = new RecordInvocation();

public override InterceptionAction Handle(Invocation invocation, Mock mock)
{
if (AmbientObserver.IsActive(out _))
if (AmbientObserver.IsActive(out var observer))
{
observer.OnInvocation(mock, invocation);
return InterceptionAction.Continue;
}

Expand Down
1 change: 0 additions & 1 deletion src/Moq/Interception/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ partial class Mock : IInterceptor
{
private static InterceptionAspect[] aspects = new InterceptionAspect[]
{
HandleTracking.Instance,
HandleWellKnownMethods.Instance,
RecordInvocation.Instance,
FindAndExecuteMatchingSetup.Instance,
Expand Down

0 comments on commit c5ffae8

Please sign in to comment.