-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from MrDave1999/feat/HasCapturedFlag
feat: Check if the player has captured the opposing team's flag
- Loading branch information
Showing
3 changed files
with
142 additions
and
4 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
6 changes: 4 additions & 2 deletions
6
tests/Application.Tests/Teams/FakePlayer.cs → tests/Application.Tests/FakePlayer.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
121 changes: 121 additions & 0 deletions
121
tests/Application.Tests/Players/Accounts/HasCapturedFlagTests.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,121 @@ | ||
namespace CTF.Application.Tests.Players.Accounts; | ||
|
||
public class HasCapturedFlagTests | ||
{ | ||
[SetUp] | ||
public void Init() | ||
{ | ||
Team.Alpha.Reset(); | ||
Team.Beta.Reset(); | ||
} | ||
|
||
[Test] | ||
public void HasCapturedFlag_WhenPlayerFromTheAlphaTeamHasCapturedTheFlagOfTheBetaTeam_ShouldReturnsTrue() | ||
{ | ||
// Arrange | ||
Team betaTeam = Team.Beta; | ||
var alphaTeamPlayer = new FakePlayer(id: 1, name: "Bob", team: TeamId.Alpha); | ||
var player = new PlayerInfo(alphaTeamPlayer.Entity); | ||
player.SetTeam(TeamId.Alpha); | ||
player.SetName("Bob"); | ||
betaTeam.Flag.SetCarrier(alphaTeamPlayer); | ||
|
||
// Act | ||
bool actual = player.HasCapturedFlag(); | ||
|
||
// Assert | ||
actual.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public void HasCapturedFlag_WhenPlayerFromTheBetaTeamHasCapturedTheFlagOfTheAlphaTeam_ShouldReturnsTrue() | ||
{ | ||
// Arrange | ||
Team alphaTeam = Team.Alpha; | ||
var betaTeamPlayer = new FakePlayer(id: 1, name: "Bob", team: TeamId.Beta); | ||
var player = new PlayerInfo(betaTeamPlayer.Entity); | ||
player.SetTeam(TeamId.Beta); | ||
player.SetName("Bob"); | ||
alphaTeam.Flag.SetCarrier(betaTeamPlayer); | ||
|
||
// Act | ||
bool actual = player.HasCapturedFlag(); | ||
|
||
// Assert | ||
actual.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public void HasCapturedFlag_WhenPlayerFromTheAlphaTeamHasNotCapturedTheFlagOfTheBetaTeam_ShouldReturnsFalse() | ||
{ | ||
// Arrange | ||
Team betaTeam = Team.Beta; | ||
var alphaTeamPlayer1 = new FakePlayer(id: 1, name: "Bob", team: TeamId.Alpha); | ||
var alphaTeamPlayer2 = new FakePlayer(id: 2, name: "Alice", team: TeamId.Alpha); | ||
var player = new PlayerInfo(alphaTeamPlayer1.Entity); | ||
player.SetTeam(TeamId.Alpha); | ||
player.SetName("Bob"); | ||
betaTeam.Flag.SetCarrier(alphaTeamPlayer2); | ||
|
||
// Act | ||
bool actual = player.HasCapturedFlag(); | ||
|
||
// Assert | ||
actual.Should().BeFalse(); | ||
} | ||
|
||
[Test] | ||
public void HasCapturedFlag_WhenPlayerFromTheBetaTeamHasNotCapturedTheFlagOfTheAlphaTeam_ShouldReturnsFalse() | ||
{ | ||
// Arrange | ||
Team alphaTeam = Team.Alpha; | ||
var betaTeamPlayer1 = new FakePlayer(id: 1, name: "Bob", team: TeamId.Beta); | ||
var betaTeamPlayer2 = new FakePlayer(id: 2, name: "Alice", team: TeamId.Beta); | ||
var player = new PlayerInfo(betaTeamPlayer1.Entity); | ||
player.SetTeam(TeamId.Beta); | ||
player.SetName("Bob"); | ||
alphaTeam.Flag.SetCarrier(betaTeamPlayer2); | ||
|
||
// Act | ||
bool actual = player.HasCapturedFlag(); | ||
|
||
// Assert | ||
actual.Should().BeFalse(); | ||
} | ||
|
||
[Test] | ||
public void HasCapturedFlag_WhenAlphaTeamFlagIsNotCaptured_ShouldReturnsFalse() | ||
{ | ||
// Arrange | ||
Team alphaTeam = Team.Alpha; | ||
var betaTeamPlayer = new FakePlayer(id: 1, name: "Bob", team: TeamId.Beta); | ||
var player = new PlayerInfo(betaTeamPlayer.Entity); | ||
player.SetTeam(TeamId.Beta); | ||
player.SetName("Bob"); | ||
alphaTeam.Flag.RemoveCarrier(); | ||
|
||
// Act | ||
bool actual = player.HasCapturedFlag(); | ||
|
||
// Assert | ||
actual.Should().BeFalse(); | ||
} | ||
|
||
[Test] | ||
public void HasCapturedFlag_WhenBetaTeamFlagIsNotCaptured_ShouldReturnsFalse() | ||
{ | ||
// Arrange | ||
Team betaTeam = Team.Beta; | ||
var alphaTeamPlayer = new FakePlayer(id: 1, name: "Bob", team: TeamId.Alpha); | ||
var player = new PlayerInfo(alphaTeamPlayer.Entity); | ||
player.SetTeam(TeamId.Alpha); | ||
player.SetName("Bob"); | ||
betaTeam.Flag.RemoveCarrier(); | ||
|
||
// Act | ||
bool actual = player.HasCapturedFlag(); | ||
|
||
// Assert | ||
actual.Should().BeFalse(); | ||
} | ||
} |