예제 #1
0
        /// <summary>Verifies mutations are prevented on methods.</summary>
        /// <param name="type">Type to verify.</param>
        /// <param name="callAllMethods">Run instance methods to validate factory parameters.</param>
        /// <param name="injectionValues">Values to inject into the method.</param>
        internal void PreventsMutationOnStatics(Type type, bool callAllMethods, params object[] injectionValues)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            foreach (MethodInfo method in FindAllMethods(type, BindingFlags.Static))
            {
                PreventsMutation(null, Fixer.FixMethod(method),
                                 callAllMethods && method.ReturnType.Inherits(type), injectionValues);
            }
        }
예제 #2
0
        /// <summary>Verifies mutations are prevented on methods.</summary>
        /// <param name="instance">Instance to test the methods on.</param>
        /// <param name="injectionValues">Values to inject into the method.</param>
        internal void PreventsMutationOnMethods(object instance, params object[] injectionValues)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            foreach (MethodInfo method in FindAllMethods(instance.GetType(), BindingFlags.Instance)
                     .Where(m => m.Name is not "Finalize" and not "Dispose"))
            {
                PreventsMutation(instance, Fixer.FixMethod(method), false, injectionValues);
            }
        }
예제 #3
0
        /// <summary>Calls all methods to test parameter being set to null.</summary>
        /// <param name="testOrigin">Method under test.</param>
        /// <param name="testParam">Parameter being set to null.</param>
        /// <param name="instance">Instance whose methods to test.</param>
        /// <param name="injectionValues">Values to inject into the method.</param>
        protected void CallAllMethods(MethodBase testOrigin,
                                      ParameterInfo testParam, object instance, object[] injectionValues)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            foreach (MethodInfo method in FindAllMethods(instance.GetType(), BindingFlags.Instance)
                     .Where(m => m.Name is not "Finalize" and not "Dispose")
                     .Where(m => !m.IsFamily)
                     .Select(m => Fixer.FixMethod(m)))
            {
                object[] data = Randomizer.CreateFor(method, injectionValues).Args.ToArray();
                try
                {
                    Disposer.Cleanup(RunCheck(testOrigin ?? method, testParam, () => method.Invoke(instance, data)));
                }
                finally
                {
                    DisposeAllButInjected(injectionValues, data);
                }
            }
        }