DownloadFile() public method

Downloads the file and returns the SHA-1 hash of the content of the saved file
On any disc or network io exception If the remote object has been disposed before the dowload is finished If download is aborted On exceptions thrown by the CMIS Server/Client
public DownloadFile ( IDocument remoteDocument, Stream localFileStream, Transmission transmission, HashAlgorithm hashAlg, UpdateChecksum update = null ) : void
remoteDocument IDocument Remote document.
localFileStream Stream Local taget file stream.
transmission Transmission Transmission status.
hashAlg System.Security.Cryptography.HashAlgorithm Hash algoritm, which should be used to calculate hash of the uploaded stream content
update UpdateChecksum Not or not yet used
return void
        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 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 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 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);
                }
            }
        }