1
+ using NUnit . Framework ;
2
+ using Rubberduck . Inspections . Concrete ;
3
+ using Rubberduck . Inspections . QuickFixes ;
4
+ using Rubberduck . Parsing . Inspections . Abstract ;
5
+ using Rubberduck . Parsing . VBA ;
6
+ using Rubberduck . Parsing . VBA . Parsing ;
7
+
8
+ namespace RubberduckTests . QuickFixes
9
+ {
10
+ [ TestFixture ]
11
+ public class RemoveAttributeQuickFixTests : QuickFixTestBase
12
+ {
13
+ [ Test ]
14
+ [ Category ( "QuickFixes" ) ]
15
+ public void ModuleAttributeWithoutAnnotation_QuickFixWorks ( )
16
+ {
17
+ const string inputCode =
18
+ @"Attribute VB_Description = ""Desc""
19
+ Public Sub Foo()
20
+ Const const1 As Integer = 9
21
+ End Sub" ;
22
+
23
+ const string expectedCode =
24
+ @"Public Sub Foo()
25
+ Const const1 As Integer = 9
26
+ End Sub" ;
27
+
28
+ var actualCode = ApplyQuickFixToFirstInspectionResult ( inputCode , state => new MissingModuleAnnotationInspection ( state ) , CodeKind . AttributesCode ) ;
29
+ Assert . AreEqual ( expectedCode , actualCode ) ;
30
+ }
31
+
32
+ [ Test ]
33
+ [ Category ( "QuickFixes" ) ]
34
+ public void VbExtKeyModuleAttributeWithoutAnnotationForOneKey_QuickFixWorks ( )
35
+ {
36
+ const string inputCode =
37
+ @"Attribute VB_Ext_Key = ""Key"", ""NotValue""
38
+ Attribute VB_Ext_Key = ""OtherKey"", ""OtherValue""
39
+ '@ModuleAttribute VB_Ext_Key, ""Key"", ""Value""
40
+ Public Sub Foo()
41
+ Const const1 As Integer = 9
42
+ End Sub" ;
43
+
44
+ const string expectedCode =
45
+ @"Attribute VB_Ext_Key = ""Key"", ""NotValue""
46
+ '@ModuleAttribute VB_Ext_Key, ""Key"", ""Value""
47
+ Public Sub Foo()
48
+ Const const1 As Integer = 9
49
+ End Sub" ;
50
+
51
+ var actualCode = ApplyQuickFixToFirstInspectionResult ( inputCode , state => new MissingModuleAnnotationInspection ( state ) , CodeKind . AttributesCode ) ;
52
+ Assert . AreEqual ( expectedCode , actualCode ) ;
53
+ }
54
+
55
+ [ Test ]
56
+ [ Category ( "QuickFixes" ) ]
57
+ public void MemberAttributeWithoutAnnotation_QuickFixWorks ( )
58
+ {
59
+ const string inputCode =
60
+ @"
61
+ Public Sub Foo()
62
+ Attribute Foo.VB_Description = ""NotDesc""
63
+ Const const1 As Integer = 9
64
+ End Sub" ;
65
+
66
+ const string expectedCode =
67
+ @"
68
+ Public Sub Foo()
69
+ Const const1 As Integer = 9
70
+ End Sub" ;
71
+
72
+ var actualCode = ApplyQuickFixToFirstInspectionResult ( inputCode , state => new MissingMemberAnnotationInspection ( state ) , CodeKind . AttributesCode ) ;
73
+ Assert . AreEqual ( expectedCode , actualCode ) ;
74
+ }
75
+
76
+ [ Test ]
77
+ [ Category ( "QuickFixes" ) ]
78
+ public void VbExtKeyMemberAttributeWithoutAnnotationForOneKey_QuickFixWorks ( )
79
+ {
80
+ const string inputCode =
81
+ @"'@MemberAttribute VB_Ext_Key, ""Key"", ""Value""
82
+ Public Sub Foo()
83
+ Attribute Foo.VB_Ext_Key = ""Key"", ""NotValue""
84
+ Attribute Foo.VB_Ext_Key = ""OtherKey"", ""OtherValue""
85
+ Const const1 As Integer = 9
86
+ End Sub" ;
87
+
88
+ const string expectedCode =
89
+ @"'@MemberAttribute VB_Ext_Key, ""Key"", ""Value""
90
+ Public Sub Foo()
91
+ Attribute Foo.VB_Ext_Key = ""Key"", ""NotValue""
92
+ Const const1 As Integer = 9
93
+ End Sub" ;
94
+
95
+ var actualCode = ApplyQuickFixToFirstInspectionResult ( inputCode , state => new MissingMemberAnnotationInspection ( state ) , CodeKind . AttributesCode ) ;
96
+ Assert . AreEqual ( expectedCode , actualCode ) ;
97
+ }
98
+
99
+ protected override IQuickFix QuickFix ( RubberduckParserState state )
100
+ {
101
+ return new RemoveAttributeQuickFix ( new AttributesUpdater ( state ) ) ;
102
+ }
103
+ }
104
+ }
0 commit comments