public IMethodReturn Invoke(IMethodInvocation invocation, GetNextBehavior getNext) { // Allows subsequent extension methods on the fluent API to retrieve the // current invocation being performed. CallContext <IMethodInvocation> .SetData(invocation); // Determines the current setup according to contextual // matchers that may have been pushed to the MockSetup context. // Allows subsequent extension methods on the fluent API to retrieve the // current setup being performed. var setup = MockSetup.Freeze(invocation); CallContext <IMockSetup> .SetData(setup); var mock = invocation.Target is IMocked mocked ? mocked.Mock : throw new ArgumentException(Resources.TargetNotMocked); mock.Invocations.Add(invocation); if (mock is MockInfo info) { info.LastSetup = setup; } return(getNext().Invoke(invocation, getNext)); }
public IMethodReturn Invoke(IMethodInvocation invocation, GetNextBehavior getNext) { var mock = invocation.Target.GetMock(); // Allows subsequent extension methods on the fluent API to retrieve the // current invocation being performed via the MockContext. CallContext <IMethodInvocation> .SetData(invocation); // Determines the current setup according to contextual // matchers that may have been pushed to the MockSetup context. // Allows subsequent extension methods on the fluent API to retrieve the // current setup being performed via the MockContext. CallContext <IMockSetup> .SetData(MockSetup.Freeze(invocation)); // Don't record the invocation if it's performed within a setup scope. if (!SetupScope.IsActive) { mock.Invocations.Add(invocation); } // While debugging, capture invocation stack traces for easier // troubleshooting if (Debugger.IsAttached) { invocation.Context["StackTrace"] = Environment.StackTrace; } return(getNext().Invoke(invocation, getNext)); }
/// <summary> /// Implements the tracking of invocations for the excuted invocations. /// </summary> public IMethodReturn Execute(IMethodInvocation invocation, GetNextBehavior next) { // Allows subsequent extension methods on the fluent API to retrieve the // current invocation being performed via the MockContext. MockContext.CurrentInvocation = invocation; // Determines the current setup according to contextual // matchers that may have been pushed to the MockSetup context. // Allows subsequent extension methods on the fluent API to retrieve the // current setup being performed via the MockContext. MockContext.CurrentSetup = MockSetup.Freeze(invocation); // While debugging, capture invocation stack traces for easier // troubleshooting if (Debugger.IsAttached) { invocation.Context[nameof(Environment.StackTrace)] = invocation.GetStackTrace(); } return(next().Invoke(invocation, next)); }