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; } }
protected RemoteToInternalSpecificationRunListenerAdapter(object listener, string runOptionsXml) { this.listener = (IMessageSink)listener; RunOptions = RunOptions.Parse(runOptionsXml); Runner = new DefaultRunner(this, RunOptions); }
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); } } }
public override TaskResult Start(TaskExecutionNode node) { var task = (RunAssemblyTask)node.RemoteTask; _contextAssembly = LoadContextAssembly(task); if (_contextAssembly == null) { return(TaskResult.Error); } var result = VersionCompatibilityChecker.Check(_contextAssembly); if (!result.Success) { Server.TaskExplain(task, result.Explanation); Server.TaskError(task, result.ErrorMessage); return(TaskResult.Error); } _listener = new PerAssemblyRunListener(Server, task); _runner = new DefaultRunner(_listener, RunOptions.Default); _runScope = GetRunScope(_runner); return(TaskResult.Success); }
public void RunAllTestsInAssembly(string pathToAssembly, ISpecificationRunListener specificationRunListener) { Assembly assemblyToRun = Assembly.LoadFrom(pathToAssembly); DefaultRunner mspecRunner = new DefaultRunner(specificationRunListener, RunOptions.Default); mspecRunner.RunAssembly(assemblyToRun); }
public void RunAllTestsInAssembly(string pathToAssembly, ISpecificationRunListener specificationRunListener) { Assembly assemblyToRun = AssemblyHelper.Load(pathToAssembly); DefaultRunner mspecRunner = CreateRunner(assemblyToRun, specificationRunListener); mspecRunner.RunAssembly(assemblyToRun); }
public void Run() { var jobRunner = DefaultRunner.Create(output); var startTime = DateTime.Now; var build = jobRunner.Run(jobName); var duration = DateTime.Now.Subtract(startTime); output.WriteLine(string.Empty); output.WriteLine($"Result: {build.Result}"); output.WriteLine($"Duration: {duration}"); }
public void Run() { var jobRunner = DefaultRunner.Create(TestContext.Out); var startTime = DateTime.Now; var build = jobRunner.Run(jobName); var duration = DateTime.Now.Subtract(startTime); TestContext.Out.WriteLine(); TestContext.Out.WriteLine($"Result: {build.Result}"); TestContext.Out.WriteLine($"Duration: {duration}"); }
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); } } }
public void GetConsoleText() { var jobRunner = DefaultRunner.Create(output, quiet: true); output.WriteLine("Running job..."); var build = jobRunner.Run(jobName); output.WriteLine("Job complete."); Assert.Equal("SUCCESS", build.Result); Assert.True(jobRunner.BuildNumber.HasValue); var text = jobRunner.Client.Builds.GetConsoleText(jobName, jobRunner.BuildNumber.Value.ToString()); output.WriteLine(text); Assert.Contains("[Hello World!]", text); }
static RunScope GetRunScope(DefaultRunner runner) { var scope = new RunScope(); var runnerType = runner.GetType(); var startRun = runnerType.GetMethod("StartRun", new[] { typeof(Assembly) }); if (startRun != null) { scope.StartRun = asm => startRun.Invoke(runner, new object[] { asm }); } var endRun = runnerType.GetMethod("EndRun", new[] { typeof(Assembly) }); if (endRun != null) { scope.EndRun = asm => endRun.Invoke(runner, new object[] { asm }); } return(scope); }
public override TaskResult Start(TaskExecutionNode node) { var task = (ContextTask)node.RemoteTask; _contextAssembly = LoadContextAssembly(task); if (_contextAssembly == null) { return(TaskResult.Error); } var result = VersionCompatibilityChecker.Check(_contextAssembly); if (!result.Success) { Server.TaskExplain(task, result.Explanation); Server.TaskError(task, result.ErrorMessage); return(TaskResult.Error); } _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(TaskResult.Error); } _listener = new PerContextRunListener(Server, node.RemoteTask); _runner = new DefaultRunner(_listener, RunOptions.Default); return(TaskResult.Success); }
public void RunC() { var runner = new DefaultRunner("input/c_memorable_moments.txt", "../../../output/c_memorable_moments.out"); runner.Run(); }
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; } } }
public void RunB() { var runner = new DefaultRunner("input/b_lovely_landscapes.txt", "../../../output/b_lovely_landscapes.out"); runner.Run(); }
public void Run() { var runner = new DefaultRunner("input/e_shiny_selfies.txt", "../../../output/e_shiny_selfies.out"); runner.Run(); }
public void RunD() { var runner = new DefaultRunner("input/d_pet_pictures.txt", "../../../output/d_pet_pictures.out"); runner.Run(); }
public void RunA() { var runner = new DefaultRunner("input/a_example.txt", "../../../output/a_example.out"); runner.Run(); }
private Controller(Action <string> listenCallback, RunOptions runOptions) { listener = new ControllerRunListener(listenCallback); explorer = new AssemblyExplorer(); runner = new DefaultRunner(listener, runOptions, false); }
private Controller(Action <string> listenCallback, RunOptions runOptions) { _listener = new ControllerRunListener(listenCallback); _explorer = new AssemblyExplorer(); _runner = new DefaultRunner(_listener, runOptions, signalRunStartAndEnd: false); }