1+ using  System . Linq ; 
2+ using  System . Threading ; 
3+ using  Microsoft . VisualStudio . TestTools . UnitTesting ; 
4+ using  Rubberduck . Inspections . Concrete ; 
5+ using  Rubberduck . Inspections . QuickFixes ; 
6+ using  Rubberduck . Parsing . Grammar ; 
7+ using  Rubberduck . VBEditor . SafeComWrappers ; 
8+ using  Rubberduck . VBEditor . SafeComWrappers . Abstract ; 
9+ using  RubberduckTests . Mocks ; 
10+ 
11+ namespace  RubberduckTests . Inspections 
12+ { 
13+     [ TestClass ] 
14+     public  class  SynchronizeAttributesQuickFixTests 
15+     { 
16+         [ TestMethod ] 
17+         public  void  AddsMissingPredeclaredIdAttribute ( ) 
18+         { 
19+             const  string  testModuleName  =  "Test" ; 
20+             const  string  inputCode  =  @" 
21+ VERSION 1.0 CLASS 
22+ BEGIN 
23+   MultiUse = -1  'True 
24+ END 
25+ Attribute VB_Name = """  +  testModuleName  +  @""" 
26+ Attribute VB_GlobalNameSpace = False 
27+ Attribute VB_Creatable = False 
28+ Attribute VB_PredeclaredId = False 
29+ Attribute VB_Exposed = False 
30+ Option Explicit 
31+ '@PredeclaredId 
32+ " ; 
33+             const  string  expectedCode  =  @" 
34+ VERSION 1.0 CLASS 
35+ BEGIN 
36+   MultiUse = -1  'True 
37+ END 
38+ Attribute VB_Name = """  +  testModuleName  +  @""" 
39+ Attribute VB_GlobalNameSpace = False 
40+ Attribute VB_Creatable = False 
41+ Attribute VB_PredeclaredId = True 
42+ Attribute VB_Exposed = False 
43+ Option Explicit 
44+ '@PredeclaredId 
45+ " ; 
46+ 
47+             IVBComponent  component ; 
48+             var  vbe  =  MockVbeBuilder . BuildFromSingleModule ( inputCode ,  testModuleName ,  ComponentType . ClassModule ,  out  component ) ; 
49+ 
50+             var  state  =  MockParser . CreateAndParse ( vbe . Object ) ; 
51+             var  inspection  =  new  MissingAttributeInspection ( state ) ; 
52+             var  inspector  =  InspectionsHelper . GetInspector ( inspection ) ; 
53+             var  result  =  inspector . FindIssuesAsync ( state ,  CancellationToken . None ) . Result ? . SingleOrDefault ( ) ; 
54+             if ( result ? . Context . GetType ( )  !=  typeof ( VBAParser . AnnotationContext ) ) 
55+             { 
56+                 Assert . Inconclusive ( "Inspection failed to return a result." ) ; 
57+             } 
58+ 
59+             var  fix  =  new  SynchronizeAttributesQuickFix ( state ) ; 
60+             fix . Fix ( result ) ; 
61+ 
62+             var  rewriter  =  state . GetAttributeRewriter ( result . QualifiedSelection . QualifiedName ) ; 
63+             var  actual  =  rewriter . GetText ( ) ; 
64+ 
65+             Assert . AreEqual ( expectedCode ,  actual ) ; 
66+         } 
67+     } 
68+ } 
0 commit comments