1
+ using System . Collections . Generic ;
2
+ using Moq ;
3
+ using NUnit . Framework ;
4
+ using Rubberduck . Inspections . Results ;
5
+ using Rubberduck . Parsing ;
6
+ using Rubberduck . Parsing . Annotations ;
7
+ using Rubberduck . Parsing . Inspections . Abstract ;
8
+ using Rubberduck . Parsing . Symbols ;
9
+ using Rubberduck . Parsing . VBA ;
10
+ using Rubberduck . Parsing . VBA . DeclarationCaching ;
11
+ using Rubberduck . UI . Inspections ;
12
+ using Rubberduck . VBEditor ;
13
+
14
+ namespace RubberduckTests . Inspections
15
+ {
16
+ [ TestFixture ]
17
+ public class InspectionResultTests
18
+ {
19
+ [ Test ]
20
+ public void InspectionResultsAreDeemedInvalidatedIfTheModuleWithTheirQualifiedModuleNameHasBeenModified ( )
21
+ {
22
+ var inspectionMock = new Mock < IInspection > ( ) ;
23
+ inspectionMock
24
+ . Setup ( m =>
25
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
26
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
27
+ . Returns ( false ) ;
28
+
29
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
30
+ var context = new QualifiedContext ( module , null ) ;
31
+ var modifiedModules = new HashSet < QualifiedModuleName > { module } ;
32
+
33
+ var inspectionResult = new QualifiedContextInspectionResult ( inspectionMock . Object , string . Empty , context ) ;
34
+
35
+ Assert . IsTrue ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
36
+ }
37
+
38
+ [ Test ]
39
+ public void InspectionResultsAreDeemedInvalidatedIfTheInspectionDeemsThemInvalidated ( )
40
+ {
41
+ var inspectionMock = new Mock < IInspection > ( ) ;
42
+ inspectionMock
43
+ . Setup ( m =>
44
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
45
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
46
+ . Returns ( true ) ;
47
+
48
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
49
+ var context = new QualifiedContext ( module , null ) ;
50
+ var modifiedModules = new HashSet < QualifiedModuleName > ( ) ;
51
+
52
+ var inspectionResult = new QualifiedContextInspectionResult ( inspectionMock . Object , string . Empty , context ) ;
53
+
54
+ Assert . IsTrue ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
55
+ }
56
+
57
+ [ Test ]
58
+ public void QualifiedContextInspectionResultsAreNotDeemedInvalidatedIfNeitherTheInspectionDeemsThemInvalidatedNorTheirQualifiedModuleNameGetsModified ( )
59
+ {
60
+ var inspectionMock = new Mock < IInspection > ( ) ;
61
+ inspectionMock
62
+ . Setup ( m =>
63
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
64
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
65
+ . Returns ( false ) ;
66
+
67
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
68
+ var otherModule = new QualifiedModuleName ( "project" , string . Empty , "otherModule" ) ;
69
+ var context = new QualifiedContext ( module , null ) ;
70
+ var modifiedModules = new HashSet < QualifiedModuleName > { otherModule } ;
71
+
72
+ var inspectionResult = new QualifiedContextInspectionResult ( inspectionMock . Object , string . Empty , context ) ;
73
+
74
+ Assert . IsFalse ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
75
+ }
76
+
77
+ [ Test ]
78
+ public void DeclarationInspectionResultsAreDeemedInvalidatedIfTheirTargetsModuleGetsModified ( )
79
+ {
80
+ var inspectionMock = new Mock < IInspection > ( ) ;
81
+ inspectionMock
82
+ . Setup ( m =>
83
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
84
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
85
+ . Returns ( false ) ;
86
+
87
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
88
+ var declarationModule = new QualifiedModuleName ( "project" , string . Empty , "declarationModule" ) ;
89
+ var declarationMemberName = new QualifiedMemberName ( declarationModule , "test" ) ;
90
+ var context = new QualifiedContext ( module , null ) ;
91
+ var declaration = new Declaration ( declarationMemberName , null , string . Empty , string . Empty , string . Empty , false , false ,
92
+ Accessibility . Public , DeclarationType . Constant , null , null , default , false , null ) ;
93
+ var modifiedModules = new HashSet < QualifiedModuleName > { declarationModule } ;
94
+
95
+ var inspectionResult = new DeclarationInspectionResult ( inspectionMock . Object , string . Empty , declaration , context ) ;
96
+
97
+ Assert . IsTrue ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
98
+ }
99
+
100
+ [ Test ]
101
+ public void DeclarationInspectionResultsAreNotDeemedInvalidatedIfNeitherTheInspectionDeemsThemInvalidatedNorTheirModuleNorThatOfTheTargetGetModified ( )
102
+ {
103
+ var inspectionMock = new Mock < IInspection > ( ) ;
104
+ inspectionMock
105
+ . Setup ( m =>
106
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
107
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
108
+ . Returns ( false ) ;
109
+
110
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
111
+ var declarationModule = new QualifiedModuleName ( "project" , string . Empty , "declarationModule" ) ;
112
+ var otherModule = new QualifiedModuleName ( "project" , string . Empty , "otherModule" ) ;
113
+ var declarationMemberName = new QualifiedMemberName ( declarationModule , "test" ) ;
114
+ var context = new QualifiedContext ( module , null ) ;
115
+ var declaration = new Declaration ( declarationMemberName , null , string . Empty , string . Empty , string . Empty , false , false ,
116
+ Accessibility . Public , DeclarationType . Constant , null , null , default , false , null ) ;
117
+ var modifiedModules = new HashSet < QualifiedModuleName > { otherModule } ;
118
+
119
+ var inspectionResult = new DeclarationInspectionResult ( inspectionMock . Object , string . Empty , declaration , context ) ;
120
+
121
+ Assert . IsFalse ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
122
+ }
123
+
124
+ [ Test ]
125
+ public void IdentifierRefereneceInspectionResultsAreDeemedInvalidatedIfTheModuleOfTheirReferencedDeclarationGetsModified ( )
126
+ {
127
+ var inspectionMock = new Mock < IInspection > ( ) ;
128
+ inspectionMock
129
+ . Setup ( m =>
130
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
131
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
132
+ . Returns ( false ) ;
133
+
134
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
135
+ var declarationModule = new QualifiedModuleName ( "project" , string . Empty , "declarationModule" ) ;
136
+ var declarationMemberName = new QualifiedMemberName ( declarationModule , "test" ) ;
137
+ var declaration = new Declaration ( declarationMemberName , null , string . Empty , string . Empty , string . Empty , false , false ,
138
+ Accessibility . Public , DeclarationType . Constant , null , null , default , false , null ) ;
139
+ var identifierReference = new IdentifierReference ( module , null , null , "test" , default , null , declaration ) ;
140
+ var modifiedModules = new HashSet < QualifiedModuleName > { declarationModule } ;
141
+
142
+ var declarationFinderProviderMock = new Mock < IDeclarationFinderProvider > ( ) ;
143
+ var declaratioFinder = new DeclarationFinder ( new List < Declaration > ( ) , new List < IAnnotation > ( ) ,
144
+ new List < UnboundMemberDeclaration > ( ) ) ;
145
+ declarationFinderProviderMock . SetupGet ( m => m . DeclarationFinder ) . Returns ( declaratioFinder ) ;
146
+ var inspectionResult = new IdentifierReferenceInspectionResult ( inspectionMock . Object , string . Empty , declarationFinderProviderMock . Object , identifierReference ) ;
147
+
148
+ Assert . IsTrue ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
149
+ }
150
+
151
+ [ Test ]
152
+ public void IdentifierReferenceInspectionResultsAreNotDeemedInvalidatedIfNeitherTheInspectionDeemsThemInvalidatedNorTheirModuleNorThatOfTheReferencedDeclarationGetModified ( )
153
+ {
154
+ var inspectionMock = new Mock < IInspection > ( ) ;
155
+ inspectionMock
156
+ . Setup ( m =>
157
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
158
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
159
+ . Returns ( false ) ;
160
+
161
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
162
+ var declarationModule = new QualifiedModuleName ( "project" , string . Empty , "declarationModule" ) ;
163
+ var otherModule = new QualifiedModuleName ( "project" , string . Empty , "otherModule" ) ;
164
+ var declarationMemberName = new QualifiedMemberName ( declarationModule , "test" ) ;
165
+ var declaration = new Declaration ( declarationMemberName , null , string . Empty , string . Empty , string . Empty , false , false ,
166
+ Accessibility . Public , DeclarationType . Constant , null , null , default , false , null ) ;
167
+
168
+ var identifierReference = new IdentifierReference ( module , null , null , "test" , default , null , declaration ) ;
169
+ var modifiedModules = new HashSet < QualifiedModuleName > { otherModule } ;
170
+
171
+ var declarationFinderProviderMock = new Mock < IDeclarationFinderProvider > ( ) ;
172
+ var declaratioFinder = new DeclarationFinder ( new List < Declaration > ( ) , new List < IAnnotation > ( ) ,
173
+ new List < UnboundMemberDeclaration > ( ) ) ;
174
+ declarationFinderProviderMock . SetupGet ( m => m . DeclarationFinder ) . Returns ( declaratioFinder ) ;
175
+ var inspectionResult = new IdentifierReferenceInspectionResult ( inspectionMock . Object , string . Empty , declarationFinderProviderMock . Object , identifierReference ) ;
176
+
177
+ Assert . IsFalse ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
178
+ }
179
+
180
+ [ Test ]
181
+ public void AggregateInspectionResultsAreAlwaysDeemedInvalidated ( )
182
+ {
183
+ var inspectionMock = new Mock < IInspection > ( ) ;
184
+ inspectionMock
185
+ . Setup ( m =>
186
+ m . ChangesInvalidateResult ( It . IsAny < IInspectionResult > ( ) ,
187
+ It . IsAny < ICollection < QualifiedModuleName > > ( ) ) )
188
+ . Returns ( false ) ;
189
+
190
+ var module = new QualifiedModuleName ( "project" , string . Empty , "module" ) ;
191
+ var otherModule = new QualifiedModuleName ( "project" , string . Empty , "otherModule" ) ;
192
+ var context = new QualifiedContext ( module , null ) ;
193
+ var modifiedModules = new HashSet < QualifiedModuleName > { otherModule } ;
194
+
195
+ var baseInspectionResult = new QualifiedContextInspectionResult ( inspectionMock . Object , string . Empty , context ) ;
196
+ var inspectionResult = new AggregateInspectionResult ( baseInspectionResult , 42 ) ;
197
+
198
+ Assert . IsTrue ( inspectionResult . ChangesInvalidateResult ( modifiedModules ) ) ;
199
+ }
200
+ }
201
+ }
0 commit comments