public void TestUploadInMultipleChunks_Interception( [CombinatorialValues(true, false)] bool knownSize, [CombinatorialValues(100, 400, 1000)] int chunkSize, [CombinatorialValues(true, false)] bool ignoreFirstUploadCall) { // One fewer interception call than server calls, as there's no initialization call. var expectedInterceptionCount = (uploadLength + chunkSize - 1) / chunkSize; using (var server = new MultiChunkServer(_server, ignoreFirstUploadCall: ignoreFirstUploadCall)) using (var service = new MockClientService(server.HttpPrefix)) { var content = knownSize ? new MemoryStream(uploadTestBytes) : new UnknownSizeMemoryStream(uploadTestBytes); var uploader = new TestResumableUpload(service, "MultiChunk", "POST", content, "text/plain", chunkSize); int interceptionCount = 0; MemoryStream interceptedBytes = new MemoryStream(); uploader.UploadStreamInterceptor = (buffer, offset, count) => { interceptedBytes.Write(buffer, offset, count); interceptionCount++; }; var progress = uploader.Upload(); Assert.Equal(expectedInterceptionCount, interceptionCount); Assert.Equal(uploadTestBytes, interceptedBytes.ToArray()); } }
public void TestUploadWithUploaderRestart_UnknownSize() { // Unknown stream size not supported, exception always thrown using (var server = new MultiChunkServer(_server)) using (var service = new MockClientService(server.HttpPrefix)) { var content = new UnknownSizeMemoryStream(uploadTestBytes); var uploader = new TestResumableUpload(service, "whatever", "PUT", content, "", 100); var url = new Uri("http://what.ever/"); Assert.ThrowsAsync <NotImplementedException>(async() => await uploader.ResumeAsync(url)); } }
public void TestUploadInMultipleChunks( [CombinatorialValues(true, false)] bool knownSize, [CombinatorialValues(100, 400, 1000)] int chunkSize) { var expectedCallCount = 1 + (uploadLength + chunkSize - 1) / chunkSize; using (var server = new MultiChunkServer(_server)) using (var service = new MockClientService(server.HttpPrefix)) { var content = knownSize ? new MemoryStream(uploadTestBytes) : new UnknownSizeMemoryStream(uploadTestBytes); var uploader = new TestResumableUpload(service, "MultiChunk", "POST", content, "text/plain", chunkSize); var progress = uploader.Upload(); Assert.Equal(expectedCallCount, server.Requests.Count); Assert.Equal(uploadTestBytes, server.Bytes); Assert.Equal(UploadStatus.Completed, progress.Status); } }
public void TestUploadProgress( [CombinatorialValues(true, false)] bool knownSize) { int chunkSize = 200; using (var server = new MultiChunkServer(_server)) using (var service = new MockClientService(server.HttpPrefix)) { var content = knownSize ? new MemoryStream(uploadTestBytes) : new UnknownSizeMemoryStream(uploadTestBytes); var uploader = new TestResumableUpload(service, "MultiChunk", "POST", content, "text/plain", chunkSize); var progress = new List <IUploadProgress>(); uploader.ProgressChanged += p => progress.Add(p); uploader.Upload(); Assert.Equal(4, progress.Count); Assert.Equal(UploadStatus.Starting, progress[0].Status); Assert.Equal(0, progress[0].BytesSent); Assert.Equal(UploadStatus.Uploading, progress[1].Status); Assert.Equal(chunkSize, progress[1].BytesSent); Assert.Equal(UploadStatus.Uploading, progress[2].Status); Assert.Equal(chunkSize * 2, progress[2].BytesSent); Assert.Equal(UploadStatus.Completed, progress[3].Status); Assert.Equal(uploadLength, progress[3].BytesSent); } }