diff --git a/src/Application/Common/Resources/Messages.Designer.cs b/src/Application/Common/Resources/Messages.Designer.cs index 120a145b..ad17f5f2 100644 --- a/src/Application/Common/Resources/Messages.Designer.cs +++ b/src/Application/Common/Resources/Messages.Designer.cs @@ -114,6 +114,15 @@ internal static string InvalidSkin { } } + /// + /// Looks up a localized string similar to Invalid team has been passed. Should be Alpha = 0, Beta = 1 or NoTeam = 255. + /// + internal static string InvalidTeam { + get { + return ResourceManager.GetString("InvalidTeam", resourceCulture); + } + } + /// /// Looks up a localized string similar to Invalid weapon has been passed. /// diff --git a/src/Application/Common/Resources/Messages.resx b/src/Application/Common/Resources/Messages.resx index 7b9f2f00..f70b5d9a 100644 --- a/src/Application/Common/Resources/Messages.resx +++ b/src/Application/Common/Resources/Messages.resx @@ -135,6 +135,9 @@ Skin ID must be between 0 and 311 + + Invalid team has been passed. Should be Alpha = 0, Beta = 1 or NoTeam = 255 + Invalid weapon has been passed diff --git a/src/Application/Players/Accounts/PlayerInfo.cs b/src/Application/Players/Accounts/PlayerInfo.cs index 2f5acd2d..d2d069ae 100644 --- a/src/Application/Players/Accounts/PlayerInfo.cs +++ b/src/Application/Players/Accounts/PlayerInfo.cs @@ -50,6 +50,7 @@ public PlayerInfo() { } public RoleId RoleId { get; private set; } = RoleId.Basic; public int SkinId { get; private set; } = NoSkin; public RankId RankId { get; private set; } = RankId.Noob; + public Team Team { get; private set; } = Team.None; public DateTime CreatedAt { get; private set; } = DateTime.UtcNow; public DateTime LastConnection { get; private set; } = DateTime.UtcNow; @@ -149,6 +150,25 @@ public Result SetSkin(int id) return Result.Success(); } + public Result SetTeam(TeamId id) + { + Result result = id switch + { + TeamId.Alpha => Result.Success(Team.Alpha), + TeamId.Beta => Result.Success(Team.Beta), + TeamId.NoTeam => Result.Success(Team.None), + _ => Result.Failure() + }; + + if (result.IsSuccess) + { + Team = result.Value; + return Result.Success(); + } + + return Result.Failure(Messages.InvalidTeam); + } + public bool CanMoveUpToNextRank() { IRank currentRank = RankCollection.GetById(RankId).Value; diff --git a/src/Application/Teams/Flags/Flag.cs b/src/Application/Teams/Flags/Flag.cs index 7b697f13..2e60d4f7 100644 --- a/src/Application/Teams/Flags/Flag.cs +++ b/src/Application/Teams/Flags/Flag.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams.Flags; -internal class Flag +public class Flag { public required FlagModel Model { get; init; } public required FlagIcon Icon { get; init; } diff --git a/src/Application/Teams/Flags/FlagIcon.cs b/src/Application/Teams/Flags/FlagIcon.cs index 9b0aff66..08fbaba2 100644 --- a/src/Application/Teams/Flags/FlagIcon.cs +++ b/src/Application/Teams/Flags/FlagIcon.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams.Flags; -internal enum FlagIcon +public enum FlagIcon { None = 1, Red = 20, diff --git a/src/Application/Teams/Flags/FlagModel.cs b/src/Application/Teams/Flags/FlagModel.cs index d9c9270c..eb830969 100644 --- a/src/Application/Teams/Flags/FlagModel.cs +++ b/src/Application/Teams/Flags/FlagModel.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams.Flags; -internal enum FlagModel +public enum FlagModel { None = 0, Red = 19306, diff --git a/src/Application/Teams/Flags/FlagStatus.cs b/src/Application/Teams/Flags/FlagStatus.cs index 8c9bb4ec..54177ef1 100644 --- a/src/Application/Teams/Flags/FlagStatus.cs +++ b/src/Application/Teams/Flags/FlagStatus.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams.Flags; -internal enum FlagStatus +public enum FlagStatus { /// /// Indicates that the flag is on its base. diff --git a/src/Application/Teams/SkinTeamId.cs b/src/Application/Teams/SkinTeamId.cs index 727ac21e..5b52d021 100644 --- a/src/Application/Teams/SkinTeamId.cs +++ b/src/Application/Teams/SkinTeamId.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams; -internal enum SkinTeamId +public enum SkinTeamId { NoTeam = 0, Alpha = 170, diff --git a/src/Application/Teams/Team.cs b/src/Application/Teams/Team.cs index 6952696d..e3ab817f 100644 --- a/src/Application/Teams/Team.cs +++ b/src/Application/Teams/Team.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams; -internal class Team +public class Team { public static readonly Team Alpha; public static readonly Team Beta; diff --git a/src/Application/Teams/TeamMembers.cs b/src/Application/Teams/TeamMembers.cs index ffe9d146..b5da50e5 100644 --- a/src/Application/Teams/TeamMembers.cs +++ b/src/Application/Teams/TeamMembers.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams; -internal class TeamMembers : IEnumerable +public class TeamMembers : IEnumerable { private readonly Dictionary _players = []; public bool IsEmpty() => _players.Count == 0; diff --git a/src/Application/Teams/TeamSounds.cs b/src/Application/Teams/TeamSounds.cs index 51257901..52006142 100644 --- a/src/Application/Teams/TeamSounds.cs +++ b/src/Application/Teams/TeamSounds.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams; -internal class TeamSounds +public class TeamSounds { public string FlagDropped { get; init; } = string.Empty; public string FlagReturned { get; init; } = string.Empty; diff --git a/src/Application/Teams/TeamStatsPerRound.cs b/src/Application/Teams/TeamStatsPerRound.cs index e3816701..9e0cb780 100644 --- a/src/Application/Teams/TeamStatsPerRound.cs +++ b/src/Application/Teams/TeamStatsPerRound.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Teams; -internal class TeamStatsPerRound +public class TeamStatsPerRound { public int Score { get; private set; } public int Kills { get; private set; } diff --git a/tests/Application.Tests/Players/Accounts/SelectedTeamTests.cs b/tests/Application.Tests/Players/Accounts/SelectedTeamTests.cs new file mode 100644 index 00000000..01b37d9e --- /dev/null +++ b/tests/Application.Tests/Players/Accounts/SelectedTeamTests.cs @@ -0,0 +1,43 @@ +namespace CTF.Application.Tests.Players.Accounts; + +public class SelectedTeamTests +{ + [TestCase(-1)] + [TestCase(-2)] + [TestCase(2)] + [TestCase(3)] + [TestCase(4)] + [TestCase(254)] + [TestCase(256)] + public void SetTeam_WhenTeamIsInvalid_ShouldReturnsFailureResult(int id) + { + // Arrange + var player = new PlayerInfo(); + TeamId teamId = (TeamId)id; + var expectedMessage = Messages.InvalidTeam; + + // Act + Result result = player.SetTeam(teamId); + + // Asserts + result.IsSuccess.Should().BeFalse(); + result.Message.Should().Be(expectedMessage); + player.Team.Id.Should().Be(TeamId.NoTeam); + } + + [TestCase(TeamId.Alpha)] + [TestCase(TeamId.Beta)] + [TestCase(TeamId.NoTeam)] + public void SetTeam_WhenTeamIsValid_ShouldReturnsSuccessResult(TeamId teamId) + { + // Arrange + var player = new PlayerInfo(); + + // Act + Result result = player.SetTeam(teamId); + + // Asserts + result.IsSuccess.Should().BeTrue(); + player.Team.Id.Should().Be(teamId); + } +}