-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into recent-activity
- Loading branch information
Showing
7 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ReviewControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
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.Token; | ||
using LBPUnion.ProjectLighthouse.Types.Serialization; | ||
using LBPUnion.ProjectLighthouse.Types.Users; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Xunit; | ||
|
||
namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers; | ||
|
||
public class ReviewControllerTests | ||
{ | ||
private static async Task InsertTestData(DatabaseContext database) | ||
{ | ||
database.Slots.Add(new SlotEntity | ||
{ | ||
SlotId = 1, | ||
CreatorId = 1, | ||
GameVersion = GameVersion.LittleBigPlanet3, | ||
}); | ||
|
||
database.Slots.Add(new SlotEntity | ||
{ | ||
SlotId = 2, | ||
CreatorId = 1, | ||
GameVersion = GameVersion.LittleBigPlanet2, | ||
}); | ||
|
||
database.Reviews.Add(new ReviewEntity | ||
{ | ||
ReviewId = 1, | ||
ReviewerId = 1, | ||
SlotId = 1, | ||
}); | ||
|
||
database.Reviews.Add(new ReviewEntity | ||
{ | ||
ReviewId = 2, | ||
ReviewerId = 1, | ||
SlotId = 2, | ||
}); | ||
await database.SaveChangesAsync(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(GameVersion.LittleBigPlanet2, 1)] | ||
[InlineData(GameVersion.LittleBigPlanet3, 2)] | ||
public async Task ReviewsBy_ShouldNotList_HigherGameVersions(GameVersion version, int expected) | ||
{ | ||
GameTokenEntity token = MockHelper.GetUnitTestToken(); | ||
token.GameVersion = version; | ||
DatabaseContext database = await MockHelper.GetTestDatabase(new List<GameTokenEntity> | ||
{ | ||
token, | ||
}); | ||
|
||
await InsertTestData(database); | ||
|
||
ReviewController controller = new(database); | ||
controller.SetupTestController(token); | ||
|
||
IActionResult response = await controller.ReviewsBy("unittest"); | ||
ReviewResponse review = response.CastTo<OkObjectResult, ReviewResponse>(); | ||
|
||
Assert.Equal(expected, review.Reviews.Count); | ||
Assert.True(review.Reviews.All(r => database.Slots.FirstOrDefault(s => s.SlotId == r.Slot.SlotId)?.GameVersion <= version)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(GameVersion.LittleBigPlanet2, 2, 1)] | ||
[InlineData(GameVersion.LittleBigPlanet2, 1, 0)] | ||
[InlineData(GameVersion.LittleBigPlanet3, 2, 1)] | ||
[InlineData(GameVersion.LittleBigPlanet3, 1, 1)] | ||
public async Task ReviewsFor_ShouldNotList_HigherGameVersions(GameVersion version, int slotId, int expected) | ||
{ | ||
GameTokenEntity token = MockHelper.GetUnitTestToken(); | ||
token.GameVersion = version; | ||
DatabaseContext database = await MockHelper.GetTestDatabase(new List<GameTokenEntity> | ||
{ | ||
token, | ||
}); | ||
|
||
await InsertTestData(database); | ||
|
||
ReviewController controller = new(database); | ||
controller.SetupTestController(token); | ||
|
||
IActionResult response = await controller.ReviewsFor(slotId); | ||
ReviewResponse review = response.CastTo<OkObjectResult, ReviewResponse>(); | ||
|
||
Assert.Equal(expected, review.Reviews.Count); | ||
Assert.True(review.Reviews.All(r => database.Slots.FirstOrDefault(s => s.SlotId == r.Slot.SlotId)?.GameVersion <= version)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters