コード例 #1
0
        public void RunMembers(Assembly assembly, IEnumerable <MemberInfo> members)
        {
            try
            {
                runner.StartRun(assembly);

                foreach (var member in members)
                {
                    runner.RunMember(assembly, member);
                }
            }
            finally
            {
                runner.EndRun(assembly);
            }
        }
コード例 #2
0
        public void RunTestsInAssembly(string pathToAssembly, IEnumerable <string> specsToRun, ISpecificationRunListener specificationRunListener)
        {
            try
            {
                Assembly assemblyToRun = Assembly.LoadFrom(pathToAssembly);

                DefaultRunner mspecRunner = new DefaultRunner(specificationRunListener, RunOptions.Default);
                foreach (string spec in specsToRun)
                {
                    // get the spec type
                    string[] splits        = spec.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries);
                    string   specClassName = splits[0];
                    string   specFieldName = splits[1];
                    Type     specType      = assemblyToRun.GetType(specClassName);

                    // get the method info from the type
                    MemberInfo specField = specType.GetMembers(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public).Where(x => x.Name == specFieldName).SingleOrDefault();
                    mspecRunner.RunMember(assemblyToRun, specField);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #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);
                }
            }
        }
コード例 #4
0
        void RunContext(TaskExecutionNode node)
        {
            var task = (ContextTask)node.RemoteTask;

            _contextClass = _contextAssembly.GetType(task.ContextTypeName);
            if (_contextClass == null)
            {
                Server.TaskExplain(task,
                                   String.Format("Could not load type '{0}' from assembly {1}.",
                                                 task.ContextTypeName,
                                                 task.AssemblyLocation));
                Server.TaskError(node.RemoteTask, "Could not load context");
                return;
            }

            _runner.RunMember(_contextAssembly, _contextClass);
        }
コード例 #5
0
 public static void Run <T>()
 {
     runner.RunMember(typeof(T).GetTypeInfo().Assembly, typeof(T).GetTypeInfo());
 }
コード例 #6
0
        public void RunTestsInAssembly(string pathToAssembly, IEnumerable <string> specsToRun, ISpecificationRunListener specificationRunListener)
        {
            DefaultRunner mspecRunner            = null;
            dynamic       dynMSpeccRunner        = null;
            Assembly      assemblyToRun          = null;
            bool          canIndicateStartAndEnd = false;

            // determine the mspec version, if its greater or equal to 0.5.12 we can call the start and endrun methods in mspec
            string pathToMSpec = Path.Combine(Path.GetDirectoryName(pathToAssembly), "Machine.Specifications.dll");

            if (File.Exists(pathToMSpec))
            {
                FileVersionInfo fileInfo = FileVersionInfo.GetVersionInfo(pathToMSpec);
                if (fileInfo.FileMinorPart > 5)
                {
                    canIndicateStartAndEnd = true;
                }
                else
                if (fileInfo.FileMinorPart == 5 && fileInfo.FileBuildPart >= 12)
                {
                    canIndicateStartAndEnd = true;
                }
            }
            try
            {
                assemblyToRun   = Assembly.LoadFrom(pathToAssembly);
                mspecRunner     = new DefaultRunner(specificationRunListener, RunOptions.Default);
                dynMSpeccRunner = mspecRunner;
                if (canIndicateStartAndEnd)
                {
                    dynMSpeccRunner.StartRun(assemblyToRun);
                }
                foreach (string spec in specsToRun)
                {
                    // get the spec type
                    string[] splits        = spec.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries);
                    string   specClassName = splits[0];
                    string   specFieldName = splits[1];
                    Type     specType      = assemblyToRun.GetType(specClassName);

                    // get the method info from the type
                    MemberInfo specField = specType.GetMembers(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public).Where(x => x.Name == specFieldName).SingleOrDefault();
                    mspecRunner.RunMember(assemblyToRun, specField);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (mspecRunner != null && assemblyToRun != null)
                {
                    if (canIndicateStartAndEnd)
                    {
                        dynMSpeccRunner.EndRun(assemblyToRun);
                    }
                    mspecRunner     = null;
                    dynMSpeccRunner = null;
                    assemblyToRun   = null;
                }
            }
        }
コード例 #7
0
        public override TaskResult Finish(TaskExecutionNode node)
        {
            _runner.RunMember(_contextAssembly, _contextClass);

            return(TaskResult.Success);
        }