示例#1
0
        public void RunNamespaces(Assembly assembly, IEnumerable <string> targetNamespaces)
        {
            try
            {
                runner.StartRun(assembly);

                foreach (var targetNamespace in targetNamespaces)
                {
                    runner.RunNamespace(assembly, targetNamespace);
                }
            }
            finally
            {
                runner.EndRun(assembly);
            }
        }
示例#2
0
        public void RunTestsInAssembly(string pathToAssembly, IEnumerable <VisualStudioTestIdentifier> specsToRun, ISpecificationRunListener specificationRunListener)
        {
            DefaultRunner mspecRunner   = null;
            Assembly      assemblyToRun = null;

            try
            {
                assemblyToRun = AssemblyHelper.Load(pathToAssembly);
                mspecRunner   = CreateRunner(assemblyToRun, specificationRunListener);

                var specsByContext = specsToRun.GroupBy(x => x.ContainerTypeFullName);

                mspecRunner.StartRun(assemblyToRun);

                foreach (var specs in specsByContext)
                {
                    var fields = specs.Select(x => x.FieldName);

                    mspecRunner.RunType(assemblyToRun, assemblyToRun.GetType(specs.Key), fields.ToArray());
                }
            }
            catch (Exception e)
            {
                specificationRunListener.OnFatalError(new ExceptionResult(e));
            }
            finally
            {
                if (mspecRunner != null && assemblyToRun != null)
                {
                    mspecRunner.EndRun(assemblyToRun);
                }
            }
        }
示例#3
0
        public void RunTestsInAssembly(string pathToAssembly, IEnumerable <VisualStudioTestIdentifier> specsToRun, ISpecificationRunListener specificationRunListener)
        {
            DefaultRunner mspecRunner   = null;
            Assembly      assemblyToRun = null;

            try
            {
                assemblyToRun = AssemblyHelper.Load(pathToAssembly);
                mspecRunner   = CreateRunner(assemblyToRun, specificationRunListener);

                IEnumerable <Context>        specificationContexts = new AssemblyExplorer().FindContextsIn(assemblyToRun) ?? Enumerable.Empty <Context>();
                Dictionary <string, Context> contextMap            = specificationContexts.ToDictionary(c => c.Type.FullName, StringComparer.Ordinal);

                // We use explicit assembly start and end to wrap the RunMember loop
                mspecRunner.StartRun(assemblyToRun);

                foreach (VisualStudioTestIdentifier test in specsToRun)
                {
                    Context context = contextMap[test.ContainerTypeFullName];
                    if (context == null)
                    {
                        continue;
                    }

                    Specification specification = context.Specifications.SingleOrDefault(spec => spec.FieldInfo.Name.Equals(test.FieldName, StringComparison.Ordinal));

                    if (specification is BehaviorSpecification)
                    {
                        // MSpec doesn't expose any way to run an an "It" coming from a "[Behavior]", so we have to do some trickery
                        VisualStudioTestIdentifier listenFor = specification.ToVisualStudioTestIdentifier(context);
                        DefaultRunner behaviorRunner         = new DefaultRunner(new SingleBehaviorTestRunListenerWrapper(specificationRunListener, listenFor), RunOptions.Default);
                        behaviorRunner.RunMember(assemblyToRun, context.Type.GetTypeInfo());
                    }
                    else
                    {
                        mspecRunner.RunMember(assemblyToRun, specification.FieldInfo);
                    }
                }
            } catch (Exception e) {
                specificationRunListener.OnFatalError(new ExceptionResult(e));
            }
            finally
            {
                if (mspecRunner != null && assemblyToRun != null)
                {
                    mspecRunner.EndRun(assemblyToRun);
                }
            }
        }