Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.15.3-beta0 #354

Merged
merged 7 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Gameboard.Api.Tests.Integration.Fixtures;

public sealed class TestGradingResultServiceConfiguration
{
public bool IncrementAttempts { get; set; } = true;
public Action<GameEngineGameState>? GameStateBuilder { get; set; }
public Exception? ThrowsOnGrading { get; set; }
}
Expand Down Expand Up @@ -54,7 +55,7 @@ private GameEngineGameState BuildChallengeStateFromChallenge(Data.Challenge chal
WhenCreated = challenge.StartTime,
Challenge = new GameEngineChallengeView
{

Attempts = _config.IncrementAttempts ? 1 : 0,
MaxPoints = challenge.Points,
Score = challenge.Score
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public async Task Grade_WithFirstSolve_SetsExpectedRankAndScore
(
string challengeId,
string challengeSpecId,
string gameId,
string graderKey,
string teamId,
IFixture fixture
Expand All @@ -30,6 +31,7 @@ await _testContext
{
state.Add<Data.Game>(fixture, g =>
{
g.Id = gameId;
g.Specs = state.Build<Data.ChallengeSpec>(fixture, spec =>
{
spec.Id = challengeSpecId;
Expand All @@ -39,6 +41,7 @@ await _testContext
g.Challenges = state.Build<Data.Challenge>(fixture, c =>
{
c.Id = challengeId;
c.GameId = gameId;
c.GraderKey = graderKey.ToSha256();
c.Points = 0;
c.Score = 0;
Expand Down Expand Up @@ -91,6 +94,7 @@ await _testContext
[Theory, GbIntegrationAutoData]
public async Task Grade_WithGamespaceExpired_ThrowsAndLogsEvent
(
string gameId,
string challengeId,
string challengeSpecId,
string sponsorId,
Expand All @@ -108,6 +112,7 @@ await _testContext.WithDataState(state =>
state.Add<Data.Sponsor>(fixture, s => s.Id = sponsorId);
state.Add<Data.Game>(fixture, g =>
{
g.Id = gameId;
g.Players = new List<Data.Player>
{
new()
Expand All @@ -121,6 +126,7 @@ await _testContext.WithDataState(state =>
EndTime = challengeEndTime,
StartTime = challengeStartTime,
SpecId = challengeSpecId,
GameId = gameId
}
},
SponsorId = sponsorId,
Expand Down Expand Up @@ -153,10 +159,10 @@ await _testContext.WithDataState(state =>
.ChallengeEvents
.AsNoTracking()
.Where(ev => ev.ChallengeId == challengeId)
.Where(ev => ev.Type == ChallengeEventType.SubmissionRejectedGamespaceExpired)
.OrderByDescending(ev => ev.Timestamp)
.ToArrayAsync();

challengeEvents.Length.ShouldBeGreaterThan(0);
challengeEvents.First().Type.ShouldBe(ChallengeEventType.SubmissionRejectedGamespaceExpired);
challengeEvents.Length.ShouldBe(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
namespace Gameboard.Api.Tests.Unit;

public class PlayerServiceCalculateSessionWindowTests
{
[Theory, GameboardAutoData]
public void CalculateSessionWindow_WithLateStart_ShortensSession(DateTimeOffset sessionStart)
{
// given a session starting now for a game with a longer session time
// than is remaining in the execution period
var gameEnd = sessionStart.AddHours(1);

var game = new Data.Game
{
GameEnd = gameEnd,
SessionMinutes = 120
};
var sut = PlayerServiceTestHelpers.GetTestableSut();

// when the session length properties are calculated
var result = sut.CalculateSessionWindow(game, sessionStart);

// then session end should be equal to the game end
result.End.ShouldBe(gameEnd);
}

[Theory, GameboardAutoData]
public void CalculateSessionWindow_WithNoLateStart_PreservesSessionLength(DateTimeOffset sessionStart)
{
// given a session starting now for a game with a longer session time
// than is remaining in the execution period
var gameEnd = sessionStart.AddHours(2);
var sessionEnd = sessionStart.AddHours(1);

var game = new Data.Game
{
GameEnd = gameEnd,
SessionMinutes = 60
};
var sut = PlayerServiceTestHelpers.GetTestableSut();

// when the session length properties are calculated
var result = sut.CalculateSessionWindow(game, sessionStart);

// then session end should be equal to the game end
result.End.ShouldBe(sessionEnd);
}

[Theory, GameboardAutoData]
public void CalculateSessionWindow_WithLateStart_MarksLateStart(DateTimeOffset sessionStart)
{
// given a session starting now for a game with a longer session time
// than is remaining in the execution period
var gameEnd = sessionStart.AddHours(1);

var game = new Data.Game
{
GameEnd = gameEnd,
SessionMinutes = 120
};
var sut = PlayerServiceTestHelpers.GetTestableSut();

// when the session length properties are calculated
var result = sut.CalculateSessionWindow(game, sessionStart);

// the session end should be equal to the game end
result.IsLateStart.ShouldBeTrue();
}

[Theory, GameboardAutoData]
public void CalculateSessionWindow_WithNoLateStart_MarksNoLateStart(DateTimeOffset sessionStart)
{
// given a session starting now for a game with a longer session time
// than is remaining in the execution period
var gameEnd = sessionStart.AddHours(2);

var game = new Data.Game
{
GameEnd = gameEnd,
SessionMinutes = 60
};
var sut = PlayerServiceTestHelpers.GetTestableSut();

// when the session length properties are calculated
var result = sut.CalculateSessionWindow(game, sessionStart);

// the session end should be equal to the game end
result.IsLateStart.ShouldBeFalse();
}
}
3 changes: 2 additions & 1 deletion src/Gameboard.Api/Data/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Player : IEntity
public PlayerRole Role { get; set; }
public DateTimeOffset SessionBegin { get; set; }
public DateTimeOffset SessionEnd { get; set; }
public int SessionMinutes { get; set; }
public double SessionMinutes { get; set; }
public int Rank { get; set; }
public int Score { get; set; }
public long Time { get; set; }
Expand All @@ -32,6 +32,7 @@ public class Player : IEntity
public User User { get; set; }
public Game Game { get; set; }
public DateTimeOffset WhenCreated { get; set; }
public bool IsLateStart { get; set; }

// navigation properties
public ICollection<Challenge> Challenges { get; set; } = new List<Challenge>();
Expand Down
3 changes: 2 additions & 1 deletion src/Gameboard.Api/Data/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public enum ChallengeEventType
GamespaceOn,
GamespaceOff,
Submission,
SubmissionRejectedGamespaceExpired
SubmissionRejectedGamespaceExpired,
SubmissionRejectedGameEnded
}

public enum ChallengeResult
Expand Down
Loading
Loading