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); } }
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); } }
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); } }
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)); } } }
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); } }