1919
2020namespace  RubberduckTests . Mocks 
2121{ 
22-     internal  class  TestParseCoordinator  :  ParseCoordinator 
23-     { 
24-         public  TestParseCoordinator ( 
25-             RubberduckParserState  state , 
26-             IParsingStageService  parsingStageService , 
27-             IParsingCacheService  parsingCacheService , 
28-             IProjectManager  projectManager , 
29-             IParserStateManager  parserStateManager )  :  base ( 
30-                 state ,  
31-                 parsingStageService ,  
32-                 parsingCacheService , 
33-                 projectManager ,  
34-                 parserStateManager ) 
35-         {  } 
36- 
37-         protected  override  void  BeginParse ( object  sender ) 
38-         { 
39-             ParseInternal ( CurrentCancellationTokenSource . Token ) ; 
40-         } 
41- 
42-         public  void  Parse ( object  sender ,  CancellationTokenSource  token ) 
43-         { 
44-             SetSavedCancellationTokenSource ( token ) ; 
45-             ParseInternal ( token . Token ) ; 
46-         } 
47- 
48-         /// <summary> 
49-         /// For the use of tests & reflection API only 
50-         /// </summary> 
51-         private  void  SetSavedCancellationTokenSource ( CancellationTokenSource  tokenSource ) 
52-         { 
53-             var  oldTokenSource  =  CurrentCancellationTokenSource ; 
54-             CurrentCancellationTokenSource  =  tokenSource ; 
55- 
56-             oldTokenSource ? . Cancel ( ) ; 
57-             oldTokenSource ? . Dispose ( ) ; 
58-         } 
59- 
60-         protected  void  ParseInternal ( CancellationToken  token ) 
61-         { 
62-             var  lockTaken  =  false ; 
63-             try 
64-             { 
65-                 if  ( ! ParsingSuspendLock . IsWriteLockHeld ) 
66-                 { 
67-                     ParsingSuspendLock . EnterReadLock ( ) ; 
68-                 } 
69-                 Monitor . Enter ( ParsingRunSyncObject ,  ref  lockTaken ) ; 
70-                 ParseAllInternal ( this ,  token ) ; 
71-             } 
72-             catch  ( OperationCanceledException ) 
73-             { 
74-                 //This is the point to which the cancellation should break. 
75-             } 
76-             finally 
77-             { 
78-                 if  ( lockTaken ) 
79-                 { 
80-                     Monitor . Exit ( ParsingRunSyncObject ) ; 
81-                 } 
82-                 if  ( ParsingSuspendLock . IsReadLockHeld ) 
83-                 { 
84-                     ParsingSuspendLock . ExitReadLock ( ) ; 
85-                 } 
86-             } 
87-         } 
88- 
89-     } 
90- 
9122    public  static class  MockParser 
9223    { 
9324        public  static RubberduckParserState  ParseString ( string  inputCode ,  out  QualifiedModuleName  qualifiedModuleName ) 
@@ -105,7 +36,7 @@ public static RubberduckParserState ParseString(string inputCode, out QualifiedM
10536            return  parser . State ; 
10637        } 
10738
108-         public  static ParseCoordinator  Create ( IVBE  vbe ,  string  serializedDeclarationsPath  =  null ) 
39+         public  static SynchronousParseCoordinator  Create ( IVBE  vbe ,  string  serializedDeclarationsPath  =  null ) 
10940        { 
11041            var  vbeEvents  =  MockVbeEvents . CreateMockVbeEvents ( new  Moq . Mock < IVBE > ( ) ) ; 
11142            var  declarationFinderFactory  =  new  DeclarationFinderFactory ( ) ; 
@@ -114,14 +45,14 @@ public static ParseCoordinator Create(IVBE vbe, string serializedDeclarationsPat
11445            return  Create ( vbe ,  state ,  projectRepository ,  serializedDeclarationsPath ) ; 
11546        } 
11647
117-         public  static ParseCoordinator  Create ( IVBE  vbe ,  RubberduckParserState  state ,  IProjectsRepository  projectRepository ,  string  serializedDeclarationsPath  =  null ) 
48+         public  static SynchronousParseCoordinator  Create ( IVBE  vbe ,  RubberduckParserState  state ,  IProjectsRepository  projectRepository ,  string  serializedDeclarationsPath  =  null ) 
11849        { 
11950            var  attributeParser  =  new  TestAttributeParser ( ( )  =>  new  VBAPreprocessor ( double . Parse ( vbe . Version ,  CultureInfo . InvariantCulture ) ) ,  state . ProjectsProvider ) ; 
12051            var  sourceCodeHandler  =  new  Mock < ISourceCodeHandler > ( ) . Object ; 
12152            return  Create ( vbe ,  state ,  attributeParser ,  sourceCodeHandler ,  projectRepository ,  serializedDeclarationsPath ) ; 
12253        } 
12354
124-         public  static ParseCoordinator  Create ( IVBE  vbe ,  RubberduckParserState  state ,  IAttributeParser  attributeParser ,  ISourceCodeHandler  sourceCodeHandler ,  IProjectsRepository  projectRepository ,  string  serializedDeclarationsPath  =  null ) 
55+         public  static SynchronousParseCoordinator  Create ( IVBE  vbe ,  RubberduckParserState  state ,  IAttributeParser  attributeParser ,  ISourceCodeHandler  sourceCodeHandler ,  IProjectsRepository  projectRepository ,  string  serializedDeclarationsPath  =  null ) 
12556        { 
12657            var  path  =  serializedDeclarationsPath  ?? 
12758                       Path . Combine ( Path . GetDirectoryName ( Assembly . GetAssembly ( typeof ( MockParser ) ) . Location ) ,  "TestFiles" ,  "Resolver" ) ; 
@@ -173,7 +104,7 @@ public static ParseCoordinator Create(IVBE vbe, RubberduckParserState state, IAt
173104                supertypeClearer 
174105                ) ; 
175106
176-             return  new  TestParseCoordinator ( 
107+             return  new  SynchronousParseCoordinator ( 
177108                state , 
178109                parsingStageService , 
179110                parsingCacheService , 
@@ -200,7 +131,7 @@ public static RubberduckParserState CreateAndParse(IVBE vbe, string serializedDe
200131            return  parser . State ; 
201132        } 
202133
203-         private  static ParseCoordinator  CreateWithLibraries ( IVBE  vbe ,  string  serializedDeclarationsPath  =  null ,  IEnumerable < string >  testLibraries  =  null ) 
134+         private  static SynchronousParseCoordinator  CreateWithLibraries ( IVBE  vbe ,  string  serializedDeclarationsPath  =  null ,  IEnumerable < string >  testLibraries  =  null ) 
204135        { 
205136            var  parser  =  Create ( vbe ,  serializedDeclarationsPath ) ; 
206137            if  ( testLibraries  !=  null ) 
0 commit comments