@@ -22,6 +22,7 @@ public partial class IntegrationTestBase
2222 protected string m_testImagePath ;
2323 protected string m_testUnicodeImagePath ;
2424 protected string m_testLargeImagePath ;
25+ protected string m_testLargeFilePath ;
2526 protected string m_testVideoPath ;
2627 protected string m_testPdfPath ;
2728 protected string m_testIconPath ;
@@ -39,6 +40,7 @@ public partial class IntegrationTestBase
3940 protected const string TEST_UNICODE_IMAGE_NAME = "TestüniNämeLögö" ;
4041 protected const string TEST_UNICODE_IMAGE = "TestüniNämeLögö.jpg" ;
4142 protected const string TEST_LARGEIMAGE = "TestLargeImage.jpg" ;
43+ protected const string TEST_LARGEFILE = "TestLargeFile.txt" ;
4244 protected const string TEST_PDF = "multipage.pdf" ;
4345 protected const string TEST_FAVICON = "favicon.ico" ;
4446
@@ -163,19 +165,21 @@ public static string GetTaggedRandomValue()
163165
164166 private void SaveTestResources ( Assembly assembly )
165167 {
166- string filePrefix = Path . GetDirectoryName ( assembly . Location ) ;
167- string testName = GetType ( ) . Name ;
168+ var filePrefix = Path . GetDirectoryName ( assembly . Location ) ?? "" ;
169+ var testName = GetType ( ) . Name ;
168170
169171 m_testVideoPath = Path . Combine ( filePrefix , testName , TEST_MOVIE ) ;
170172 m_testImagePath = Path . Combine ( filePrefix , testName , TEST_IMAGE ) ;
171173 m_testUnicodeImagePath = Path . Combine ( filePrefix , testName , TEST_UNICODE_IMAGE ) ;
172174 m_testLargeImagePath = Path . Combine ( filePrefix , testName , TEST_LARGEIMAGE ) ;
175+ m_testLargeFilePath = Path . Combine ( filePrefix , testName , TEST_LARGEFILE ) ;
173176 m_testPdfPath = Path . Combine ( filePrefix , testName , TEST_PDF ) ;
174177 m_testIconPath = Path . Combine ( filePrefix , testName , TEST_FAVICON ) ;
175178
176179 SaveEmbeddedToDisk ( assembly , TEST_IMAGE , m_testImagePath ) ;
177180 SaveEmbeddedToDisk ( assembly , TEST_IMAGE , m_testUnicodeImagePath ) ;
178181 SaveEmbeddedToDisk ( assembly , TEST_LARGEIMAGE , m_testLargeImagePath ) ;
182+ PopulateLargeFile ( m_testLargeFilePath , 20971520 ) ;
179183 SaveEmbeddedToDisk ( assembly , TEST_MOVIE , m_testVideoPath ) ;
180184 SaveEmbeddedToDisk ( assembly , TEST_FAVICON , m_testIconPath ) ;
181185 SaveEmbeddedToDisk ( assembly , TEST_PDF , m_testPdfPath ) ;
@@ -195,20 +199,66 @@ private static void SaveEmbeddedToDisk(Assembly assembly, string sourcePath, str
195199 Directory . CreateDirectory ( directoryName ) ;
196200 }
197201
198- Stream stream = assembly . GetManifestResourceStream ( resName ) ;
199- using ( FileStream fileStream = new FileStream ( destPath , FileMode . CreateNew ) )
202+ var stream = assembly . GetManifestResourceStream ( resName ) ;
203+ using ( var fileStream = new FileStream ( destPath , FileMode . CreateNew ) )
200204 {
201205 stream . CopyTo ( fileStream ) ;
202206 }
203207 }
204208 catch
205209 {
210+ // ignored
211+ }
212+ }
206213
214+ private static void PopulateLargeFile ( string filePath , long size , int chunkSize = 4096 )
215+ {
216+ if ( File . Exists ( filePath ) )
217+ {
218+ return ;
219+ }
220+
221+ // Write the initial binary data
222+ var initialData = new byte [ ]
223+ {
224+ 0x42 , 0x4D , 0x4A , 0xB9 , 0x59 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x8A , 0x00 , 0x00 , 0x00 , 0x7C , 0x00 ,
225+ 0x00 , 0x00 , 0x78 , 0x05 , 0x00 , 0x00 , 0x78 , 0x05 , 0x00 , 0x00 , 0x01 , 0x00 , 0x18 , 0x00 , 0x00 , 0x00 ,
226+ 0x00 , 0x00 , 0xC0 , 0xB8 , 0x59 , 0x00 , 0x61 , 0x0F , 0x00 , 0x00 , 0x61 , 0x0F , 0x00 , 0x00 , 0x00 , 0x00 ,
227+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 ,
228+ 0x00 , 0x00 , 0x00 , 0xFF , 0x42 , 0x47 , 0x52 , 0x73 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
229+ 0x54 , 0xB8 , 0x1E , 0xFC , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x66 , 0x66 , 0x66 , 0xFC ,
230+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xC4 , 0xF5 , 0x28 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 ,
231+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
232+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
233+ } ;
234+
235+ using ( var fileStream = new FileStream ( filePath , FileMode . CreateNew ) )
236+ {
237+ fileStream . Write ( initialData , 0 , initialData . Length ) ;
238+
239+ // Calculate the remaining size to fill
240+ var remainingSize = size - fileStream . Length ;
241+
242+ var buffer = new byte [ chunkSize ] ;
243+
244+ // Fill the buffer with 0xFF
245+ for ( var i = 0 ; i < buffer . Length ; i ++ )
246+ {
247+ buffer [ i ] = 0xFF ;
248+ }
249+
250+ // Write chunks until the file reaches the specified size
251+ while ( remainingSize > 0 )
252+ {
253+ var currChunkSize = ( int ) Math . Min ( remainingSize , chunkSize ) ;
254+ fileStream . Write ( buffer , 0 , currChunkSize ) ;
255+ remainingSize -= currChunkSize ;
256+ }
207257 }
208258 }
209259
210260
211- protected List < string > SplitFile ( string sourceFile , int chunkSize , string suffix = "" )
261+ protected static List < string > SplitFile ( string sourceFile , int chunkSize , string suffix = "" )
212262 {
213263 var chunks = new List < string > ( ) ;
214264
@@ -520,6 +570,11 @@ protected static string GetFileMd5Sum(string filename)
520570 }
521571 }
522572
573+ protected static int GetFileSize ( string filename )
574+ {
575+ return ( int ) new FileInfo ( filename ) . Length ;
576+ }
577+
523578 [ OneTimeTearDown ]
524579 public virtual void Cleanup ( )
525580 {
0 commit comments