Example #1
0
        public AssemblyResult RunMethod(Assembly assembly, MethodInfo method)
        {
            var runContext = new RunContext(assembly, options, method);

            var conventions = GetConventions(runContext);

            foreach (var convention in conventions)
                convention.Methods.Where(m => m == method);

            var type = method.DeclaringType;

            return Run(runContext, conventions, type);
        }
Example #2
0
        public Result RunMethod(Assembly assembly, MethodInfo method)
        {
            var runContext = new RunContext(assembly, options, method);

            var conventions = GetConventions(runContext);

            foreach (var convention in conventions)
                convention.Cases = new CustomCaseFilter().SetFilterMethod(t => new List<MemberInfo>{t.GetMethod(method.Name)});

            var type = method.DeclaringType;

            return Run(runContext, conventions, type);
        }
Example #3
0
        static Convention ConstructConvention(Type conventionType, RunContext runContext)
        {
            var constructors = conventionType.GetConstructors();

            if (constructors.Length == 1)
            {
                var parameters = constructors.Single().GetParameters();

                if (parameters.Length == 1 && parameters.Single().ParameterType == typeof(RunContext))
                    return (Convention)Activator.CreateInstance(conventionType, runContext);
            }

            return (Convention)Activator.CreateInstance(conventionType);
        }
Example #4
0
        public AssemblyResult RunType(Assembly assembly, Type type)
        {
            if (type.IsSubclassOf(typeof(Convention)))
            {
                var singleConventionRunContext = new RunContext(assembly, options);
                var singleConvention = ConstructConvention(type, singleConventionRunContext);

                return RunTypes(singleConventionRunContext, singleConvention, assembly.GetTypes());
            }

            var runContext = new RunContext(assembly, options, type);

            return RunTypes(runContext, type);
        }
Example #5
0
        public CustomConvention(RunContext runContext)
        {
            Classes
                .NameEndsWith("Tests");

            Cases
                .Where(method => method.Void())
                .Where(method =>
                {
                    var isMarkedExplicit = method.Has<ExplicitAttribute>();

                    return !isMarkedExplicit || runContext.TargetMember == method;
                });

            ClassExecution
                .CreateInstancePerTestClass();
        }
Example #6
0
        public CustomConvention(RunContext runContext)
        {
            var desiredCategories = runContext.Options["include"].ToArray();
            var shouldRunAll = !desiredCategories.Any();

            Classes
                .NameEndsWith("Tests");

            Cases
                .Where(method => method.Void())
                .Where(method => shouldRunAll || MethodHasAnyDesiredCategory(method, desiredCategories));

            if (!shouldRunAll)
            {
                Console.WriteLine("Categories: " + string.Join(", ", desiredCategories));
                Console.WriteLine();
            }
        }
Example #7
0
        static Convention[] GetConventions(RunContext runContext)
        {
            var customConventions = runContext.Assembly
                .GetTypes()
                .Where(t => t.IsSubclassOf(typeof(Convention)))
                .Select(t => ConstructConvention(t, runContext))
                .ToArray();

            if (customConventions.Any())
                return customConventions;

            return new[] { (Convention) new DefaultConvention() };
        }
Example #8
0
        public AssemblyResult RunNamespace(Assembly assembly, string ns)
        {
            var runContext = new RunContext(assembly, options);

            return RunTypes(runContext, assembly.GetTypes().Where(type => type.IsInNamespace(ns)).ToArray());
        }
Example #9
0
        public AssemblyResult RunAssembly(Assembly assembly)
        {
            var runContext = new RunContext(assembly, options);

            return RunTypes(runContext, assembly.GetTypes());
        }
Example #10
0
 private AssemblyResult RunTypes(RunContext runContext, Convention convention, params Type[] types)
 {
     return Run(runContext, new[] { convention }, types);
 }
Example #11
0
 private AssemblyResult RunTypes(RunContext runContext, params Type[] types)
 {
     return Run(runContext, GetConventions(runContext), types);
 }
Example #12
0
        AssemblyResult Run(RunContext runContext, IEnumerable<Convention> conventions, params Type[] candidateTypes)
        {
            var resultListener = new AssemblyResultListener(listener);

            resultListener.AssemblyStarted(runContext.Assembly);

            foreach (var convention in conventions)
                convention.Execute(resultListener, candidateTypes);

            var result = resultListener.AssemblyResult;

            resultListener.AssemblyCompleted(runContext.Assembly, result);

            return result;
        }
Example #13
0
        public AssemblyResult RunType(Assembly assembly, Convention convention, Type type)
        {
            var runContext = new RunContext (assembly, options);

            return RunTypes (runContext, convention, type);
        }
Example #14
0
        AssemblyResult Run(RunContext runContext, IEnumerable<Convention> conventions, params Type[] candidateTypes)
        {
            var assemblyResult = new AssemblyResult(runContext.Assembly.Location);

            listener.AssemblyStarted(runContext.Assembly);

            foreach (var convention in conventions)
            {
                var conventionResult = convention.Execute(listener, candidateTypes);

                assemblyResult.Add(conventionResult);
            }

            listener.AssemblyCompleted(runContext.Assembly, assemblyResult);

            return assemblyResult;
        }