コード例 #1
0
 /// <summary>
 /// Tries to get an exclusive file lock on the <see cref="TargetFile"/>.
 /// This causes an exception if the file is in use.
 /// </summary>
 protected void EnsureTargetFileIsUnlocked()
 {
     //getting an exclusive stream only works if the file was released
     using (var fs = TargetFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
     {
         fs.Close();
     }
 }
コード例 #2
0
        public void Underlying_Stream_Should_Have_Been_Closed_After_Throwing_Exception()
        {
            //write a block in order to open the stream
            var block = CreateBufferedBlocks().First();

            UploadHandler.WriteBlock(block);

            //make sure the scheduler can readjust
            SystemTime.Now = () => Token.ExpirationTime.Value.AddSeconds(1);
            Thread.CurrentThread.Join(500);

            //getting an exclusive stream only works if the file was released
            using (var fs = TargetFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                fs.Close();
            }
        }
コード例 #3
0
        public void Starting_To_Write_After_Expiration_Should_Not_Open_The_Stream()
        {
            SystemTime.Now = () => Token.ExpirationTime.Value.AddSeconds(1);

            //make sure the scheduler can readjust
            Thread.CurrentThread.Join(500);

            //write a block in order to open the stream
            try
            {
                var block = CreateBufferedBlocks().First();
                UploadHandler.WriteBlock(block);
                Assert.Fail("Expected status exception");
            }
            catch (TransferStatusException ignored)
            { }

            //getting an exclusive stream only works if the file was released
            using (var fs = TargetFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                fs.Close();
            }
        }