mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-31 01:08:41 +00:00
Re-do formatting
This commit is contained in:
parent
95a1fd35a5
commit
173addfd03
74 changed files with 1286 additions and 905 deletions
|
@ -5,10 +5,13 @@ using LBPUnion.ProjectLighthouse.Types;
|
|||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests {
|
||||
public class AuthenticationTests : LighthouseTest {
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public class AuthenticationTests : LighthouseTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task ShouldReturnErrorOnNoPostData() {
|
||||
public async Task ShouldReturnErrorOnNoPostData()
|
||||
{
|
||||
HttpResponseMessage response = await this.Client.PostAsync("/LITTLEBIGPLANETPS3_XML/login", null!);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
#if NET6_0_OR_GREATER
|
||||
|
@ -19,7 +22,8 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnWithValidData() {
|
||||
public async Task ShouldReturnWithValidData()
|
||||
{
|
||||
HttpResponseMessage response = await this.AuthenticateResponse();
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
@ -28,9 +32,10 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task CanSerializeBack() {
|
||||
public async Task CanSerializeBack()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
|
||||
|
||||
Assert.NotNull(loginResult);
|
||||
Assert.NotNull(loginResult.AuthTicket);
|
||||
Assert.NotNull(loginResult.LbpEnvVer);
|
||||
|
@ -40,18 +45,20 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task CanUseToken() {
|
||||
public async Task CanUseToken()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
|
||||
HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/eula", loginResult.AuthTicket);
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
Assert.Contains("You are now logged in", responseContent);
|
||||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnForbiddenWhenNotAuthenticated() {
|
||||
public async Task ShouldReturnForbiddenWhenNotAuthenticated()
|
||||
{
|
||||
HttpResponseMessage response = await this.Client.GetAsync("/LITTLEBIGPLANETPS3_XML/eula");
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
Assert.True(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests {
|
||||
public class DatabaseTests : LighthouseTest {
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public class DatabaseTests : LighthouseTest
|
||||
{
|
||||
[DatabaseFact]
|
||||
public async Task CanCreateUserTwice() {
|
||||
public async Task CanCreateUserTwice()
|
||||
{
|
||||
await using Database database = new();
|
||||
int rand = new Random().Next();
|
||||
|
||||
|
|
|
@ -4,47 +4,56 @@ using System.Text;
|
|||
using LBPUnion.ProjectLighthouse.Types.Files;
|
||||
using Xunit;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests {
|
||||
public class FileTypeTests {
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public class FileTypeTests
|
||||
{
|
||||
[Fact]
|
||||
public void ShouldRecognizeLevel() {
|
||||
public void ShouldRecognizeLevel()
|
||||
{
|
||||
LbpFile file = new(File.ReadAllBytes("ExampleFiles/TestLevel.lvl"));
|
||||
Assert.True(file.FileType == LbpFileType.Level);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldRecognizeScript() {
|
||||
public void ShouldRecognizeScript()
|
||||
{
|
||||
LbpFile file = new(File.ReadAllBytes("ExampleFiles/TestScript.ff"));
|
||||
Assert.True(file.FileType == LbpFileType.Script);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldRecognizeTexture() {
|
||||
public void ShouldRecognizeTexture()
|
||||
{
|
||||
LbpFile file = new(File.ReadAllBytes("ExampleFiles/TestTexture.tex"));
|
||||
Assert.True(file.FileType == LbpFileType.Texture);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldRecognizeFileArchive() {
|
||||
public void ShouldRecognizeFileArchive()
|
||||
{
|
||||
LbpFile file = new(File.ReadAllBytes("ExampleFiles/TestFarc.farc"));
|
||||
Assert.True(file.FileType == LbpFileType.FileArchive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldNotRecognizeFileArchiveAsScript() {
|
||||
public void ShouldNotRecognizeFileArchiveAsScript()
|
||||
{
|
||||
LbpFile file = new(File.ReadAllBytes("ExampleFiles/TestFarc.farc"));
|
||||
Assert.False(file.FileType == LbpFileType.Script);
|
||||
Assert.True(file.FileType == LbpFileType.FileArchive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldRecognizeNothingAsUnknown() {
|
||||
public void ShouldRecognizeNothingAsUnknown()
|
||||
{
|
||||
LbpFile file = new(Array.Empty<byte>());
|
||||
Assert.True(file.FileType == LbpFileType.Unknown);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldRecognizeGarbageAsUnknown() {
|
||||
public void ShouldRecognizeGarbageAsUnknown()
|
||||
{
|
||||
LbpFile file = new(Encoding.ASCII.GetBytes("free pc only $900"));
|
||||
Assert.True(file.FileType == LbpFileType.Unknown);
|
||||
}
|
||||
|
|
|
@ -6,12 +6,15 @@ using System.Threading.Tasks;
|
|||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests {
|
||||
public class MatchTests : LighthouseTest {
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public class MatchTests : LighthouseTest
|
||||
{
|
||||
private static readonly SemaphoreSlim semaphore = new(1, 1);
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldRejectEmptyData() {
|
||||
public async Task ShouldRejectEmptyData()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
|
@ -22,16 +25,13 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnOk() {
|
||||
public async Task ShouldReturnOk()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest(
|
||||
"LITTLEBIGPLANETPS3_XML/match",
|
||||
Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"),
|
||||
loginResult.AuthTicket
|
||||
);
|
||||
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
|
||||
("LITTLEBIGPLANETPS3_XML/match", Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"), loginResult.AuthTicket);
|
||||
|
||||
semaphore.Release();
|
||||
Assert.True(result.IsSuccessStatusCode);
|
||||
|
@ -39,23 +39,21 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
public async Task<int> GetPlayerCount() => Convert.ToInt32(await this.Client.GetStringAsync("LITTLEBIGPLANETPS3_XML/totalPlayerCount"));
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldIncrementPlayerCount() {
|
||||
public async Task ShouldIncrementPlayerCount()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate(new Random().Next());
|
||||
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
int oldPlayerCount = await this.GetPlayerCount();
|
||||
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest(
|
||||
"LITTLEBIGPLANETPS3_XML/match",
|
||||
Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"),
|
||||
loginResult.AuthTicket
|
||||
);
|
||||
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
|
||||
("LITTLEBIGPLANETPS3_XML/match", Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"), loginResult.AuthTicket);
|
||||
|
||||
Assert.True(result.IsSuccessStatusCode);
|
||||
|
||||
int playerCount = await this.GetPlayerCount();
|
||||
|
||||
|
||||
semaphore.Release();
|
||||
Assert.Equal(oldPlayerCount + 1, playerCount);
|
||||
}
|
||||
|
|
|
@ -2,30 +2,42 @@ using System.Collections.Generic;
|
|||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using Xunit;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests {
|
||||
public class SerializerTests : LighthouseTest {
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public class SerializerTests : LighthouseTest
|
||||
{
|
||||
[Fact]
|
||||
public void BlankElementWorks() {
|
||||
public void BlankElementWorks()
|
||||
{
|
||||
Assert.Equal("<test></test>", LbpSerializer.BlankElement("test"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringElementWorks() {
|
||||
public void StringElementWorks()
|
||||
{
|
||||
Assert.Equal("<test>asd</test>", LbpSerializer.StringElement("test", "asd"));
|
||||
Assert.Equal("<test>asd</test>", LbpSerializer.StringElement(new KeyValuePair<string, object>("test", "asd")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TaggedStringElementWorks() {
|
||||
public void TaggedStringElementWorks()
|
||||
{
|
||||
Assert.Equal("<test foo=\"bar\">asd</test>", LbpSerializer.TaggedStringElement("test", "asd", "foo", "bar"));
|
||||
Assert.Equal("<test foo=\"bar\">asd</test>", LbpSerializer.TaggedStringElement(new KeyValuePair<string, object>("test", "asd"),
|
||||
new KeyValuePair<string, object>("foo", "bar")));
|
||||
Assert.Equal
|
||||
(
|
||||
"<test foo=\"bar\">asd</test>",
|
||||
LbpSerializer.TaggedStringElement(new KeyValuePair<string, object>("test", "asd"), new KeyValuePair<string, object>("foo", "bar"))
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ElementsWorks() {
|
||||
Assert.Equal("<test>asd</test><foo>bar</foo>", LbpSerializer.Elements(new KeyValuePair<string, object>("test", "asd"),
|
||||
new KeyValuePair<string, object>("foo", "bar")));
|
||||
public void ElementsWorks()
|
||||
{
|
||||
Assert.Equal
|
||||
(
|
||||
"<test>asd</test><foo>bar</foo>",
|
||||
LbpSerializer.Elements(new KeyValuePair<string, object>("test", "asd"), new KeyValuePair<string, object>("foo", "bar"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,10 +4,13 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
|||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||
using Xunit;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests {
|
||||
public class SlotTests : LighthouseTest {
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public class SlotTests : LighthouseTest
|
||||
{
|
||||
[DatabaseFact]
|
||||
public async Task ShouldOnlyShowUsersLevels() {
|
||||
public async Task ShouldOnlyShowUsersLevels()
|
||||
{
|
||||
await using Database database = new();
|
||||
|
||||
User userA = await database.CreateUser("unitTestUser0");
|
||||
|
@ -17,7 +20,8 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
database.Locations.Add(l);
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
Slot slotA = new() {
|
||||
Slot slotA = new()
|
||||
{
|
||||
Creator = userA,
|
||||
Name = "slotA",
|
||||
Location = l,
|
||||
|
@ -25,7 +29,8 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
ResourceCollection = "",
|
||||
};
|
||||
|
||||
Slot slotB = new() {
|
||||
Slot slotB = new()
|
||||
{
|
||||
Creator = userB,
|
||||
Name = "slotB",
|
||||
Location = l,
|
||||
|
@ -47,7 +52,7 @@ namespace LBPUnion.ProjectLighthouse.Tests {
|
|||
Assert.NotEqual(respA, respB);
|
||||
Assert.DoesNotContain(respA, "slotB");
|
||||
Assert.DoesNotContain(respB, "slotA");
|
||||
|
||||
|
||||
// Cleanup
|
||||
|
||||
database.Slots.Remove(slotA);
|
||||
|
|
|
@ -4,39 +4,47 @@ using System.Net.Http;
|
|||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests {
|
||||
public class UploadTests : LighthouseTest {
|
||||
public UploadTests() {
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public class UploadTests : LighthouseTest
|
||||
{
|
||||
public UploadTests()
|
||||
{
|
||||
string assetsDirectory = Path.Combine(Environment.CurrentDirectory, "r");
|
||||
if(Directory.Exists(assetsDirectory)) Directory.Delete(assetsDirectory, true);
|
||||
if (Directory.Exists(assetsDirectory)) Directory.Delete(assetsDirectory, true);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptScript() {
|
||||
public async Task ShouldNotAcceptScript()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/scriptTest", "ExampleFiles/TestScript.ff");
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptFarc() {
|
||||
public async Task ShouldNotAcceptFarc()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/farcTest", "ExampleFiles/TestFarc.farc");
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptGarbage() {
|
||||
public async Task ShouldNotAcceptGarbage()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/garbageTest", "ExampleFiles/TestGarbage.bin");
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldAcceptTexture() {
|
||||
public async Task ShouldAcceptTexture()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/textureTest", "ExampleFiles/TestTexture.tex");
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldAcceptLevel() {
|
||||
public async Task ShouldAcceptLevel()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/levelTest", "ExampleFiles/TestLevel.lvl");
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue