Chunked downloader.
Inheritance: IFileDownloader
 public void ConstructorWithoutInput() {
     using (var downloader = new ChunkedDownloader(this.chunkSize)) {
         Assert.AreEqual(this.chunkSize, downloader.ChunkSize);
     }
 }
        public void ResumeDownloadWithUtils() {
            long startPos = this.remoteLength / 2;
            SetupResumeDownload(startPos);

            using (var memorystream = new MemoryStream(this.remoteChunk)) {
                this.mockedStream.Setup(stream => stream.Stream).Returns(memorystream);

                using (IFileDownloader downloader = new ChunkedDownloader(this.chunkSize)) {
                    ContentTaskUtils.PrepareResume(startPos, this.localFileStream, this.hashAlg);
                    downloader.DownloadFile(this.mock.Object, this.localFileStream, this.transmission, this.hashAlg);
                    Assert.AreEqual(this.remoteContent.Length, this.localFileStream.Length);
                    Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.remoteContent), this.hashAlg.Hash);
                    Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.localFileStream.ToArray()), this.hashAlg.Hash);
                }
            }
        }
        public void ResumeDownloadByWrongStorage() {
            long startPos = this.remoteLength / 2;
            SetupFullDownload();
            SetupStorage(startPos);

            this.localFileStream.Write(this.remoteContent, 0, (int)startPos);
            this.localFileStream.Seek(0, SeekOrigin.Begin);
            Assert.AreEqual(this.remoteChunk.Length, this.remoteLength - this.localFileStream.Length);

            byte[] checksum = this.mockedStorage.Object.GetObjectList()[0].LastChecksum;
            checksum[0] = (byte)(checksum[0] + 1);

            using (var memorystream = new MemoryStream(this.remoteChunk)) {
                this.mockedStream.Setup(stream => stream.Stream).Returns(memorystream);

                using (IFileDownloader downloader = new ChunkedDownloader(this.chunkSize, this.mockedStorage.Object)) {
                    downloader.DownloadFile(this.mock.Object, this.localFileStream, this.transmission, this.hashAlg);
                    Assert.AreEqual(this.remoteContent.Length, this.localFileStream.Length);
                    Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.remoteContent), this.hashAlg.Hash);
                    Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.localFileStream.ToArray()), this.hashAlg.Hash);
                }
            }
        }
        public void FullDownloadWithoutLength() {
            SetupFullDownload();

            this.mockedStream.Setup(stream => stream.Length).Returns((long?)null);
            var mockedMemoryStream = new Mock<MemoryStream>(this.remoteContent) { CallBase = true };
            mockedMemoryStream.Setup(ms => ms.Length).Throws(new NotSupportedException());
            this.mockedStream.Setup(stream => stream.Stream).Returns(mockedMemoryStream.Object);

            using (IFileDownloader downloader = new ChunkedDownloader(this.chunkSize)) {
                downloader.DownloadFile(this.mock.Object, this.localFileStream, this.transmission, this.hashAlg);
                Assert.AreEqual(this.remoteContent.Length, this.localFileStream.Length);
                Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.remoteContent), this.hashAlg.Hash);
                Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.localFileStream.ToArray()), this.hashAlg.Hash);
            }
        }
        public void FullDownload() {
            SetupFullDownload();

            using (var memorystream = new MemoryStream(this.remoteContent)) {
                this.mockedStream.Setup(stream => stream.Stream).Returns(memorystream);

                using (IFileDownloader downloader = new ChunkedDownloader(this.chunkSize)) {
                    downloader.DownloadFile(this.mock.Object, this.localFileStream, this.transmission, this.hashAlg);
                    Assert.AreEqual(this.remoteContent.Length, this.localFileStream.Length);
                    Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.remoteContent), this.hashAlg.Hash);
                    Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.localFileStream.ToArray()), this.hashAlg.Hash);
                }
            }
        }
 public void ConstructorWithValidInput() {
     using (var downloader = new ChunkedDownloader()) {
         Assert.Greater(downloader.ChunkSize, 0);
     }
 }