public IEnumerable<TestMethod> GenerateTestMethods(TypeContext typeContext) { foreach (var method in GetMethods(typeContext)) { var request = new MethodSourceCodeGenerationRequest(method, true, method.GetParameters().First()); var methodName = sourceCodeGenerator.BuildMethodName(request); var sourceCode = sourceCodeGenerator.BuildSourceCode(request); yield return new TestMethod(method, methodName, sourceCode); } }
/// <summary> /// Generates a collection of <see cref="TestMethod"/>. /// </summary> /// <param name="typeContext">The context for which the methods are generated.</param> /// <returns>Collection of <see cref="TestMethod"/>.</returns> public IEnumerable<TestMethod> GenerateTestMethods(TypeContext typeContext) { var tests = new List<TestMethod>(); var ctorsToTest = GetAccessibleContructors(typeContext.TargetType, typeContext.InternalsVisible); var explicitMethodParameters = GetCtorsWithExplicitParameterCast(ctorsToTest); var hasMultipleConstructors = HasMultipleParametrizedConstructors(ctorsToTest); foreach (var ctor in ctorsToTest) { var metadata = new ConstructorMetadata(ctor, explicitMethodParameters.Contains(ctor), hasMultipleConstructors); var testMethods = GenerateTestMethodsFor(metadata); tests.AddRange(testMethods); } return tests; }
/// <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; }
private static System.Reflection.MethodInfo[] GetMethods(TypeContext typeContext) { return typeContext.TargetType.GetMethods() .Where(x => x.GetParameters().Count() > 1) .ToArray(); }