@@ -6,13 +6,15 @@ namespace VirtualClient.Contracts
66 using System ;
77 using System . Collections . Generic ;
88 using System . Diagnostics ;
9+ using System . IO ;
910 using System . Linq ;
1011 using System . Runtime . InteropServices ;
1112 using System . Text ;
1213 using System . Threading ;
1314 using System . Threading . Tasks ;
1415 using Microsoft . Extensions . DependencyInjection ;
1516 using Microsoft . Extensions . DependencyInjection . Extensions ;
17+ using Moq ;
1618 using NUnit . Framework ;
1719 using VirtualClient . Common . Contracts ;
1820 using VirtualClient . Common . Extensions ;
@@ -249,6 +251,200 @@ public void CombineExtensionProducesTheExpectedPathOnUnixSystems()
249251 }
250252 }
251253
254+ [ Test ]
255+ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnUnixSystems_1 ( )
256+ {
257+ this . fixture . Setup ( PlatformID . Unix ) ;
258+
259+ string directory = "/home/user/Logs" ;
260+ string [ ] expectedFiles = new string [ ]
261+ {
262+ $ "{ directory } /log1.txt",
263+ $ "{ directory } /log2.txt"
264+ } ;
265+
266+ this . fixture . FileSystem
267+ . Setup ( fs => fs . Path . GetDirectoryName ( It . IsAny < string > ( ) ) )
268+ . Returns < string > ( file => directory ) ;
269+
270+ this . fixture . FileSystem
271+ . Setup ( fs => fs . Directory . GetFiles ( directory , "*.*" , SearchOption . AllDirectories ) )
272+ . Returns ( expectedFiles ) ;
273+
274+ using ( var component = new TestVirtualClientComponent ( this . fixture ) )
275+ {
276+ IEnumerable < FileUploadDescriptor > descriptors = component . CreateFileUploadDescriptors ( directory , timestamped : false ) ;
277+
278+ Assert . IsNotNull ( descriptors ) ;
279+ Assert . IsTrue ( descriptors . Count ( ) == 2 ) ;
280+
281+ FileUploadDescriptor descriptor1 = descriptors . ElementAt ( 0 ) ;
282+ Assert . AreEqual ( expectedFiles [ 0 ] , descriptor1 . FilePath ) ;
283+ Assert . IsTrue ( descriptor1 . BlobName . EndsWith ( "log1.txt" ) ) ;
284+ Assert . IsTrue ( descriptor1 . BlobPath . EndsWith ( "/log1.txt" ) ) ;
285+ Assert . AreEqual ( component . ExperimentId , descriptor1 . ContainerName ) ;
286+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor1 . ContentEncoding ) ;
287+ Assert . IsNotNull ( descriptor1 . ContentType ) ;
288+
289+ FileUploadDescriptor descriptor2 = descriptors . ElementAt ( 1 ) ;
290+ Assert . AreEqual ( expectedFiles [ 1 ] , descriptor2 . FilePath ) ;
291+ Assert . IsTrue ( descriptor2 . BlobName . EndsWith ( "log2.txt" ) ) ;
292+ Assert . IsTrue ( descriptor2 . BlobPath . EndsWith ( "/log2.txt" ) ) ;
293+ Assert . AreEqual ( component . ExperimentId , descriptor2 . ContainerName ) ;
294+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor2 . ContentEncoding ) ;
295+ Assert . IsNotNull ( descriptor2 . ContentType ) ;
296+ }
297+ }
298+
299+ [ Test ]
300+ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnUnixSystems_2 ( )
301+ {
302+ this . fixture . Setup ( PlatformID . Unix ) ;
303+
304+ string directory = "/home/user/Logs" ;
305+ string [ ] expectedFiles = new string [ ]
306+ {
307+ $ "{ directory } /log1.txt",
308+ $ "{ directory } /directory2/log2.txt",
309+ $ "{ directory } /directory2/directory3/log3.txt"
310+ } ;
311+
312+ this . fixture . FileSystem
313+ . Setup ( fs => fs . Path . GetDirectoryName ( It . IsAny < string > ( ) ) )
314+ . Returns < string > ( file => file . Replace ( Path . GetFileName ( file ) , string . Empty ) ) ;
315+
316+ this . fixture . FileSystem
317+ . Setup ( fs => fs . Directory . GetFiles ( directory , "*.*" , SearchOption . AllDirectories ) )
318+ . Returns ( expectedFiles ) ;
319+
320+ using ( var component = new TestVirtualClientComponent ( this . fixture ) )
321+ {
322+ IEnumerable < FileUploadDescriptor > descriptors = component . CreateFileUploadDescriptors ( directory , timestamped : false ) ;
323+
324+ Assert . IsNotNull ( descriptors ) ;
325+ Assert . IsTrue ( descriptors . Count ( ) == 3 ) ;
326+
327+ FileUploadDescriptor descriptor1 = descriptors . ElementAt ( 0 ) ;
328+ Assert . AreEqual ( expectedFiles [ 0 ] , descriptor1 . FilePath ) ;
329+ Assert . IsTrue ( descriptor1 . BlobName . EndsWith ( "log1.txt" ) ) ;
330+ Assert . IsTrue ( descriptor1 . BlobPath . EndsWith ( "/log1.txt" ) ) ;
331+ Assert . AreEqual ( component . ExperimentId , descriptor1 . ContainerName ) ;
332+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor1 . ContentEncoding ) ;
333+ Assert . IsNotNull ( descriptor1 . ContentType ) ;
334+
335+ FileUploadDescriptor descriptor2 = descriptors . ElementAt ( 1 ) ;
336+ Assert . AreEqual ( expectedFiles [ 1 ] , descriptor2 . FilePath ) ;
337+ Assert . IsTrue ( descriptor2 . BlobName . EndsWith ( "log2.txt" ) ) ;
338+ Assert . IsTrue ( descriptor2 . BlobPath . EndsWith ( "/directory2/log2.txt" ) ) ;
339+ Assert . AreEqual ( component . ExperimentId , descriptor2 . ContainerName ) ;
340+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor2 . ContentEncoding ) ;
341+ Assert . IsNotNull ( descriptor2 . ContentType ) ;
342+
343+ FileUploadDescriptor descriptor3 = descriptors . ElementAt ( 2 ) ;
344+ Assert . AreEqual ( expectedFiles [ 2 ] , descriptor3 . FilePath ) ;
345+ Assert . IsTrue ( descriptor3 . BlobName . EndsWith ( "log3.txt" ) ) ;
346+ Assert . IsTrue ( descriptor3 . BlobPath . EndsWith ( "/directory2/directory3/log3.txt" ) ) ;
347+ Assert . AreEqual ( component . ExperimentId , descriptor3 . ContainerName ) ;
348+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor3 . ContentEncoding ) ;
349+ Assert . IsNotNull ( descriptor3 . ContentType ) ;
350+ }
351+ }
352+
353+ [ Test ]
354+ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnWindowsSystems_1 ( )
355+ {
356+ string directory = "C:\\ Users\\ User\\ Logs" ;
357+ string [ ] expectedFiles = new string [ ]
358+ {
359+ $ "{ directory } \\ log1.txt",
360+ $ "{ directory } \\ log2.txt"
361+ } ;
362+
363+ this . fixture . FileSystem
364+ . Setup ( fs => fs . Path . GetDirectoryName ( It . IsAny < string > ( ) ) )
365+ . Returns < string > ( file => directory ) ;
366+
367+ this . fixture . FileSystem
368+ . Setup ( fs => fs . Directory . GetFiles ( directory , "*.*" , SearchOption . AllDirectories ) )
369+ . Returns ( expectedFiles ) ;
370+
371+ using ( var component = new TestVirtualClientComponent ( this . fixture ) )
372+ {
373+ IEnumerable < FileUploadDescriptor > descriptors = component . CreateFileUploadDescriptors ( directory , timestamped : false ) ;
374+
375+ Assert . IsNotNull ( descriptors ) ;
376+ Assert . IsTrue ( descriptors . Count ( ) == 2 ) ;
377+
378+ FileUploadDescriptor descriptor1 = descriptors . ElementAt ( 0 ) ;
379+ Assert . AreEqual ( expectedFiles [ 0 ] , descriptor1 . FilePath ) ;
380+ Assert . IsTrue ( descriptor1 . BlobName . EndsWith ( "log1.txt" ) ) ;
381+ Assert . IsTrue ( descriptor1 . BlobPath . EndsWith ( "/log1.txt" ) ) ;
382+ Assert . AreEqual ( component . ExperimentId , descriptor1 . ContainerName ) ;
383+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor1 . ContentEncoding ) ;
384+ Assert . IsNotNull ( descriptor1 . ContentType ) ;
385+
386+ FileUploadDescriptor descriptor2 = descriptors . ElementAt ( 1 ) ;
387+ Assert . AreEqual ( expectedFiles [ 1 ] , descriptor2 . FilePath ) ;
388+ Assert . IsTrue ( descriptor2 . BlobName . EndsWith ( "log2.txt" ) ) ;
389+ Assert . IsTrue ( descriptor2 . BlobPath . EndsWith ( "/log2.txt" ) ) ;
390+ Assert . AreEqual ( component . ExperimentId , descriptor2 . ContainerName ) ;
391+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor2 . ContentEncoding ) ;
392+ Assert . IsNotNull ( descriptor2 . ContentType ) ;
393+ }
394+ }
395+
396+ [ Test ]
397+ public void CreateCreateFileUploadDescriptorsExtensionCreatesTheExpectedDescriptorsOnWindowsSystems_2 ( )
398+ {
399+ string directory = "C:\\ Users\\ User\\ Logs" ;
400+ string [ ] expectedFiles = new string [ ]
401+ {
402+ $ "{ directory } \\ log1.txt",
403+ $ "{ directory } \\ directory2\\ log2.txt",
404+ $ "{ directory } \\ directory2\\ directory3\\ log3.txt"
405+ } ;
406+
407+ this . fixture . FileSystem
408+ . Setup ( fs => fs . Path . GetDirectoryName ( It . IsAny < string > ( ) ) )
409+ . Returns < string > ( file => file . Replace ( Path . GetFileName ( file ) , string . Empty ) ) ;
410+
411+ this . fixture . FileSystem
412+ . Setup ( fs => fs . Directory . GetFiles ( directory , "*.*" , SearchOption . AllDirectories ) )
413+ . Returns ( expectedFiles ) ;
414+
415+ using ( var component = new TestVirtualClientComponent ( this . fixture ) )
416+ {
417+ IEnumerable < FileUploadDescriptor > descriptors = component . CreateFileUploadDescriptors ( directory , timestamped : false ) ;
418+
419+ Assert . IsNotNull ( descriptors ) ;
420+ Assert . IsTrue ( descriptors . Count ( ) == 3 ) ;
421+
422+ FileUploadDescriptor descriptor1 = descriptors . ElementAt ( 0 ) ;
423+ Assert . AreEqual ( expectedFiles [ 0 ] , descriptor1 . FilePath ) ;
424+ Assert . IsTrue ( descriptor1 . BlobName . EndsWith ( "log1.txt" ) ) ;
425+ Assert . IsTrue ( descriptor1 . BlobPath . EndsWith ( "/log1.txt" ) ) ;
426+ Assert . AreEqual ( component . ExperimentId , descriptor1 . ContainerName ) ;
427+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor1 . ContentEncoding ) ;
428+ Assert . IsNotNull ( descriptor1 . ContentType ) ;
429+
430+ FileUploadDescriptor descriptor2 = descriptors . ElementAt ( 1 ) ;
431+ Assert . AreEqual ( expectedFiles [ 1 ] , descriptor2 . FilePath ) ;
432+ Assert . IsTrue ( descriptor2 . BlobName . EndsWith ( "log2.txt" ) ) ;
433+ Assert . IsTrue ( descriptor2 . BlobPath . EndsWith ( "/directory2/log2.txt" ) ) ;
434+ Assert . AreEqual ( component . ExperimentId , descriptor2 . ContainerName ) ;
435+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor2 . ContentEncoding ) ;
436+ Assert . IsNotNull ( descriptor2 . ContentType ) ;
437+
438+ FileUploadDescriptor descriptor3 = descriptors . ElementAt ( 2 ) ;
439+ Assert . AreEqual ( expectedFiles [ 2 ] , descriptor3 . FilePath ) ;
440+ Assert . IsTrue ( descriptor3 . BlobName . EndsWith ( "log3.txt" ) ) ;
441+ Assert . IsTrue ( descriptor3 . BlobPath . EndsWith ( "/directory2/directory3/log3.txt" ) ) ;
442+ Assert . AreEqual ( component . ExperimentId , descriptor3 . ContainerName ) ;
443+ Assert . AreEqual ( Encoding . UTF8 . WebName , descriptor3 . ContentEncoding ) ;
444+ Assert . IsNotNull ( descriptor3 . ContentType ) ;
445+ }
446+ }
447+
252448 [ Test ]
253449 public void VerifyLayoutDefinedExtensionThrowsWhenVerifyingTheEnvironmentLayoutIfItDoesNotExist ( )
254450 {
0 commit comments