/// <inheritdoc/>
        public IDuplicatable DeepClone(IDuplicator duplicator)
        {
            if (duplicator == null)
            {
                throw new ArgumentNullException(nameof(duplicator));
            }

            return(new MethodCallWrapper(duplicator.Copy(_method),
                                         duplicator.Copy(_names.Select(n => Tuple.Create(n, _args[n])).ToArray())));
        }
        /// <summary>Verifies mutations are prevented on a method.</summary>
        /// <param name="instance">Instance with the method under test.</param>
        /// <param name="method">Method under test.</param>
        /// <param name="callAllMethods">If all instance methods should be called after the method.</param>
        /// <param name="injectionValues">Values to inject into the method.</param>
        private void PreventsMutation(object instance,
                                      MethodBase method, bool callAllMethods, object[] injectionValues)
        {
            object[] data   = null;
            object[] copy   = null;
            object   result = null;

            try
            {
                data = Randomizer.CreateFor(method, injectionValues).Args.ToArray();
                copy = _duplicator.Copy(data);

                result = (instance == null && method is ConstructorInfo builder)
                    ? RunCheck(method, null, () => builder.Invoke(data))
                    : RunCheck(method, null, () => method.Invoke(instance, data));

                if (result != null && callAllMethods)
                {
                    CallAllMethods(method, null, result, injectionValues);
                }

                _asserter.ValuesEqual(copy, data, $"Parameter data was mutated when testing '{method.Name}'.");
            }
            finally
            {
                DisposeAllButInjected(injectionValues, data, copy, result);
            }
        }
Example #3
0
        /// <inheritdoc/>
        public IDuplicatable DeepClone(IDuplicator duplicator)
        {
            if (duplicator == null)
            {
                throw new ArgumentNullException(nameof(duplicator));
            }

            return(new CallData(_methodName, _generics.ToArray(), duplicator.Copy(_args), duplicator.Copy(_valuer)));
        }