コード例 #1
0
ファイル: OneDriveSyncTests.cs プロジェクト: yvanam/SyncPro
        public void OneDrive1ByteFileUploadTest()
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage);
            }

            int fragmentSize = 327680; // 320k
            int payloadSize  = 1;

            TokenResponse currentToken = GetCurrentToken();

            Guid remoteTestFolderName = Guid.NewGuid();
            Item remoteTestFolder     = CreateOneDriveTestDirectory(currentToken, remoteTestFolderName.ToString("D")).Result;

            using (OneDriveClient client = new OneDriveClient(currentToken))
            {
                OneDriveUploadSession session =
                    client.CreateUploadSession(remoteTestFolder.Id, "uploadTest.txt", payloadSize).Result;

                using (OneDriveFileUploadStream stream = new OneDriveFileUploadStream(client, session, fragmentSize))
                {
                    // Create a buffer for the data we want to send, and fill it with ASCII text
                    stream.Write(new byte[] { 0xAB }, 0, 1);
                }

                Assert.AreEqual(OneDriveFileUploadState.Completed, session.State);
            }
        }
コード例 #2
0
ファイル: OneDriveSyncTests.cs プロジェクト: yvanam/SyncPro
        public void OneDriveFileUploadNotEnoughData()
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage);
            }

            int payloadSize = 262144; // 256k

            TokenResponse currentToken = GetCurrentToken();

            Guid remoteTestFolderName = Guid.NewGuid();
            Item remoteTestFolder     = CreateOneDriveTestDirectory(currentToken, remoteTestFolderName.ToString("D")).Result;

            using (OneDriveClient client = new OneDriveClient(currentToken))
            {
                // Specify the upload size as 16 bytes larger than we are actually going to send.
                OneDriveUploadSession session =
                    client.CreateUploadSession(remoteTestFolder.Id, "uploadTest.txt", payloadSize + 16).Result;

                using (OneDriveFileUploadStream stream = new OneDriveFileUploadStream(client, session))
                {
                    byte[] data = CreateUploadBuffer(payloadSize);

                    // Write the data in 1k chunks
                    int writeSize = 1024;
                    for (int j = 0; j < payloadSize; j += writeSize)
                    {
                        stream.Write(data, j, writeSize);
                    }
                }

                Assert.AreEqual(OneDriveFileUploadState.Cancelled, session.State);
            }
        }
コード例 #3
0
ファイル: OneDriveSyncTests.cs プロジェクト: yvanam/SyncPro
        public void OneDriveFileUploadSingleFragment()
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage);
            }

            int fragmentSize = OneDriveFileUploadStream.DefaultFragmentSize; // 10M
            int payloadSize  = 524288;                                       // < 1 fragments

            TokenResponse currentToken = GetCurrentToken();

            Guid remoteTestFolderName = Guid.NewGuid();
            Item remoteTestFolder     = CreateOneDriveTestDirectory(currentToken, remoteTestFolderName.ToString("D")).Result;

            using (OneDriveClient client = new OneDriveClient(currentToken))
            {
                OneDriveUploadSession session =
                    client.CreateUploadSession(remoteTestFolder.Id, "uploadTest.txt", payloadSize).Result;

                using (OneDriveFileUploadStream stream = new OneDriveFileUploadStream(client, session, fragmentSize))
                {
                    byte[] data = CreateUploadBuffer(payloadSize);
                    stream.Write(data, 0, data.Length);
                }

                Assert.AreEqual(OneDriveFileUploadState.Completed, session.State);
                Assert.IsNotNull(session.Item);
            }
        }
コード例 #4
0
ファイル: OneDriveSyncTests.cs プロジェクト: yvanam/SyncPro
        public void OneDriveEmptyFileUploadTest()
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage);
            }

            TokenResponse currentToken = GetCurrentToken();

            using (OneDriveClient client = new OneDriveClient(currentToken))
            {
                try
                {
                    client.CreateUploadSession("nonExistentId", "uploadTest.txt", 0).Wait();
                }
                catch (AggregateException aggregateException)
                {
                    Assert.IsNotNull(aggregateException.InnerException);
                    Assert.IsInstanceOfType(aggregateException.InnerException, typeof(ArgumentOutOfRangeException));
                }
            }
        }
コード例 #5
0
ファイル: OneDriveSyncTests.cs プロジェクト: yvanam/SyncPro
        public void OneDriveFileUploadMultipleWrites()
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage);
            }

            int fragmentSize = 327680; // 320k
            int payloadSize  = 819200; // 2.5 fragments

            TokenResponse currentToken = GetCurrentToken();

            Guid remoteTestFolderName = Guid.NewGuid();
            Item remoteTestFolder     = CreateOneDriveTestDirectory(currentToken, remoteTestFolderName.ToString("D")).Result;

            using (OneDriveClient client = new OneDriveClient(currentToken))
            {
                OneDriveUploadSession session =
                    client.CreateUploadSession(remoteTestFolder.Id, "uploadTest.txt", payloadSize).Result;

                using (OneDriveFileUploadStream stream = new OneDriveFileUploadStream(client, session, fragmentSize))
                {
                    // Create a buffer for the data we want to send, and fill it with ASCII text
                    byte[] data = CreateUploadBuffer(payloadSize);

                    // Write the data in 1k chunks
                    int writeSize = 1024;
                    for (int j = 0; j < payloadSize; j += writeSize)
                    {
                        stream.Write(data, j, writeSize);
                    }
                }

                Assert.AreEqual(OneDriveFileUploadState.Completed, session.State);
            }
        }