diff --git a/castledice-riptide-message-extensions-tests/MessageExtensionsTests.cs b/castledice-riptide-message-extensions-tests/MessageExtensionsTests.cs index 7302563..ee32a29 100644 --- a/castledice-riptide-message-extensions-tests/MessageExtensionsTests.cs +++ b/castledice-riptide-message-extensions-tests/MessageExtensionsTests.cs @@ -8,6 +8,18 @@ namespace castledice_riptide_dto_adapters_tests; public class MessageExtensionsTests { + [Fact] + public void AddSwitchTimerDTO_ShouldAddSwitchTimerDTOToMessage() + { + var DTOToSend = new SwitchTimerDTO(GetRandomTimeSpan(), new Random().Next(), new Random().Next(1, 2) == 1); + var message = GetEmptyMessage(); + + message.AddSwitchTimerDTO(DTOToSend); + var receivedDTO = message.GetSwitchTimerDTO(); + + Assert.Equal(DTOToSend, receivedDTO); + } + [Fact] public void AddInitializePlayerDTO_ShouldAddInitializePlayerDTOToMessage() { diff --git a/castledice-riptide-message-extensions-tests/ObjectCreationUtility.cs b/castledice-riptide-message-extensions-tests/ObjectCreationUtility.cs index 8f63000..6edc648 100644 --- a/castledice-riptide-message-extensions-tests/ObjectCreationUtility.cs +++ b/castledice-riptide-message-extensions-tests/ObjectCreationUtility.cs @@ -169,4 +169,10 @@ public static PlacementType GetRandomPlacementType() var randomIndex = random.Next(values.Length); return (PlacementType)values.GetValue(randomIndex); } + + public static TimeSpan GetRandomTimeSpan() + { + var random = new Random(); + return new TimeSpan(random.Next()); + } } \ No newline at end of file diff --git a/castledice-riptide-message-extensions-tests/castledice-riptide-message-extensions-tests.csproj b/castledice-riptide-message-extensions-tests/castledice-riptide-message-extensions-tests.csproj index 3eb6f08..8590d8f 100644 --- a/castledice-riptide-message-extensions-tests/castledice-riptide-message-extensions-tests.csproj +++ b/castledice-riptide-message-extensions-tests/castledice-riptide-message-extensions-tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/castledice-riptide-message-extensions/Extensions/MessageExtensions.cs b/castledice-riptide-message-extensions/Extensions/MessageExtensions.cs index 660cc85..5a8397a 100644 --- a/castledice-riptide-message-extensions/Extensions/MessageExtensions.cs +++ b/castledice-riptide-message-extensions/Extensions/MessageExtensions.cs @@ -8,6 +8,21 @@ namespace castledice_riptide_dto_adapters.Extensions; public static class MessageExtensions { + public static void AddSwitchTimerDTO(this Message message, SwitchTimerDTO dto) + { + message.AddInt(dto.PlayerId); + message.AddTimeSpan(dto.TimeLeft); + message.AddBool(dto.Switch); + } + + public static SwitchTimerDTO GetSwitchTimerDTO(this Message message) + { + var playerId = message.GetInt(); + var timeLeft = message.GetTimeSpan(); + var switchTimer = message.GetBool(); + return new SwitchTimerDTO(timeLeft, playerId, switchTimer); + } + public static void AddInitializePlayerDTO(this Message message, InitializePlayerDTO dto) { message.AddString(dto.VerificationKey); diff --git a/castledice-riptide-message-extensions/castledice-riptide-message-extensions.csproj b/castledice-riptide-message-extensions/castledice-riptide-message-extensions.csproj index a42f72f..2345999 100644 --- a/castledice-riptide-message-extensions/castledice-riptide-message-extensions.csproj +++ b/castledice-riptide-message-extensions/castledice-riptide-message-extensions.csproj @@ -9,7 +9,7 @@ - +