mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 08:28:39 +00:00
Rewrite gameserver slot filter system (#763)
* Initial implementation of new slot sorting and filtering system * Initial implementation of filtering for lbp3 community tab * Add support for organization on lbp3 * Add playlist and user categories * Implement unit tests for all filters Refactor more systems to use PaginationData * Fix PlayerCountFilter test * Add more unit tests and integration tests for the filter system * Fix LBP2 move filter and gameFilterType * Fix sort by likes in LBP3 category * Add sort for total plays * Remove extra whitespace and make styling more consistent * Order hearted and queued levels by primary key ID * Fix query without order warnings
This commit is contained in:
parent
de228cb242
commit
0c1e350fa3
106 changed files with 4040 additions and 1183 deletions
|
@ -0,0 +1,388 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LBPUnion.ProjectLighthouse.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Filter.Filters;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Tests.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class ControllerExtensionTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetDefaultFilters_ShouldReturnFilterBuilder()
|
||||
{
|
||||
SlotQueryBuilder queryBuilder = new SlotsController(null!).GetDefaultFilters(MockHelper.GetUnitTestToken());
|
||||
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(GameVersionFilter)));
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(SubLevelFilter)));
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(HiddenSlotFilter)));
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(SlotTypeFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddExcludeLbp1Filter_WhenTokenNotLbp1()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString(),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(ExcludeLBP1OnlyFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldReturnFilters_WhenQueryEmpty()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString(),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(GameVersionFilter)));
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(ExcludeLBP1OnlyFilter)));
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(SubLevelFilter)));
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(HiddenSlotFilter)));
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(SlotTypeFilter)));
|
||||
}
|
||||
|
||||
private static List<ISlotFilter> GetDefaultFilters
|
||||
(SlotQueryBuilder queryBuilder) =>
|
||||
queryBuilder.GetFilters(typeof(GameVersionFilter))
|
||||
.Union(queryBuilder.GetFilters(typeof(SubLevelFilter))
|
||||
.Union(queryBuilder.GetFilters(typeof(HiddenSlotFilter))
|
||||
.Union(queryBuilder.GetFilters(typeof(SlotTypeFilter)))))
|
||||
.ToList();
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddLabelFilter_WhenAuthorLabelPresent()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?labelFilter0=LABEL_TEST"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(AuthorLabelFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddPlayerCountFilter_WhenPlayersPresent()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?players=1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(PlayerCountFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddTextFilter_WhenTextFilterPresent()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?textFilter=test"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(TextFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddFirstUploadedFilter_WhenDateFilterPresent()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?dateFilterType=thisWeek"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(FirstUploadedFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddExcludeMoveFilter_WhenMoveEqualsFalse()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?move=false"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(ExcludeMovePackFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddMoveFilter_WhenMoveEqualsOnly()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?move=only"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(MovePackFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddCrossControlFilter_WhenCrossControlEqualsTrue()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet2;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?crosscontrol=true"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(CrossControlFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddAdventureFilter_WhenAdventureEqualsAllMust()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet3;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?adventure=allMust"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(AdventureFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddExcludeAdventureFilter_WhenAdventureEqualsNoneCan()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet3;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?adventure=noneCan"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(ExcludeAdventureFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddMovePackFilter_WhenMoveEqualsAllMust()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet3;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?move=allMust"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(MovePackFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddExcludeMoveFilter_WhenMoveEqualsNoneCan()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet3;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?move=noneCan"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(ExcludeMovePackFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddGameVersionListFilter_WhenGameFilterIsPresent()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet3;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?gameFilter[]=lbp1&gameFilter[]=lbp3"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(GameVersionListFilter)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilterFromRequest_ShouldAddResultTypeFilter_WhenResultTypeIsPresent()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet3;
|
||||
SlotsController controller = new(null!)
|
||||
{
|
||||
ControllerContext =
|
||||
{
|
||||
HttpContext = new DefaultHttpContext
|
||||
{
|
||||
Request =
|
||||
{
|
||||
QueryString = new QueryString("?resultType[]=slot&resultType[]=playlist"),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
SlotQueryBuilder queryBuilder = controller.FilterFromRequest(token);
|
||||
Assert.NotEmpty(queryBuilder.GetFilters(typeof(ResultTypeFilter)));
|
||||
}
|
||||
}
|
|
@ -41,11 +41,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\n";
|
|||
|
||||
IActionResult result = messageController.Eula();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObjectResult = result as OkObjectResult;
|
||||
Assert.NotNull(okObjectResult);
|
||||
Assert.NotNull(okObjectResult.Value);
|
||||
Assert.Equal(expected, (string)okObjectResult.Value);
|
||||
string eulaMsg = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expected, eulaMsg);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -72,11 +69,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
|
||||
IActionResult result = messageController.Eula();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObjectResult = result as OkObjectResult;
|
||||
Assert.NotNull(okObjectResult);
|
||||
Assert.NotNull(okObjectResult.Value);
|
||||
Assert.Equal(expected, (string)okObjectResult.Value);
|
||||
string eulaMsg = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expected, eulaMsg);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -92,11 +86,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
|
||||
IActionResult result = await messageController.Announce();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObjectResult = result as OkObjectResult;
|
||||
Assert.NotNull(okObjectResult);
|
||||
Assert.NotNull(okObjectResult.Value);
|
||||
Assert.Equal(expected, (string)okObjectResult.Value);
|
||||
string announceMsg = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expected, announceMsg);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -112,11 +103,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
|
||||
IActionResult result = await messageController.Announce();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObjectResult = result as OkObjectResult;
|
||||
Assert.NotNull(okObjectResult);
|
||||
Assert.NotNull(okObjectResult.Value);
|
||||
Assert.Equal(expected, (string)okObjectResult.Value);
|
||||
string announceMsg = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expected, announceMsg);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -147,11 +135,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
|
||||
IActionResult result = await messageController.Filter(new NullMailService());
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObjectResult = result as OkObjectResult;
|
||||
Assert.NotNull(okObjectResult);
|
||||
Assert.NotNull(okObjectResult.Value);
|
||||
Assert.Equal(expectedBody, (string)okObjectResult.Value);
|
||||
string filteredMessage = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expectedBody, filteredMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -173,11 +158,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
|
||||
IActionResult result = await messageController.Filter(new NullMailService());
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObjectResult = result as OkObjectResult;
|
||||
Assert.NotNull(okObjectResult);
|
||||
Assert.NotNull(okObjectResult.Value);
|
||||
Assert.Equal(expectedBody, (string)okObjectResult.Value);
|
||||
string filteredMessage = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expectedBody, filteredMessage);
|
||||
}
|
||||
|
||||
private static Mock<IMailService> getMailServiceMock()
|
||||
|
@ -189,7 +171,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void Filter_ShouldNotSendEmail_WhenMailDisabled()
|
||||
public async Task Filter_ShouldNotSendEmail_WhenMailDisabled()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
Mock<IMailService> mailMock = getMailServiceMock();
|
||||
|
@ -200,20 +182,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
ServerConfiguration.Instance.Mail.MailEnabled = false;
|
||||
CensorConfiguration.Instance.FilteredWordList = new List<string>();
|
||||
|
||||
const int expectedStatus = 200;
|
||||
const string expected = "/setemail unittest@unittest.com";
|
||||
|
||||
IActionResult result = await messageController.Filter(mailMock.Object);
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObjectResult = result as OkObjectResult;
|
||||
Assert.NotNull(okObjectResult);
|
||||
Assert.Equal(expectedStatus, okObjectResult.StatusCode);
|
||||
Assert.Equal(expected, okObjectResult.Value);
|
||||
string filteredMessage = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expected, filteredMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Filter_ShouldSendEmail_WhenMailEnabled_AndEmailNotTaken()
|
||||
public async Task Filter_ShouldSendEmail_WhenMailEnabled_AndEmailNotTaken()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -236,7 +214,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailTaken()
|
||||
public async Task Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailTaken()
|
||||
{
|
||||
List<UserEntity> users = new()
|
||||
{
|
||||
|
@ -265,7 +243,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailAlreadyVerified()
|
||||
public async Task Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailAlreadyVerified()
|
||||
{
|
||||
UserEntity unitTestUser = MockHelper.GetUnitTestUser();
|
||||
unitTestUser.EmailAddressVerified = true;
|
||||
|
@ -290,7 +268,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>." + "\nuni
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailFormatInvalid()
|
||||
public async Task Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailFormatInvalid()
|
||||
{
|
||||
UserEntity unitTestUser = MockHelper.GetUnitTestUser();
|
||||
unitTestUser.EmailAddressVerified = true;
|
||||
|
|
|
@ -0,0 +1,380 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
using LBPUnion.ProjectLighthouse.Tests.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class SlotControllerTests
|
||||
{
|
||||
#region SlotsBy
|
||||
[Fact]
|
||||
public async Task SlotsBy_ShouldReturnNotFound_WhenUserInvalid()
|
||||
{
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase();
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.SlotsBy("bytest");
|
||||
|
||||
Assert.IsType<NotFoundResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SlotsBy_ShouldFetchLevelsByUser()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 1,
|
||||
CreatorId = 2,
|
||||
},
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 2,
|
||||
CreatorId = 2,
|
||||
},
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 3,
|
||||
CreatorId = 3,
|
||||
},
|
||||
};
|
||||
List<UserEntity> users = new()
|
||||
{
|
||||
MockHelper.GetUnitTestUser(),
|
||||
new UserEntity
|
||||
{
|
||||
Username = "bytest",
|
||||
UserId = 2,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new IList[]
|
||||
{
|
||||
slots, users,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.SlotsBy("bytest");
|
||||
|
||||
const int expectedElements = 2;
|
||||
|
||||
GenericSlotResponse slotResponse = result.CastTo<OkObjectResult, GenericSlotResponse>();
|
||||
Assert.Equal(expectedElements, slotResponse.Slots.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SlotsBy_ResultsAreOrderedByFirstUploadedTimestampDescending()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 1,
|
||||
CreatorId = 2,
|
||||
FirstUploaded = 3,
|
||||
},
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 2,
|
||||
CreatorId = 2,
|
||||
FirstUploaded = 1,
|
||||
},
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 3,
|
||||
CreatorId = 2,
|
||||
FirstUploaded = 2,
|
||||
},
|
||||
};
|
||||
List<UserEntity> users = new()
|
||||
{
|
||||
MockHelper.GetUnitTestUser(),
|
||||
new UserEntity
|
||||
{
|
||||
Username = "bytest",
|
||||
UserId = 2,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new IList[]
|
||||
{
|
||||
slots, users,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.SlotsBy("bytest");
|
||||
|
||||
const int expectedElements = 3;
|
||||
const int expectedFirstSlotId = 1;
|
||||
const int expectedSecondSlotId = 3;
|
||||
const int expectedThirdSlotId = 2;
|
||||
|
||||
GenericSlotResponse slotResponse = result.CastTo<OkObjectResult, GenericSlotResponse>();
|
||||
Assert.Equal(expectedElements, slotResponse.Slots.Count);
|
||||
|
||||
Assert.Equal(expectedFirstSlotId, ((GameUserSlot)slotResponse.Slots[0]).SlotId);
|
||||
Assert.Equal(expectedSecondSlotId, ((GameUserSlot)slotResponse.Slots[1]).SlotId);
|
||||
Assert.Equal(expectedThirdSlotId, ((GameUserSlot)slotResponse.Slots[2]).SlotId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region UserSlot
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldFetch_WhenSlotIsValid()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 2,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new[]
|
||||
{
|
||||
slots,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(2);
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldNotFetch_WhenGameVersionMismatch()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 2,
|
||||
GameVersion = GameVersion.LittleBigPlanet2,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new[]
|
||||
{
|
||||
slots,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(2);
|
||||
|
||||
Assert.IsType<NotFoundResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldFetch_WhenGameVersionEqual()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanetVita;
|
||||
List<GameTokenEntity> tokens = new()
|
||||
{
|
||||
token,
|
||||
};
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 2,
|
||||
GameVersion = GameVersion.LittleBigPlanetVita,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new IList[]
|
||||
{
|
||||
slots, tokens,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController(token);
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(2);
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldFetch_WhenGameVersionIsGreater()
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = GameVersion.LittleBigPlanet3;
|
||||
List<GameTokenEntity> tokens = new()
|
||||
{
|
||||
token,
|
||||
};
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 2,
|
||||
GameVersion = GameVersion.LittleBigPlanet1,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new IList[]
|
||||
{
|
||||
slots, tokens,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController(token);
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(2);
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldReturnNotFound_WhenSlotDoesNotExist()
|
||||
{
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase();
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(20);
|
||||
|
||||
Assert.IsType<NotFoundResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldFetch_WhenSlotIsNotSubLevel()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 27,
|
||||
CreatorId = 4,
|
||||
SubLevel = false,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new[]
|
||||
{
|
||||
slots,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(27);
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldNotFetch_WhenSlotIsHidden()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 27,
|
||||
CreatorId = 4,
|
||||
Hidden = true,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new[]
|
||||
{
|
||||
slots,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(27);
|
||||
|
||||
Assert.IsType<NotFoundResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldNotFetch_WhenSlotIsWrongType()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 27,
|
||||
Type = SlotType.Developer,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new[]
|
||||
{
|
||||
slots,
|
||||
});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(27);
|
||||
|
||||
Assert.IsType<NotFoundResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserSlot_ShouldNotFetch_WhenSlotIsSubLevel()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 27,
|
||||
CreatorId = 4,
|
||||
SubLevel = true,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new []{slots,});
|
||||
SlotsController slotsController = new(db);
|
||||
slotsController.SetupTestController();
|
||||
|
||||
IActionResult result = await slotsController.UserSlot(27);
|
||||
|
||||
Assert.IsType<NotFoundResult>(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DeveloperSlot
|
||||
[Fact]
|
||||
public async Task DeveloperSlot_ShouldFetch_WhenSlotIdIsValid()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
new SlotEntity
|
||||
{
|
||||
SlotId = 1,
|
||||
InternalSlotId = 25,
|
||||
Type = SlotType.Developer,
|
||||
},
|
||||
};
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase(new[]
|
||||
{
|
||||
slots,
|
||||
});
|
||||
SlotsController controller = new(db);
|
||||
controller.SetupTestController();
|
||||
|
||||
IActionResult result = await controller.DeveloperSlot(25);
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeveloperSlot_ShouldFetch_WhenSlotIdIsInvalid()
|
||||
{
|
||||
DatabaseContext db = await MockHelper.GetTestDatabase();
|
||||
SlotsController controller = new(db);
|
||||
controller.SetupTestController();
|
||||
|
||||
IActionResult result = await controller.DeveloperSlot(26);
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
using LBPUnion.ProjectLighthouse.Tests.Helpers;
|
||||
|
@ -14,7 +15,7 @@ namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers;
|
|||
public class StatisticsControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public async void PlanetStats_ShouldReturnCorrectCounts_WhenEmpty()
|
||||
public async Task PlanetStats_ShouldReturnCorrectCounts_WhenEmpty()
|
||||
{
|
||||
await using DatabaseContext db = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -26,17 +27,13 @@ public class StatisticsControllerTests
|
|||
|
||||
IActionResult result = await statsController.PlanetStats();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? objectResult = result as OkObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
PlanetStatsResponse? response = objectResult.Value as PlanetStatsResponse;
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(expectedSlots, response.TotalSlotCount);
|
||||
Assert.Equal(expectedTeamPicks, response.TeamPickCount);
|
||||
PlanetStatsResponse statsResponse = result.CastTo<OkObjectResult, PlanetStatsResponse>();
|
||||
Assert.Equal(expectedSlots, statsResponse.TotalSlotCount);
|
||||
Assert.Equal(expectedTeamPicks, statsResponse.TeamPickCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void PlanetStats_ShouldReturnCorrectCounts_WhenNotEmpty()
|
||||
public async Task PlanetStats_ShouldReturnCorrectCounts_WhenNotEmpty()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
|
@ -64,17 +61,13 @@ public class StatisticsControllerTests
|
|||
|
||||
IActionResult result = await statsController.PlanetStats();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? objectResult = result as OkObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
PlanetStatsResponse? response = objectResult.Value as PlanetStatsResponse;
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(expectedSlots, response.TotalSlotCount);
|
||||
Assert.Equal(expectedTeamPicks, response.TeamPickCount);
|
||||
PlanetStatsResponse statsResponse = result.CastTo<OkObjectResult, PlanetStatsResponse>();
|
||||
Assert.Equal(expectedSlots, statsResponse.TotalSlotCount);
|
||||
Assert.Equal(expectedTeamPicks, statsResponse.TeamPickCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void PlanetStats_ShouldReturnCorrectCounts_WhenSlotsAreIncompatibleGameVersion()
|
||||
public async Task PlanetStats_ShouldReturnCorrectCounts_WhenSlotsAreIncompatibleGameVersion()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
|
@ -105,17 +98,13 @@ public class StatisticsControllerTests
|
|||
|
||||
IActionResult result = await statsController.PlanetStats();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? objectResult = result as OkObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
PlanetStatsResponse? response = objectResult.Value as PlanetStatsResponse;
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(expectedSlots, response.TotalSlotCount);
|
||||
Assert.Equal(expectedTeamPicks, response.TeamPickCount);
|
||||
PlanetStatsResponse statsResponse = result.CastTo<OkObjectResult, PlanetStatsResponse>();
|
||||
Assert.Equal(expectedSlots, statsResponse.TotalSlotCount);
|
||||
Assert.Equal(expectedTeamPicks, statsResponse.TeamPickCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void TotalLevelCount_ShouldReturnCorrectCount_WhenSlotsAreCompatible()
|
||||
public async Task TotalLevelCount_ShouldReturnCorrectCount_WhenSlotsAreCompatible()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
|
@ -145,14 +134,12 @@ public class StatisticsControllerTests
|
|||
|
||||
IActionResult result = await statsController.TotalLevelCount();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? objectResult = result as OkObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.Equal(expectedTotal, objectResult.Value);
|
||||
string totalSlotsResponse = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expectedTotal, totalSlotsResponse);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void TotalLevelCount_ShouldReturnCorrectCount_WhenSlotsAreNotCompatible()
|
||||
public async Task TotalLevelCount_ShouldReturnCorrectCount_WhenSlotsAreNotCompatible()
|
||||
{
|
||||
List<SlotEntity> slots = new()
|
||||
{
|
||||
|
@ -178,15 +165,11 @@ public class StatisticsControllerTests
|
|||
StatisticsController statsController = new(dbMock);
|
||||
statsController.SetupTestController();
|
||||
|
||||
const int expectedStatusCode = 200;
|
||||
const string expectedTotal = "0";
|
||||
|
||||
IActionResult result = await statsController.TotalLevelCount();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? objectResult = result as OkObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.Equal(expectedStatusCode, objectResult.StatusCode);
|
||||
Assert.Equal(expectedTotal, objectResult.Value);
|
||||
string totalSlots = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expectedTotal, totalSlots);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
using LBPUnion.ProjectLighthouse.Tests.Helpers;
|
||||
|
@ -14,7 +15,7 @@ namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers;
|
|||
public class UserControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public async void GetUser_WithValidUser_ShouldReturnUser()
|
||||
public async Task GetUser_WithValidUser_ShouldReturnUser()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -25,16 +26,12 @@ public class UserControllerTests
|
|||
|
||||
IActionResult result = await userController.GetUser("unittest");
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
GameUser? gameUser = okObject.Value as GameUser;
|
||||
Assert.NotNull(gameUser);
|
||||
GameUser gameUser = result.CastTo<OkObjectResult, GameUser>();
|
||||
Assert.Equal(expectedId, gameUser.UserId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetUser_WithInvalidUser_ShouldReturnNotFound()
|
||||
public async Task GetUser_WithInvalidUser_ShouldReturnNotFound()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -47,7 +44,7 @@ public class UserControllerTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetUserAlt_WithInvalidUser_ShouldReturnEmptyList()
|
||||
public async Task GetUserAlt_WithInvalidUser_ShouldReturnEmptyList()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -56,16 +53,12 @@ public class UserControllerTests
|
|||
|
||||
IActionResult result = await userController.GetUserAlt(new[]{"notfound",});
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
MinimalUserListResponse? userList = okObject.Value as MinimalUserListResponse? ?? default;
|
||||
Assert.NotNull(userList);
|
||||
Assert.Empty(userList.Value.Users);
|
||||
MinimalUserListResponse userList = result.CastTo<OkObjectResult, MinimalUserListResponse>();
|
||||
Assert.Empty(userList.Users);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetUserAlt_WithOnlyInvalidUsers_ShouldReturnEmptyList()
|
||||
public async Task GetUserAlt_WithOnlyInvalidUsers_ShouldReturnEmptyList()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -77,16 +70,12 @@ public class UserControllerTests
|
|||
"notfound", "notfound2", "notfound3",
|
||||
});
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
MinimalUserListResponse? userList = okObject.Value as MinimalUserListResponse? ?? default;
|
||||
Assert.NotNull(userList);
|
||||
Assert.Empty(userList.Value.Users);
|
||||
MinimalUserListResponse userList = result.CastTo<OkObjectResult, MinimalUserListResponse>();
|
||||
Assert.Empty(userList.Users);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetUserAlt_WithTwoInvalidUsers_AndOneValidUser_ShouldReturnOne()
|
||||
public async Task GetUserAlt_WithTwoInvalidUsers_AndOneValidUser_ShouldReturnOne()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -99,16 +88,12 @@ public class UserControllerTests
|
|||
"notfound", "unittest", "notfound3",
|
||||
});
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
MinimalUserListResponse? userList = okObject.Value as MinimalUserListResponse? ?? default;
|
||||
Assert.NotNull(userList);
|
||||
Assert.Single(userList.Value.Users);
|
||||
MinimalUserListResponse userList = result.CastTo<OkObjectResult, MinimalUserListResponse>();
|
||||
Assert.Single(userList.Users);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetUserAlt_WithTwoValidUsers_ShouldReturnTwo()
|
||||
public async Task GetUserAlt_WithTwoValidUsers_ShouldReturnTwo()
|
||||
{
|
||||
List<UserEntity> users = new()
|
||||
{
|
||||
|
@ -132,16 +117,12 @@ public class UserControllerTests
|
|||
"unittest2", "unittest",
|
||||
});
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
MinimalUserListResponse? userList = okObject.Value as MinimalUserListResponse? ?? default;
|
||||
Assert.NotNull(userList);
|
||||
Assert.Equal(expectedLength, userList.Value.Users.Count);
|
||||
MinimalUserListResponse userList = result.CastTo<OkObjectResult, MinimalUserListResponse>();
|
||||
Assert.Equal(expectedLength, userList.Users.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateMyPins_ShouldReturnBadRequest_WhenBodyIsInvalid()
|
||||
public async Task UpdateMyPins_ShouldReturnBadRequest_WhenBodyIsInvalid()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -155,7 +136,7 @@ public class UserControllerTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateMyPins_ShouldUpdatePins()
|
||||
public async Task UpdateMyPins_ShouldUpdatePins()
|
||||
{
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase();
|
||||
|
||||
|
@ -167,15 +148,13 @@ public class UserControllerTests
|
|||
|
||||
IActionResult result = await userController.UpdateMyPins();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
string pinsResponse = result.CastTo<OkObjectResult, string>();
|
||||
Assert.Equal(expectedPins, dbMock.Users.First().Pins);
|
||||
Assert.Equal(expectedResponse, okObject.Value);
|
||||
Assert.Equal(expectedResponse, pinsResponse);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateMyPins_ShouldNotSave_WhenPinsAreEqual()
|
||||
public async Task UpdateMyPins_ShouldNotSave_WhenPinsAreEqual()
|
||||
{
|
||||
UserEntity entity = MockHelper.GetUnitTestUser();
|
||||
entity.Pins = "1234";
|
||||
|
@ -193,10 +172,9 @@ public class UserControllerTests
|
|||
|
||||
IActionResult result = await userController.UpdateMyPins();
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
OkObjectResult? okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
string pinsResponse = result.CastTo<OkObjectResult, string>();
|
||||
|
||||
Assert.Equal(expectedPins, dbMock.Users.First().Pins);
|
||||
Assert.Equal(expectedResponse, okObject.Value);
|
||||
Assert.Equal(expectedResponse, pinsResponse);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ public class DigestMiddlewareTests
|
|||
{
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldNotComputeDigests_WhenDigestsDisabled()
|
||||
public async Task DigestMiddleware_ShouldNotComputeDigests_WhenDigestsDisabled()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldReject_WhenDigestHeaderIsMissing()
|
||||
public async Task DigestMiddleware_ShouldReject_WhenDigestHeaderIsMissing()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldReject_WhenRequestDigestInvalid()
|
||||
public async Task DigestMiddleware_ShouldReject_WhenRequestDigestInvalid()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldUseAlternateDigest_WhenPrimaryDigestInvalid()
|
||||
public async Task DigestMiddleware_ShouldUseAlternateDigest_WhenPrimaryDigestInvalid()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -150,8 +150,8 @@ public class DigestMiddlewareTests
|
|||
Assert.Equal(expectedClientDigest, context.Response.Headers["X-Digest-B"][0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldNotReject_WhenRequestingAnnounce()
|
||||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldNotReject_WhenRequestingAnnounce()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -188,7 +188,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldCalculate_WhenAuthCookieEmpty()
|
||||
public async Task DigestMiddleware_ShouldCalculate_WhenAuthCookieEmpty()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -225,7 +225,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldComputeDigestsWithNoBody_WhenDigestsEnabled()
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithNoBody_WhenDigestsEnabled()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -263,7 +263,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldComputeDigestsWithBody_WhenDigestsEnabled_AndNoResponseBody()
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithBody_WhenDigestsEnabled_AndNoResponseBody()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -301,7 +301,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldComputeDigestsWithBody_WhenDigestsEnabled_AndResponseBody()
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithBody_WhenDigestsEnabled_AndResponseBody()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -339,7 +339,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldComputeDigestsWithBody_WhenUploading()
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithBody_WhenUploading()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -377,7 +377,7 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void DigestMiddleware_ShouldCompressResponse_WhenAcceptEncodingHeaderIsPresent()
|
||||
public async Task DigestMiddleware_ShouldCompressResponse_WhenAcceptEncodingHeaderIsPresent()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
|
|
@ -17,9 +17,8 @@ namespace ProjectLighthouse.Tests.GameApiTests.Unit.Middlewares;
|
|||
[Trait("Category", "Unit")]
|
||||
public class SetLastContactMiddlewareTests
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public async void SetLastContact_ShouldAddLastContact_WhenTokenIsLBP1()
|
||||
public async Task SetLastContact_ShouldAddLastContact_WhenTokenIsLBP1()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -56,7 +55,7 @@ public class SetLastContactMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void SetLastContact_ShouldUpdateLastContact_WhenTokenIsLBP1()
|
||||
public async Task SetLastContact_ShouldUpdateLastContact_WhenTokenIsLBP1()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -106,7 +105,7 @@ public class SetLastContactMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async void SetLastContact_ShouldNotAddLastContact_WhenTokenIsNotLBP1()
|
||||
public async Task SetLastContact_ShouldNotAddLastContact_WhenTokenIsNotLBP1()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
{
|
||||
|
@ -146,5 +145,4 @@ public class SetLastContactMiddlewareTests
|
|||
LastContactEntity? lastContactEntity = dbMock.LastContacts.FirstOrDefault();
|
||||
Assert.Null(lastContactEntity);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue