public void Execute(InvocationDescriptor invocationDescriptor)
        {
            invocationDescriptor.Invocation.ReturnValue = invocationDescriptor.Method.GetDefaultReturnValue();

            var index = nextIndex;

            if (index == invocationOperations.Count)
            {
                index = jumpBackIndex;
            }

            while (index < invocationOperations.Count)
            {
                var invocationOperation = invocationOperations[index];
                index++;

                var execution = invocationOperation.Execute(invocationDescriptor);
                if (execution == Execution.Stop)
                {
                    break;
                }
            }

            nextIndex = index;
            if (index != invocationOperations.Count)
            {
                jumpBackIndex = index;
            }
        }
Example #2
0
        public void AddInvocationOperation(InvocationDescriptor invocationDescriptor, InvocationOperation invocationOperation)
        {
            var mockAndMethod = new MockAndMethod(invocationDescriptor);
            var sub           = table.GetOrAdd(mockAndMethod, add => new MockMethodInvocationOperationManagerFinder());

            sub.AddInvocationOperation(invocationDescriptor, invocationOperation);
        }
Example #3
0
 public bool TryFind(InvocationDescriptor invocationDescriptor, out InvocationOperationManager invocationOperationManager)
 {
     lock (synchronization) {
         invocationOperationManager = operationManagers.FirstOrDefault(
             operationManager => operationManager.Matches(invocationDescriptor));
         return(invocationOperationManager != null);
     }
 }
Example #4
0
        public void SetLastInvocation(InvocationDescriptor invocationDescriptor)
        {
            var lastStagedInvocationDescriptor = SwapLastStagedInvocation(invocationDescriptor);

            if (lastStagedInvocationDescriptor != null)
            {
                verificationInvocationsContainer.HandleUnverifiedInvocation(lastStagedInvocationDescriptor);
            }
        }
Example #5
0
        public bool TryFind(InvocationDescriptor invocationDescriptor, out InvocationOperationManager invocationOperationManager)
        {
            invocationOperationManager = null;
            var mockAndMethod = new MockAndMethod(invocationDescriptor);
            MockMethodInvocationOperationManagerFinder mockMethodInvocationOperationManagerFinder;

            return(table.TryGetValue(mockAndMethod, out mockMethodInvocationOperationManagerFinder) &&
                   mockMethodInvocationOperationManagerFinder.TryFind(invocationDescriptor, out invocationOperationManager));
        }
Example #6
0
        public void Backward(InvocationDescriptor invocationDescriptor)
        {
            var transformations = invocationDescriptor.Transformations;

            for (var i = transformations.Count - 1; i >= 0; i--)
            {
                var transformation = transformations[i];
                transformation.Backward(invocationDescriptor);
            }
        }
Example #7
0
        private bool TrySwapStagedInvocationDescriptor(InvocationDescriptor invocationDescriptor, out InvocationDescriptor lastStagedInvocationDescriptor)
        {
            lastStagedInvocationDescriptor = stagedInvocationDescriptor;
            var originalStagedInvocationDescriptor = Interlocked.CompareExchange(
                ref stagedInvocationDescriptor,
                invocationDescriptor,
                lastStagedInvocationDescriptor);

            return(originalStagedInvocationDescriptor == lastStagedInvocationDescriptor);
        }
Example #8
0
 public void Forward(InvocationDescriptor invocationDescriptor)
 {
     foreach (var transformation in possibleTransformations)
     {
         if (transformation.IsApplicable(invocationDescriptor))
         {
             transformation.Forward(invocationDescriptor);
             invocationDescriptor.Transformations.Add(transformation);
         }
     }
 }
Example #9
0
        private InvocationDescriptor SwapLastStagedInvocation(InvocationDescriptor invocationDescriptor)
        {
            InvocationDescriptor lastStagedInvocationDescriptor;
            SpinWait             spinner = new SpinWait();

            while (!TrySwapStagedInvocationDescriptor(invocationDescriptor, out lastStagedInvocationDescriptor))
            {
                spinner.SpinOnce();
            }
            return(lastStagedInvocationDescriptor);
        }
Example #10
0
 public void AddInvocationOperation(InvocationDescriptor invocationDescriptor, InvocationOperation invocationOperation)
 {
     lock (synchronization) {
         InvocationOperationManager invocationOperationManager;
         if (!TryFind(invocationDescriptor, out invocationOperationManager))
         {
             invocationOperationManager = new InvocationOperationManager(invocationDescriptor.SmartParameters);
             operationManagers.Add(invocationOperationManager);
         }
         invocationOperationManager.AddInvocationOperation(invocationOperation);
     }
 }
Example #11
0
 public MockAndMethod(InvocationDescriptor invocationDescriptor)
 {
     Mock   = invocationDescriptor.Mock;
     Method = invocationDescriptor.Method;
 }
 public bool Matches(InvocationDescriptor invocationDescriptor)
 {
     return(smartParameterCollection.Matches(invocationDescriptor));
 }