/// <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;
        }
Exemplo n.º 2
0
        /// <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);
        }
        protected override IEnumerable<TestMethod> GenerateTestMethodsFor(ConstructorMetadata metadata)
        {
            if (IsDefaultConstructor(metadata.Constructor))
            {
                return Enumerable.Empty<TestMethod>();
            }

            var methods = new List<TestMethod>();
            foreach (var nullParameter in metadata.Constructor.GetParameters().Where(x => ParameterSatisfied(x)))
            {
                var request = new ConstructorSourceCodeGenerationRequest(metadata.Constructor,
                    metadata.NullArgumentNeedsExplicitCast,
                    metadata.HasMultipleConstructors,
                    nullParameter);
                var sourceCode = sourceCodeGenerator.BuildSourceCode(request);
                var method = new TestMethod(metadata.Constructor, sourceCodeGenerator.BuildMethodName(request), sourceCode, typeof(ArgumentNullException));
                methods.Add(method);
            }
            return methods;
        }
Exemplo n.º 4
0
        protected override IEnumerable <TestMethod> GenerateTestMethodsFor(ConstructorMetadata metadata)
        {
            if (IsDefaultConstructor(metadata.Constructor))
            {
                return(Enumerable.Empty <TestMethod>());
            }

            var methods = new List <TestMethod>();

            foreach (var nullParameter in metadata.Constructor.GetParameters().Where(x => ParameterSatisfied(x)))
            {
                var request = new ConstructorSourceCodeGenerationRequest(metadata.Constructor,
                                                                         metadata.NullArgumentNeedsExplicitCast,
                                                                         metadata.HasMultipleConstructors,
                                                                         nullParameter);
                var sourceCode = sourceCodeGenerator.BuildSourceCode(request);
                var method     = new TestMethod(metadata.Constructor, sourceCodeGenerator.BuildMethodName(request), sourceCode, typeof(ArgumentNullException));
                methods.Add(method);
            }
            return(methods);
        }
 protected abstract IEnumerable<TestMethod> GenerateTestMethodsFor(ConstructorMetadata metadata);
Exemplo n.º 6
0
 protected abstract IEnumerable <TestMethod> GenerateTestMethodsFor(ConstructorMetadata metadata);