@@ -190,7 +190,7 @@ public async Task InstallPackageFromFeedUsingCustomNuGetConfig()
190190 // Assert
191191 Assert . NotEmpty ( plugins ) ;
192192 }
193-
193+
194194 [ Collection ( nameof ( NotThreadSafeResourceCollection ) ) ]
195195 public class DefaultOptions : IDisposable
196196 {
@@ -199,7 +199,7 @@ public DefaultOptions()
199199 NugetPluginCatalogOptions . Defaults . PluginNameOptions =
200200 new PluginNameOptions ( ) { PluginNameGenerator = ( nameOptions , type ) => type . FullName + "Modified" } ;
201201 }
202-
202+
203203 [ Fact ]
204204 public async Task CanConfigureDefaultNamingOptions ( )
205205 {
@@ -216,13 +216,83 @@ public async Task CanConfigureDefaultNamingOptions()
216216 // Assert
217217 Assert . EndsWith ( "Modified" , plugin . Name ) ;
218218 }
219-
219+
220220 public void Dispose ( )
221221 {
222222 NugetPluginCatalogOptions . Defaults . PluginNameOptions = new PluginNameOptions ( ) ;
223223 }
224224 }
225-
225+
226+ [ Collection ( nameof ( NotThreadSafeResourceCollection ) ) ]
227+ public class NugetDownloadResultsSerialisation : IDisposable
228+ {
229+ private string _packagesFolderInTestsBin ;
230+
231+ public NugetDownloadResultsSerialisation ( )
232+ {
233+ var executingAssemblyDir = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
234+ _packagesFolderInTestsBin = Path . Combine ( executingAssemblyDir , "TestPackagesDownloadResult" ) ;
235+ }
236+
237+ [ Fact ]
238+ public async Task SaveDownloadResultIfGivenCustomPackagesPath ( )
239+ {
240+ var options = new NugetPluginCatalogOptions ( )
241+ {
242+ TypeFinderOptions = new TypeFinderOptions ( )
243+ {
244+ TypeFinderCriterias = new List < TypeFinderCriteria > ( )
245+ {
246+ new TypeFinderCriteria ( )
247+ {
248+ Query = ( context , type ) =>
249+ {
250+ if ( string . Equals ( type . Name , "SqlConnection" ) )
251+ {
252+ return true ;
253+ }
254+
255+ return false ;
256+ }
257+ }
258+ }
259+ }
260+ } ;
261+
262+ // Arrange
263+ var catalog = new NugetPackagePluginCatalog ( "Microsoft.Data.SqlClient" , "2.1.2" , options : options , packagesFolder : _packagesFolderInTestsBin ) ;
264+
265+ // Act
266+ await catalog . Initialize ( ) ;
267+
268+ var plugin = catalog . Single ( ) ;
269+
270+ // This is the connection string part of the Weik.io docs. It provides readonly access to the Adventureworks database sample.
271+ // So it should be ok to have it here.
272+ dynamic conn = Activator . CreateInstance ( plugin , "Server=tcp:adafydevtestdb001.database.windows.net,1433;User ID=docs;Password=3h1@*6PXrldU4F95;Integrated Security=false;Initial Catalog=adafyweikiodevtestdb001;" ) ;
273+
274+ conn . Open ( ) ;
275+
276+ var cmd = conn . CreateCommand ( ) ;
277+ cmd . CommandText = "select top 1 * from SalesLT.Customer" ;
278+
279+ var reader = cmd . ExecuteReader ( ) ;
280+ while ( reader . Read ( ) )
281+ {
282+ Console . WriteLine ( String . Format ( "{0}" , reader [ 0 ] ) ) ;
283+ }
284+
285+ conn . Dispose ( ) ;
286+
287+ Assert . True ( File . Exists ( _packagesFolderInTestsBin + "/nugetDownloadResult.json" ) ) ;
288+ }
289+
290+ public void Dispose ( )
291+ {
292+ File . Delete ( _packagesFolderInTestsBin + "/nugetDownloadResult.json" ) ;
293+ }
294+ }
295+
226296 [ Fact ]
227297 public async Task CanInstallPackageWithNativeDepencencies ( )
228298 {
0 commit comments