Skip to content

Commit

Permalink
Added methods for SwitchTimerDTO.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehanari committed Dec 31, 2023
1 parent a24c549 commit 6af92cb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,10 @@ public static PlacementType GetRandomPlacementType()
var randomIndex = random.Next(values.Length);
return (PlacementType)values.GetValue(randomIndex);

Check warning on line 170 in castledice-riptide-message-extensions-tests/ObjectCreationUtility.cs

View workflow job for this annotation

GitHub Actions / run_dlls_builder

Unboxing a possibly null value.

Check warning on line 170 in castledice-riptide-message-extensions-tests/ObjectCreationUtility.cs

View workflow job for this annotation

GitHub Actions / run_dlls_builder

Unboxing a possibly null value.
}

public static TimeSpan GetRandomTimeSpan()
{
var random = new Random();
return new TimeSpan(random.Next());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="castledice-events-logic" Version="0.0.1-dev1" />
<PackageReference Include="castledice-events-logic" Version="0.0.1-dev3-timer-switch" />
<PackageReference Include="castledice-game-data-logic" Version="0.0.1-dev5" />
<PackageReference Include="castledice-game-logic" Version="0.0.1-dev5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="castledice-events-logic" Version="0.0.1-dev1" />
<PackageReference Include="castledice-events-logic" Version="0.0.1-dev3-timer-switch" />
<PackageReference Include="castledice-game-data-logic" Version="0.0.1-dev5" />
<PackageReference Include="castledice-game-logic" Version="0.0.1-dev5" />
<PackageReference Include="RiptideNetworking.Riptide" Version="2.0.0" />
Expand Down

0 comments on commit 6af92cb

Please sign in to comment.