22using Machine . Specifications . Runner . Impl ;
33using System ;
44using System . Collections . Generic ;
5- using System . Diagnostics ;
6- using System . IO ;
75using System . Linq ;
86using System . Reflection ;
9- using Machine . Specifications . Explorers ;
10- using Machine . Specifications . Model ;
117using Machine . Specifications ;
128using Machine . VSTestAdapter . Helpers ;
139
@@ -48,7 +44,6 @@ private DefaultRunner CreateRunner(Assembly assembly,ISpecificationRunListener s
4844 return new DefaultRunner ( listener , RunOptions . Default ) ;
4945 }
5046
51-
5247 public void RunTestsInAssembly ( string pathToAssembly , IEnumerable < VisualStudioTestIdentifier > specsToRun , ISpecificationRunListener specificationRunListener )
5348 {
5449 DefaultRunner mspecRunner = null ;
@@ -59,34 +54,19 @@ public void RunTestsInAssembly(string pathToAssembly, IEnumerable<VisualStudioTe
5954 assemblyToRun = AssemblyHelper . Load ( pathToAssembly ) ;
6055 mspecRunner = CreateRunner ( assemblyToRun , specificationRunListener ) ;
6156
62- IEnumerable < Context > specificationContexts = new AssemblyExplorer ( ) . FindContextsIn ( assemblyToRun ) ?? Enumerable . Empty < Context > ( ) ;
63- Dictionary < string , Context > contextMap = specificationContexts . ToDictionary ( c => c . Type . FullName , StringComparer . Ordinal ) ;
57+ var specsByContext = specsToRun . GroupBy ( x => x . ContainerTypeFullName ) ;
6458
65- // We use explicit assembly start and end to wrap the RunMember loop
6659 mspecRunner . StartRun ( assemblyToRun ) ;
6760
68- foreach ( VisualStudioTestIdentifier test in specsToRun )
61+ foreach ( var specs in specsByContext )
6962 {
70- Context context = contextMap [ test . ContainerTypeFullName ] ;
71- if ( context == null )
72- continue ;
73-
74- Specification specification = context . Specifications . SingleOrDefault ( spec => spec . FieldInfo . Name . Equals ( test . FieldName , StringComparison . Ordinal ) ) ;
75-
76- if ( specification is BehaviorSpecification )
77- {
78- // MSpec doesn't expose any way to run an an "It" coming from a "[Behavior]", so we have to do some trickery
79- VisualStudioTestIdentifier listenFor = specification . ToVisualStudioTestIdentifier ( context ) ;
80- DefaultRunner behaviorRunner = new DefaultRunner ( new SingleBehaviorTestRunListenerWrapper ( specificationRunListener , listenFor ) , RunOptions . Default ) ;
81- behaviorRunner . RunMember ( assemblyToRun , context . Type . GetTypeInfo ( ) ) ;
82- }
83- else
84- {
85- mspecRunner . RunMember ( assemblyToRun , specification . FieldInfo ) ;
86- }
63+ var fields = specs . Select ( x => x . FieldName ) ;
8764
65+ mspecRunner . RunType ( assemblyToRun , assemblyToRun . GetType ( specs . Key ) , fields . ToArray ( ) ) ;
8866 }
89- } catch ( Exception e ) {
67+ }
68+ catch ( Exception e )
69+ {
9070 specificationRunListener . OnFatalError ( new ExceptionResult ( e ) ) ;
9171 }
9272 finally
0 commit comments