protected override void CleanupInternal()
        {
            if (Token != null)
            {
                if (DownloadHandler.GetTransferStatus(Token.TransferId) != TransferStatus.UnknownTransfer)
                {
                    DownloadHandler.CancelTransfer(Token.TransferId, AbortReason.Undefined);
                }
            }

            SystemTime.Reset();
            ParentDirectory.Delete(true);

            base.CleanupInternal();
        }
        public void Aborted_Transfer_Should_Unlock_Immediately()
        {
            //behind the scenes, many blocks are read, independent of the buffer size. Accordingly,
            //the transfer will abort as soon as we want it
            string resourceId = SourceFileInfo.FullName;

            using (Stream stream = DownloadHandler.ReadFile(resourceId))
            {
                //we need to get the token in order to get the transfer that was created internally
                var token = GetToken(resourceId);

                byte[] buffer = new byte[1234];
                stream.Read(buffer, 0, buffer.Length);
                int r = stream.Read(buffer, 1000, 234);
                Assert.AreEqual(234, r);

                //abort the transfer
                DownloadHandler.CancelTransfer(token.TransferId, AbortReason.ClientAbort);

                Assert.AreEqual(ResourceLockState.Unlocked, provider.LockRepository.GetLockState(resourceId));
            }
        }
        public void Aborted_Transfer_Should_Hit_While_Reading_Even_If_We_Try_To_Read_In_One_Buffer()
        {
            //behind the scenes, many blocks are read, independent of the buffer size. Accordingly,
            //the transfer will abort as soon as we want it
            string resourceId = SourceFileInfo.FullName;

            using (Stream stream = DownloadHandler.ReadFile(resourceId))
            {
                //we need to get the token in order to get the transfer that was created internally
                var token = GetToken(resourceId);

                byte[] buffer = new byte[1234];
                stream.Read(buffer, 0, buffer.Length);
                int r = stream.Read(buffer, 1000, 234);
                Assert.AreEqual(234, r);

                //abort the transfer
                DownloadHandler.CancelTransfer(token.TransferId, AbortReason.ClientAbort);

                //try to read again
                stream.Read(buffer, 0, buffer.Length);
            }
        }