Beispiel #1
0
        public void HandleMockVerification(IInvocation invocation, INMockitoTimesMatcher times, NMockitoOrder order)
        {
            invocation.ReturnValue = GetDefaultValue(invocation.Method.ReturnType);

            // Flatten params[] of invocation arguments
            var method              = invocation.Method;
            var methodParameters    = method.GetParameters();
            var invocationArguments = invocation.Arguments;

            if (methodParameters.Length > 0 &&
                methodParameters.Last().GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0 &&
                invocationArguments.Last() != null)
            {
                var paramsArray            = (Array)invocationArguments.Last();
                var newInvocationArguments = new object[invocationArguments.Length + paramsArray.Length - 1];
                var cutIndex = invocationArguments.Length - 1;
                Array.Copy(invocationArguments, newInvocationArguments, cutIndex);
                Array.Copy(paramsArray, 0, newInvocationArguments, cutIndex, paramsArray.Length);
                invocationArguments = newInvocationArguments;
            }

            var smartParameters = NMockitoSmartParameters.CopyAndClearSmartParameters().ToArray();

            if (smartParameters.Length == 0)
            {
                smartParameters = ConvertInvocationArgumentsToEqualityParameters(invocationArguments);
            }
            if (smartParameters.Length != invocationArguments.Length)
            {
                throw new NMockitoNotEnoughSmartParameters();
            }
            // Find out/ref parameters, swap them with null
            for (var i = 0; i < methodParameters.Length; i++)
            {
                var parameter = methodParameters[i];
                if (parameter.Attributes.HasFlag(ParameterAttributes.Out))
                {
                    smartParameters[i] = null;
                }
            }

            var counters = FindMatchingInvocationCounters(invocation.Method, invocation.GenericArguments, smartParameters);

            times.MatchOrThrow(counters.Sum(counter => counter.Count), invocation, invocationCountsByInvocation);
            foreach (var counter in counters)
            {
                foreach (var count in counter)
                {
                    NMockitoInvocationCounters.AcceptVerificationCounterOrThrow(count, order);
                }
                counter.Clear();
            }
        }
Beispiel #2
0
 [DebuggerHidden] public T Any <T>(Func <T, bool> test = null)
 {
     return(NMockitoSmartParameters.Any <T>(test));
 }
Beispiel #3
0
 [DebuggerHidden] public T Eq <T>(T value)
 {
     return(NMockitoSmartParameters.Eq(value));
 }
Beispiel #4
0
 [DebuggerHidden] public TCollection EqSequence <TCollection>(TCollection value)
     where TCollection : IEnumerable
 {
     return(NMockitoSmartParameters.EqSequence(value));
 }
Beispiel #5
0
 public WhenContext()
 {
     invocationAndMockState = NMockitoGlobals.GetLastInvocationAndMockState();
     invocationAndMockState.State.DecrementInvocationCounter(invocationAndMockState.Invocation);
     smartParameters = NMockitoSmartParameters.CopyAndClearSmartParameters();
 }