mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-14 22:02:26 +00:00
Add tests for match
This commit is contained in:
parent
a459ef2302
commit
15e3870620
2 changed files with 60 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
@ -52,10 +53,22 @@ namespace ProjectLighthouse.Tests {
|
||||||
return await this.Client.PostAsync(endpoint, new StringContent(await File.ReadAllTextAsync(filePath)));
|
return await this.Client.PostAsync(endpoint, new StringContent(await File.ReadAllTextAsync(filePath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<HttpResponseMessage> AuthenticatedUploadFileRequest(string endpoint, string filePath) {
|
public async Task<HttpResponseMessage> UploadDataRequest(string endpoint, byte[] data) {
|
||||||
|
return await this.Client.PostAsync(endpoint, new ByteArrayContent(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<HttpResponseMessage> AuthenticatedUploadFileRequest(string endpoint, string filePath, string mmAuth) {
|
||||||
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, endpoint);
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, endpoint);
|
||||||
|
requestMessage.Headers.Add("Cookie", mmAuth);
|
||||||
requestMessage.Content = new StringContent(await File.ReadAllTextAsync(filePath));
|
requestMessage.Content = new StringContent(await File.ReadAllTextAsync(filePath));
|
||||||
return await this.Client.SendAsync(requestMessage);
|
return await this.Client.SendAsync(requestMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<HttpResponseMessage> AuthenticatedUploadDataRequest(string endpoint, byte[] data, string mmAuth) {
|
||||||
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, endpoint);
|
||||||
|
requestMessage.Headers.Add("Cookie", mmAuth);
|
||||||
|
requestMessage.Content = new ByteArrayContent(data);
|
||||||
|
return await this.Client.SendAsync(requestMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
46
ProjectLighthouse.Tests/Tests/MatchTests.cs
Normal file
46
ProjectLighthouse.Tests/Tests/MatchTests.cs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectLighthouse.Types;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace ProjectLighthouse.Tests {
|
||||||
|
public class MatchTests : LighthouseTest {
|
||||||
|
private readonly ITestOutputHelper testOutputHelper;
|
||||||
|
private static SemaphoreSlim semaphore = new(1, 1);
|
||||||
|
public MatchTests(ITestOutputHelper testOutputHelper) {
|
||||||
|
this.testOutputHelper = testOutputHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DatabaseFact]
|
||||||
|
public async Task ShouldReturnOk() {
|
||||||
|
LoginResult loginResult = await this.Authenticate();
|
||||||
|
await semaphore.WaitAsync();
|
||||||
|
|
||||||
|
HttpResponseMessage result = await AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
|
||||||
|
Assert.True(result.IsSuccessStatusCode);
|
||||||
|
|
||||||
|
semaphore.Release();
|
||||||
|
}
|
||||||
|
public async Task<int> GetPlayerCount() => Convert.ToInt32(await this.Client.GetStringAsync("LITTLEBIGPLANETPS3_XML/totalPlayerCount"));
|
||||||
|
|
||||||
|
[DatabaseFact]
|
||||||
|
public async Task ShouldIncrementPlayerCount() {
|
||||||
|
LoginResult loginResult = await this.Authenticate(new Random().Next());
|
||||||
|
|
||||||
|
await semaphore.WaitAsync();
|
||||||
|
|
||||||
|
int oldPlayerCount = await this.GetPlayerCount();
|
||||||
|
|
||||||
|
HttpResponseMessage result = await AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
|
||||||
|
Assert.True(result.IsSuccessStatusCode);
|
||||||
|
|
||||||
|
int playerCount = await this.GetPlayerCount();
|
||||||
|
|
||||||
|
semaphore.Release();
|
||||||
|
Assert.Equal(oldPlayerCount + 1, playerCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue