public void Getting_The_Stream_Should_Lock_File()
        {
            //make the stream big enough so it won't be auto-closed
            //on the server side
            byte[] buffer = new byte[1024 * 1024 * 200];
            File.WriteAllBytes(Context.DownloadFile0Template.FullName, buffer);
            Context.DownloadFile0Template.Refresh();
            FileSystem.WriteFile(Context.DownloadFile0Template.FullName, SourceFileInfo.FullName, true);

            var token = InitToken();

            using (Stream stream = Downloads.DownloadFile(token.TransferId))
            {
                //certain providers may already unlock the file - in this case,
                //we won't be able to complete this test
                var status = Downloads.GetTransferStatus(token.TransferId);
                if (status == TransferStatus.Completed)
                {
                    return;
                }

                try
                {
                    //if we request to delete the file, this should fail
                    SourceFile.Delete();
                    Assert.Fail("Could delete file although it should be locked.");
                }
                catch (ResourceLockedException e)
                {
                }
            }
        }
Example #2
0
        public void Uploading_An_Empty_File_Should_Create_The_File()
        {
            Uploads.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            //create source file
            SourceFile.Delete();
            using (var fs = SourceFile.Create())
            {
                fs.Close();
            }

            SourceFile.Refresh();
            Assert.AreEqual(0, SourceFile.Length);

            Assert.IsFalse(FileSystem.IsFileAvailable(TargetFilePath));
            using (var fs = SourceFile.OpenRead())
            {
                Uploads.WriteFile(TargetFilePath, fs, true, 0, "");
            }

            var target = FileSystem.GetFileInfo(TargetFilePath);

            Assert.AreEqual(0, target.Length);

            Context.DownloadFile1Template.Refresh();
            Assert.AreNotEqual(0, Context.DownloadFile1Template.Length);
            FileSystem.SaveFile(target, Context.DownloadFile1Template.FullName);
            Context.DownloadFile1Template.Refresh();
            Assert.AreEqual(0, Context.DownloadFile1Template.Length);
        }
        public void Completed_Transfer_Should_Unlock_File()
        {
            //get stream and write to file
            using (Stream stream = Downloads.ReadFile(SourceFileInfo.FullName))
            {
                stream.WriteTo(TargetFilePath);
            }

            Assert.IsTrue(SourceFile.Exists);
            SourceFile.Delete();
        }
        public void Closing_Stream_Should_Unlock_File()
        {
            string resourceId = SourceFileInfo.FullName.ToLowerInvariant();

            using (Stream stream = Downloads.ReadFile(resourceId))
            {
                byte[] buffer = new byte[6000];
                stream.Read(buffer, 0, buffer.Length);

                //close the stream
                stream.Close();
            }

            //attempting to delete the file should work now
            Thread.CurrentThread.Join(1000);
            SourceFile.Delete();
        }
Example #5
0
 //------------------------------------------
 public static void Delete(DirectoryInfo SourceDirectory)
 {
     DirectoryInfo[] SourceSubDirectories;
     FileInfo[]      SourceFiles;
     SourceFiles          = SourceDirectory.GetFiles();
     SourceSubDirectories = SourceDirectory.GetDirectories();
     //for (int i = 0; i < Form1.newModulesNames.Length; i++)
     //{
     //Recursively Copy Every SubDirectory and it's Contents (according to folder filter)
     foreach (DirectoryInfo SourceSubDirectory in SourceSubDirectories)
     {
         Delete(SourceSubDirectory);
     }
     foreach (FileInfo SourceFile in SourceFiles)
     {
         SourceFile.Delete();
     }
 }
        public void Uploading_An_Empty_File_Should_Create_The_File()
        {
            UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            SourceFile.Delete();
            using (var fs = SourceFile.Create())
            {
                fs.Close();
            }

            SourceFile.Refresh();
            Assert.AreEqual(0, SourceFile.Length);

            TargetFile.Refresh();
            Assert.IsFalse(TargetFile.Exists);

            using (var fs = SourceFile.OpenRead())
            {
                UploadHandler.WriteFile(TargetFilePath, fs, true, 0, "");
            }

            TargetFile.Refresh();
            Assert.IsTrue(TargetFile.Exists);
        }
Example #7
0
 public void Modifying_And_Deleting_Should_Work_While_Downloading()
 {
     DownloadHandler.ReadBlock(Token.TransferId, 0);
     //this doesn't delete the file right away (it's still in use, but leaves it up to the FS to clean up)
     SourceFile.Delete();
 }
Example #8
0
 public void Trying_To_Read_First_Block_Of_Deleted_File_Should_Fail()
 {
     SourceFile.Delete();
     DownloadHandler.ReadBlock(Token.TransferId, 0);
 }
 public void Deleted_File_Should_Cause()
 {
     SourceFile.Delete();
     Assert.Fail("Test not implemented yet."); //TODO missing test
 }
 public void Modifying_And_Deleting_Should_Work_While_Downloading()
 {
     DownloadService.ReadBlock(Token.TransferId, 0);
     SourceFile.Delete();
 }