/// <summary>
        /// Generates a enumeration of <see cref="TestMethod"/>.
        /// </summary>
        /// <param name="typeContext">The context for which the methods are generated.</param>
        /// <returns>The enumeration of <see cref="TestMethod"/>.</returns>
        public IEnumerable<TestMethod> GenerateTestMethods(TypeContext typeContext)
        {
            var tests = new List<TestMethod>();
            var methodsToTest = GetMethodsToTest(typeContext.TargetType, typeContext.InternalsVisible);
            var explicitMethodParameters = GetMethodsWithExplicitParameterCast(methodsToTest);
            var overloadedMethods = GetOverloadedMethodsWithConflictingParameter(methodsToTest);

            foreach (var method in methodsToTest)
            {
                var metadata = new MethodMetadata(method,
                    explicitMethodParameters.Contains(method),
                    overloadedMethods.Contains(method));
                var testMethods = GenerateTestMethodsFor(metadata);
                tests.AddRange(testMethods);
            }
            return tests;
        }
Exemple #2
0
        /// <summary>
        /// Generates a enumeration of <see cref="TestMethod"/>.
        /// </summary>
        /// <param name="typeContext">The context for which the methods are generated.</param>
        /// <returns>The enumeration of <see cref="TestMethod"/>.</returns>
        public IEnumerable <TestMethod> GenerateTestMethods(TypeContext typeContext)
        {
            var tests                    = new List <TestMethod>();
            var methodsToTest            = GetMethodsToTest(typeContext.TargetType, typeContext.InternalsVisible);
            var explicitMethodParameters = GetMethodsWithExplicitParameterCast(methodsToTest);
            var overloadedMethods        = GetOverloadedMethodsWithConflictingParameter(methodsToTest);

            foreach (var method in methodsToTest)
            {
                var metadata = new MethodMetadata(method,
                                                  explicitMethodParameters.Contains(method),
                                                  overloadedMethods.Contains(method));
                var testMethods = GenerateTestMethodsFor(metadata);
                tests.AddRange(testMethods);
            }
            return(tests);
        }
Exemple #3
0
        protected override IEnumerable <TestMethod> GenerateTestMethodsFor(MethodMetadata metadata)
        {
            var tests = new List <TestMethod>();

            var parameters = metadata.Method.GetParameters();

            foreach (var nullParameter in parameters.Where(x => ParameterSatisfied(x)))
            {
                var request = new MethodSourceCodeGenerationRequest(metadata.Method,
                                                                    metadata.NullArgumentNeedsExplicitCast,
                                                                    nullParameter,
                                                                    metadata.ConflictingMethodParameterName);
                var    sourceCode = sourceCodeGenerator.BuildSourceCode(request);
                string methodName = sourceCodeGenerator.BuildMethodName(request);

                var testMethod = new TestMethod(metadata.Method, methodName, sourceCode, typeof(ArgumentNullException));
                tests.Add(testMethod);
            }

            return(tests);
        }
 protected abstract IEnumerable<TestMethod> GenerateTestMethodsFor(MethodMetadata metadata);
Exemple #5
0
 protected abstract IEnumerable <TestMethod> GenerateTestMethodsFor(MethodMetadata metadata);