BlinkSyncTests.MainTest.CreateTestFiles C# (CSharp) Method

CreateTestFiles() private static method

Creates files from specified array of files names
private static CreateTestFiles ( string baseDir, string srcDir, string files ) : void
baseDir string
srcDir string
files string
return void
        private static void CreateTestFiles(string baseDir, string srcDir, string[] files)
        {
            foreach (string file in files)
            {
                bool isHidden;  // create this file hidden
                bool isCopy;    // this is a destination file which should be an exact copy of the source
                // get file name and metadata
                string fileName = StripMetadataFromFilename(file, out isHidden, out isCopy);
                if (!isCopy)
                {
                    // create a new test file
                    string filePath = Path.Combine(baseDir, fileName);
                    FileStream fileStream = File.Create(filePath);

                    // seed a random number generator with a hash of the file name so we get exactly repeatable pseudorandom behavior
                    byte[] hashBytes = MD5.Create().ComputeHash(ASCIIEncoding.UTF8.GetBytes(filePath));
                    Random random = new Random(BitConverter.ToInt32(hashBytes, 0));

                    // pick a (deterministically seeded) random length
                    int length = random.Next(1, 16384);
                    byte[] fileBytes = new byte[length];
                    // fill the file with (deterministically seeded) random data
                    for (int i = 0; i < length; i++)
                    {
                        fileBytes[i] = (byte)random.Next(0, 255);
                    }
                    fileStream.Write(fileBytes, 0, fileBytes.Length);
                    fileStream.Close();

                    // set file as hidden if specified
                    if (isHidden)
                    {
                        File.SetAttributes(filePath, FileAttributes.Hidden);
                    }
                }
                else
                {
                    // copy file from source to dest
                    string srcPath = Path.Combine(srcDir, fileName);
                    string destPath = Path.Combine(baseDir, fileName);
                    File.Copy(srcPath, destPath);
                }
            }
        }