public void Run(Assembly assembly, IEnumerable <Context> contexts) { var hasExecutableSpecifications = false; try { hasExecutableSpecifications = contexts.Any(x => x.HasExecutableSpecifications); var explorer = new AssemblyExplorer(); var globalCleanups = explorer.FindAssemblyWideContextCleanupsIn(assembly).ToList(); var specificationSupplements = explorer.FindSpecificationSupplementsIn(assembly).ToList(); if (hasExecutableSpecifications) { _assemblyStart(assembly); } foreach (var context in contexts) { RunContext(context, globalCleanups, specificationSupplements); } } catch (Exception err) { _listener.OnFatalError(new ExceptionResult(err)); } finally { if (hasExecutableSpecifications) { _assemblyEnd(assembly); } } }
public void Run(Assembly assembly, IEnumerable <Context> contexts) { bool hasExecutableSpecifications = contexts.Where(x => x.HasExecutableSpecifications).Any(); var explorer = new AssemblyExplorer(); var assemblyContexts = new List <IAssemblyContext>(explorer.FindAssemblyContextsIn(assembly)); var globalCleanups = new List <ICleanupAfterEveryContextInAssembly>(explorer.FindAssemblyWideContextCleanupsIn(assembly)); var specificationSupplements = new List <ISupplementSpecificationResults>(explorer.FindSpecificationSupplementsIn(assembly)); _listener.OnAssemblyStart(assembly.GetInfo()); var executedAssemblyContexts = new List <IAssemblyContext>(); try { if (hasExecutableSpecifications) { assemblyContexts.ForEach(assemblyContext => { assemblyContext.OnAssemblyStart(); executedAssemblyContexts.Add(assemblyContext); }); } foreach (var context in contexts) { RunContext(context, globalCleanups, specificationSupplements); } } catch (Exception err) { _listener.OnFatalError(new ExceptionResult(err)); } finally { if (hasExecutableSpecifications) { try { executedAssemblyContexts.Reverse(); executedAssemblyContexts.ForEach(assemblyContext => assemblyContext.OnAssemblyComplete()); } catch (Exception err) { _listener.OnFatalError(new ExceptionResult(err)); throw; } } } _listener.OnAssemblyEnd(assembly.GetInfo()); }
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 AssemblyRunner(ISpecificationRunListener listener, Assembly assembly, RunOptions options) { try { var runner = new DefaultRunner(listener, options); runner.RunAssembly(assembly); } catch (Exception err) { listener.OnFatalError(new ExceptionResult(err)); } }
public NamespaceRunner(ISpecificationRunListener listener, Assembly assembly, RunOptions options, string targetNamespace) { try { var runner = new DefaultRunner(listener, options); runner.RunNamespace(assembly, targetNamespace); } catch (Exception err) { listener.OnFatalError(new ExceptionResult(err)); } }
public MemberRunner(ISpecificationRunListener listener, Assembly assembly, RunOptions options, MemberInfo memberInfo) { try { var runner = new DefaultRunner(listener, options); runner.RunMember(assembly, memberInfo); } catch (Exception err) { listener.OnFatalError(new ExceptionResult(err)); } }
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); } } }
private void OnListenEvent(string value) { using (var stringReader = new StringReader(value)) { XDocument doc = XDocument.Load(stringReader); XElement element = doc.XPathSelectElement("/listener/*"); switch (element.Name.ToString()) { case "onassemblystart": _runListener.OnAssemblyStart(AssemblyInfo.Parse(element.XPathSelectElement("//onassemblystart/*").ToString())); break; case "onassemblyend": _runListener.OnAssemblyEnd(AssemblyInfo.Parse(element.XPathSelectElement("//onassemblyend/*").ToString())); break; case "onrunstart": _runListener.OnRunStart(); break; case "onrunend": _runListener.OnRunEnd(); break; case "oncontextstart": _runListener.OnContextStart(ContextInfo.Parse(element.XPathSelectElement("//oncontextstart/*").ToString())); break; case "oncontextend": _runListener.OnContextEnd(ContextInfo.Parse(element.XPathSelectElement("//oncontextend/*").ToString())); break; case "onspecificationstart": _runListener.OnSpecificationStart(SpecificationInfo.Parse(element.XPathSelectElement("//onspecificationstart/*").ToString())); break; case "onspecificationend": _runListener.OnSpecificationEnd( SpecificationInfo.Parse(element.XPathSelectElement("//onspecificationend/specificationinfo").ToString()), Result.Parse(element.XPathSelectElement("//onspecificationend/result").ToString())); break; case "onfatalerror": _runListener.OnFatalError(ExceptionResult.Parse(element.XPathSelectElement("//onfatalerror/*").ToString())); break; } } }
public void RunTestsInAssembly(string pathToAssembly, IEnumerable<VisualStudioTestIdentifier> specsToRun, ISpecificationRunListener specificationRunListener) { DefaultRunner mspecRunner = null; Assembly assemblyToRun = null; try { assemblyToRun = Assembly.LoadFrom(pathToAssembly); mspecRunner = new DefaultRunner(specificationRunListener, RunOptions.Default); 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); } else { mspecRunner.RunMember(assemblyToRun, specification.FieldInfo); } } } catch (Exception e) { specificationRunListener.OnFatalError(new ExceptionResult(e)); } finally { if (mspecRunner != null && assemblyToRun != null) mspecRunner.EndRun(assemblyToRun); } }
public static void Run(this ISpecificationRunListener adapter, AssemblyInfo assemblyInfo, SpecificationInfo specificationInfo, Result failure, ExceptionResult exceptionResult, ContextInfo contexInfo) { adapter.OnAssemblyStart(assemblyInfo); adapter.OnAssemblyEnd(assemblyInfo); adapter.OnSpecificationStart(specificationInfo); adapter.OnSpecificationEnd(specificationInfo, failure); adapter.OnFatalError(exceptionResult); adapter.OnContextStart(contexInfo); adapter.OnContextEnd(contexInfo); adapter.OnRunStart(); adapter.OnRunEnd(); }
public IEnumerable <Result> Run( Context context, ISpecificationRunListener listener, RunOptions options, IEnumerable <ICleanupAfterEveryContextInAssembly> globalCleanups, IEnumerable <ISupplementSpecificationResults> resultSupplementers) { listener.OnContextStart(context.GetInfo()); var result = Result.Pass(); if (context.HasExecutableSpecifications) { result = context.EstablishContext(); } var results = result.Passed ? RunSpecifications(context, listener, options, resultSupplementers) : FailSpecifications(context, listener, result, resultSupplementers); if (context.HasExecutableSpecifications) { var cleanupResult = context.Cleanup(); if (!cleanupResult.Passed) { listener.OnFatalError(cleanupResult.Exception); } foreach (var cleanup in globalCleanups) { cleanup.AfterContextCleanup(); } } listener.OnContextEnd(context.GetInfo()); return(results); }
public IEnumerable<Result> Run(Context context, ISpecificationRunListener listener, RunOptions options, IEnumerable<ICleanupAfterEveryContextInAssembly> globalCleanups, IEnumerable<ISupplementSpecificationResults> resultSupplementers) { IEnumerable<Result> results; listener.OnContextStart(context.GetInfo()); Result result = Result.Pass(); if (context.HasExecutableSpecifications) { result = context.EstablishContext(); } if (result.Passed) { results = RunSpecifications(context, listener, options, resultSupplementers); } else { results = FailSpecifications(context, listener, options, result, resultSupplementers); } if (context.HasExecutableSpecifications) { var cleanupResult = context.Cleanup(); if (!cleanupResult.Passed) { listener.OnFatalError(cleanupResult.Exception); } foreach (var cleanup in globalCleanups) { cleanup.AfterContextCleanup(); } } listener.OnContextEnd(context.GetInfo()); return results; }
public void OnFatalError(ExceptionResult exception) { runListener.OnFatalError(exception); }
public virtual void OnFatalError(ExceptionResult exceptionResult) { _runListener.OnFatalError(exceptionResult); }
public void OnFatalError(Specifications.ExceptionResult exception) { listener.OnFatalError(GetExceptionResult(exception)); }
public override void OnFatalError(ExceptionResult exception) { _listener.OnFatalError(exception); }