Exemple #1
0
        public void OneDriveFileDownloadTest()
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage);
            }

            TokenResponse currentToken = GetCurrentToken();

            using (OneDriveClient client = new OneDriveClient(currentToken))
            {
                string path        = "Sample%20Pictures/sample_photo_02.jpg";
                Item   item        = client.GetItemByPathAsync(path).Result;
                Uri    downloadUri = client.GetDownloadUriForItem(item.Id).Result;

                using (OneDriveFileDownloadStream stream = new OneDriveFileDownloadStream(client, downloadUri))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        byte[] buffer    = new byte[32768];
                        int    totalRead = 0;
                        while (true)
                        {
                            int read = stream.Read(buffer, 0, 32768);
                            totalRead += read;
                            ms.Write(buffer, 0, read);

                            if (read == 0 || read < 32768)
                            {
                                Assert.AreEqual(ms.Position, 76929);
                                Assert.AreEqual(totalRead, 76929);
                                break;
                            }
                        }
                    }
                }
            }
        }