public void If_File_Size_Is_Not_Multitude_Of_Block_Size_Then_Last_Block_Should_Be_Smaller_Then_Others()
        {
            var maxSize = Downloads.MaxBlockSize ?? 2048;

            //upload a file that consists of a total of 5.5 (6) blocks
            File.WriteAllBytes(Context.DownloadFile0Template.FullName, new byte[maxSize * 5 + maxSize / 2]);
            Context.DownloadFile0Template.Refresh();
            SourceFile = Context.DownloadFolder.AddFile(Context.DownloadFile0Template.FullName, "multiple.bin", false);

            Downloads.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);
            Token = Downloads.RequestDownloadToken(SourceFileInfo.FullName, false, maxSize);

            Assert.AreEqual(maxSize, Token.DownloadBlockSize);
            Assert.AreEqual(6, Token.TotalBlockCount);


            List <BufferedDataBlock> blockList = new List <BufferedDataBlock>();

            int blockNumber = 0;

            while (true)
            {
                BufferedDataBlock block = Downloads.ReadBlock(Token.TransferId, blockNumber++);
                blockList.Add(block);
                if (block.IsLastBlock)
                {
                    break;
                }
            }

            Assert.AreEqual(6, blockList.Count);
            Assert.AreEqual(maxSize / 2, blockList[5].BlockLength);
        }
        public void Token_Should_Calculate_MD5_File_Hash_If_Explicitly_Requested()
        {
            //cancel old download
            Assert.IsNullOrEmpty(Token.Md5FileHash);
            Downloads.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            //get new token with hash
            Token = Downloads.RequestDownloadToken(Token.ResourceIdentifier, true);
            Assert.IsNotEmpty(Token.Md5FileHash);

            var hash = Context.DownloadFile0Template.CalculateMd5Hash();

            StringAssert.AreEqualIgnoringCase(hash, Token.Md5FileHash);
        }
Ejemplo n.º 3
0
        public void Requesting_Block_Size_With_Specified_Value_Should_Be_Allowed_If_Service_Does_Not_Have_Limit()
        {
            if (Downloads.MaxBlockSize.HasValue)
            {
                Assert.Inconclusive("Download service has a maximum block size - did not run test.");
            }

            var blockSize = 2048;

            Token = Downloads.RequestDownloadToken(SourceFileInfo.FullName, false, blockSize);
            Assert.AreEqual(blockSize, Token.DownloadBlockSize);

            BufferedDataBlock block = Downloads.ReadBlock(Token.TransferId, 0);

            Assert.AreEqual(blockSize, block.BlockLength);
            Assert.AreEqual(blockSize, block.Data.Length);
        }
Ejemplo n.º 4
0
        public void Requesting_Token_With_Block_Size_Below_Maximum_Should_Return_Small_Blocks()
        {
            if (!Downloads.MaxBlockSize.HasValue)
            {
                Assert.Inconclusive("Download service does not provide maximum block size");
            }

            var blockSize = Downloads.MaxBlockSize.Value / 2;

            Token = Downloads.RequestDownloadToken(SourceFileInfo.FullName, false, blockSize);
            Assert.AreEqual(blockSize, Token.DownloadBlockSize);

            BufferedDataBlock block = Downloads.ReadBlock(Token.TransferId, 0);

            Assert.AreEqual(blockSize, block.BlockLength);
            Assert.AreEqual(blockSize, block.Data.Length);
        }
Ejemplo n.º 5
0
        public void Requesting_Token_With_Block_Size_Above_Max_Size_Should_Fall_Back_To_Maxium()
        {
            if (!Downloads.MaxBlockSize.HasValue)
            {
                Assert.Inconclusive("Download service does not provide maximum block size");
            }

            var expectedSize = Downloads.MaxBlockSize.Value;
            var blockSize    = expectedSize + 10000;

            Token = Downloads.RequestDownloadToken(SourceFileInfo.FullName, false, blockSize);
            Assert.AreEqual(expectedSize, Token.DownloadBlockSize);

            BufferedDataBlock block = Downloads.ReadBlock(Token.TransferId, 0);

            Assert.AreEqual(expectedSize, block.BlockLength);
            Assert.AreEqual(expectedSize, block.Data.Length);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Requests a download token for a given resource.
 /// </summary>
 public OperationResult <DownloadToken> Get(string filePath, bool includeFileHash)
 {
     return(SecureFunc(() => Downloads.RequestDownloadToken(filePath, includeFileHash)));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets a download token for the <see cref="SourceFile"/> and
 /// assigns it to the <see cref="Token"/> property.
 /// </summary>
 /// <returns>The retrieved token.</returns>
 protected DownloadToken InitToken()
 {
     Token = Downloads.RequestDownloadToken(SourceFileInfo.FullName, false);
     return(Token);
 }