@@ -177,6 +177,77 @@ public void TestCoverageMergeWithWrongParameter()
177
177
178
178
directory . Delete ( true ) ;
179
179
}
180
+
181
+ [ Fact ]
182
+ public void TestCoverageUnloadWithParameters ( )
183
+ {
184
+ string module = GetType ( ) . Assembly . Location ;
185
+ string pdb = Path . Combine ( Path . GetDirectoryName ( module ) , Path . GetFileNameWithoutExtension ( module ) + ".pdb" ) ;
186
+
187
+ DirectoryInfo directory = Directory . CreateDirectory ( Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ) ;
188
+
189
+ File . Copy ( module , Path . Combine ( directory . FullName , Path . GetFileName ( module ) ) , true ) ;
190
+ File . Copy ( pdb , Path . Combine ( directory . FullName , Path . GetFileName ( pdb ) ) , true ) ;
191
+
192
+ var mockInstrumentationHelper = new Mock < IInstrumentationHelper > ( ) ;
193
+
194
+ var parameters = new CoverageParameters
195
+ {
196
+ IncludeFilters = new string [ ] { "[coverlet.tests.projectsample.excludedbyattribute*]*" } ,
197
+ IncludeDirectories = Array . Empty < string > ( ) ,
198
+ ExcludeFilters = Array . Empty < string > ( ) ,
199
+ ExcludedSourceFiles = Array . Empty < string > ( ) ,
200
+ ExcludeAttributes = Array . Empty < string > ( ) ,
201
+ IncludeTestAssembly = false ,
202
+ SingleHit = false ,
203
+ MergeWith = string . Empty ,
204
+ UseSourceLink = false
205
+ } ;
206
+
207
+ var coverage = new Coverage ( Path . Combine ( directory . FullName , Path . GetFileName ( module ) ) , parameters , _mockLogger . Object , mockInstrumentationHelper . Object , new FileSystem ( ) , new SourceRootTranslator ( _mockLogger . Object , new FileSystem ( ) ) , new CecilSymbolHelper ( ) ) ;
208
+ coverage . PrepareModules ( ) ;
209
+ coverage . UnloadModule ( Path . Combine ( directory . FullName , Path . GetFileName ( module ) ) ) ;
210
+
211
+ mockInstrumentationHelper . Verify ( i => i . RestoreOriginalModule ( It . Is < string > ( v => v . Equals ( Path . Combine ( directory . FullName , Path . GetFileName ( module ) ) ) ) , It . IsAny < string > ( ) ) , Times . Once ) ;
212
+ _mockLogger . Verify ( l => l . LogVerbose ( It . Is < string > ( v => v . Equals ( $ "Module at { Path . Combine ( directory . FullName , Path . GetFileName ( module ) ) } is unloaded.") ) ) , Times . Once ) ;
213
+ }
214
+
215
+ [ Fact ]
216
+ public void TestCoverageUnloadWithNoParameters ( )
217
+ {
218
+ string module = GetType ( ) . Assembly . Location ;
219
+ string pdb = Path . Combine ( Path . GetDirectoryName ( module ) , Path . GetFileNameWithoutExtension ( module ) + ".pdb" ) ;
220
+
221
+ DirectoryInfo directory = Directory . CreateDirectory ( Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ) ;
222
+
223
+ File . Copy ( module , Path . Combine ( directory . FullName , Path . GetFileName ( module ) ) , true ) ;
224
+ File . Copy ( pdb , Path . Combine ( directory . FullName , Path . GetFileName ( pdb ) ) , true ) ;
225
+
226
+ var mockInstrumentationHelper = new Mock < IInstrumentationHelper > ( ) ;
227
+ mockInstrumentationHelper
228
+ . Setup ( x => x . SelectModules ( It . IsAny < IEnumerable < string > > ( ) , It . IsAny < string [ ] > ( ) , It . IsAny < string [ ] > ( ) ) )
229
+ . Returns ( new List < string > ( ) { "ModuleX" } ) ;
230
+
231
+ var parameters = new CoverageParameters
232
+ {
233
+ IncludeFilters = new string [ ] { "[coverlet.tests.projectsample.excludedbyattribute*]*" } ,
234
+ IncludeDirectories = Array . Empty < string > ( ) ,
235
+ ExcludeFilters = Array . Empty < string > ( ) ,
236
+ ExcludedSourceFiles = Array . Empty < string > ( ) ,
237
+ ExcludeAttributes = Array . Empty < string > ( ) ,
238
+ IncludeTestAssembly = false ,
239
+ SingleHit = false ,
240
+ MergeWith = string . Empty ,
241
+ UseSourceLink = false
242
+ } ;
243
+
244
+ var coverage = new Coverage ( Path . Combine ( directory . FullName , Path . GetFileName ( module ) ) , parameters , _mockLogger . Object , mockInstrumentationHelper . Object , new FileSystem ( ) , new SourceRootTranslator ( _mockLogger . Object , new FileSystem ( ) ) , new CecilSymbolHelper ( ) ) ;
245
+ coverage . PrepareModules ( ) ;
246
+ coverage . UnloadModules ( ) ;
247
+
248
+ mockInstrumentationHelper . Verify ( i => i . RestoreOriginalModule ( It . Is < string > ( v => v . Equals ( "ModuleX" ) ) , It . IsAny < string > ( ) ) , Times . Once ) ;
249
+ _mockLogger . Verify ( l => l . LogVerbose ( It . Is < string > ( v => v . Equals ( "All Modules unloaded." ) ) ) , Times . Once ) ;
250
+ }
180
251
}
181
252
}
182
253
0 commit comments