-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathChunkUploadServerLiveTest.cs
More file actions
76 lines (64 loc) · 2.42 KB
/
ChunkUploadServerLiveTest.cs
File metadata and controls
76 lines (64 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.Net;
using SimpleHTTPServer;
[TestClass]
public class ChunkUploadServerTests
{
private HttpClientHandler clientHandler;
[TestInitialize]
public void TestInitialize()
{
clientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; }
};
}
[TestMethod]
public async Task WhenCreatingAServer_ThenItStartsSuccessfully()
{
// Arrange
int chunkSize = 1024 * 1024;
int threadCount = 4;
int port = 8090;
var server = new ChunkUploadServer(chunkSize, threadCount);
server.StartServer(port);
// Act
using var client = new HttpClient(clientHandler);
var response = await client.GetAsync($"http://localhost:{port}/upload/");
Assert.AreEqual(HttpStatusCode.MethodNotAllowed, response.StatusCode);
}
[TestMethod]
[ExpectedException(typeof(HttpRequestException))]
public async Task WhenUploadingLargeFiles_ThenShouldRejectLargeFilesExceedingChunkCapacityByThrowingException()
{
// Arrange
int chunkSize = 1024 * 1024;
int threadCount = 4;
int port = 8091;
long fileSize = (chunkSize * threadCount) + 1; // Exceeds total chunk size
var server = new ChunkUploadServer(chunkSize, threadCount);
server.StartServer(port);
// Act
using var client = new HttpClient(clientHandler);
using var content = new ByteArrayContent(new byte[fileSize]);
content.Headers.Add("X-Filename", "test.txt");
var response = await client.PostAsync($"http://localhost:{port}/upload/", content);
}
[TestMethod]
public async Task WhenUploadingAFile_ThenShouldProcessChunksWithMultipleThreads()
{
// Arrange
int chunkSize = 1024 * 1024;
int threadCount = 4;
int port = 8092;
long fileSize = chunkSize * threadCount;
var server = new ChunkUploadServer(chunkSize, threadCount);
server.StartServer(port);
// Act
using var client = new HttpClient(clientHandler);
using var content = new ByteArrayContent(new byte[fileSize]);
content.Headers.Add("X-Filename", "test.txt");
var response = await client.PostAsync($"http://localhost:{port}/upload/", content);
// Assert
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
}
}