mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-16 22:52:27 +00:00
Refactor Database into DatabaseContext Moved into separate folder so it actually has a namespace instead sitting in the root
91 lines
No EOL
2.8 KiB
C#
91 lines
No EOL
2.8 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using LBPUnion.ProjectLighthouse.Database;
|
|
using LBPUnion.ProjectLighthouse.Helpers;
|
|
using LBPUnion.ProjectLighthouse.Servers.GameServer.Startup;
|
|
using LBPUnion.ProjectLighthouse.Tests;
|
|
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
|
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
|
using LBPUnion.ProjectLighthouse.Types.Misc;
|
|
using LBPUnion.ProjectLighthouse.Types.Users;
|
|
using Xunit;
|
|
|
|
namespace ProjectLighthouse.Tests.GameApiTests.Tests;
|
|
|
|
public class SlotTests : LighthouseServerTest<GameServerTestStartup>
|
|
{
|
|
[DatabaseFact]
|
|
public async Task ShouldOnlyShowUsersLevels()
|
|
{
|
|
await using DatabaseContext database = new();
|
|
|
|
Random r = new();
|
|
|
|
User userA = await database.CreateUser($"unitTestUser{r.Next()}", CryptoHelper.GenerateAuthToken());
|
|
User userB = await database.CreateUser($"unitTestUser{r.Next()}", CryptoHelper.GenerateAuthToken());
|
|
|
|
Location l = new()
|
|
{
|
|
X = 0,
|
|
Y = 0,
|
|
};
|
|
database.Locations.Add(l);
|
|
await database.SaveChangesAsync();
|
|
|
|
Slot slotA = new()
|
|
{
|
|
Creator = userA,
|
|
CreatorId = userA.UserId,
|
|
Name = "slotA",
|
|
Location = l,
|
|
LocationId = l.Id,
|
|
ResourceCollection = "",
|
|
};
|
|
|
|
Slot slotB = new()
|
|
{
|
|
Creator = userB,
|
|
CreatorId = userB.UserId,
|
|
Name = "slotB",
|
|
Location = l,
|
|
LocationId = l.Id,
|
|
ResourceCollection = "",
|
|
};
|
|
|
|
database.Slots.Add(slotA);
|
|
database.Slots.Add(slotB);
|
|
|
|
await database.SaveChangesAsync();
|
|
|
|
LoginResult loginResult = await this.Authenticate();
|
|
|
|
HttpResponseMessage respMessageA = await this.AuthenticatedRequest
|
|
($"LITTLEBIGPLANETPS3_XML/slots/by?u={userA.Username}&pageStart=1&pageSize=1", loginResult.AuthTicket);
|
|
HttpResponseMessage respMessageB = await this.AuthenticatedRequest
|
|
($"LITTLEBIGPLANETPS3_XML/slots/by?u={userB.Username}&pageStart=1&pageSize=1", loginResult.AuthTicket);
|
|
|
|
Assert.True(respMessageA.IsSuccessStatusCode);
|
|
Assert.True(respMessageB.IsSuccessStatusCode);
|
|
|
|
string respA = await respMessageA.Content.ReadAsStringAsync();
|
|
string respB = await respMessageB.Content.ReadAsStringAsync();
|
|
|
|
Assert.False(string.IsNullOrEmpty(respA));
|
|
Assert.False(string.IsNullOrEmpty(respB));
|
|
|
|
Assert.NotEqual(respA, respB);
|
|
Assert.DoesNotContain(respA, "slotB");
|
|
Assert.DoesNotContain(respB, "slotA");
|
|
|
|
// Cleanup
|
|
|
|
database.Slots.Remove(slotA);
|
|
database.Slots.Remove(slotB);
|
|
|
|
await database.RemoveUser(userA);
|
|
await database.RemoveUser(userB);
|
|
|
|
await database.SaveChangesAsync();
|
|
}
|
|
} |