Skip to content

Commit

Permalink
refactor: rename Prepare to Ready
Browse files Browse the repository at this point in the history
  • Loading branch information
aa89227 committed May 7, 2024
1 parent 3515673 commit ef1c72e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
28 changes: 0 additions & 28 deletions Application/Usecases/PlayerPreparedUsecase.cs

This file was deleted.

28 changes: 28 additions & 0 deletions Application/Usecases/PlayerReadyUsecase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Application.Common;
using Domain.Common;

namespace Application.Usecases;

public record PlayerReadyRequest(string GameId, string PlayerId)
: Request(GameId, PlayerId);

public record PlayerReadyResponse(IReadOnlyList<DomainEvent> Events) : CommandResponse(Events);

public class PlayerReadyUsecase(ICommandRepository repository, IEventBus<DomainEvent> eventBus)
: CommandUsecase<PlayerReadyRequest, PlayerReadyResponse>(repository, eventBus)
{
public override async Task ExecuteAsync(PlayerReadyRequest request, IPresenter<PlayerReadyResponse> presenter)
{
//查
var game = Repository.FindGameById(request.GameId).ToDomain();

//改
game.PlayerReady(request.PlayerId);

//存
Repository.Save(game);

//推
await presenter.PresentAsync(new PlayerReadyResponse(game.DomainEvents));
}
}
4 changes: 2 additions & 2 deletions Domain/Monopoly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ public void SelectLocation(string playerId, int locationID)
///
/// </summary>
/// <param name="playerId"></param>
public void PlayerPrepare(string playerId)
public void PlayerReady(string playerId)
{
if (GameStage == GameStage.Preparing)
{
Player player = GetPlayer(playerId);

AddDomainEvent(player.Parpare());
AddDomainEvent(player.Ready());
}

}
Expand Down
2 changes: 1 addition & 1 deletion Domain/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ internal bool CanNotSelectDirection(Map.Direction d)
return d == chess.CurrentDirection.Opposite();
}

internal DomainEvent Parpare()
internal DomainEvent Ready()
{
if (RoleId is null || LocationId == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions Server/Hubs/MonopolyHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ await usecase.ExecuteAsync(
);
}

public async Task PlayerReady(PlayerPreparedUsecase usecase, SignalrDefaultPresenter<PlayerPreparedResponse> presenter)
public async Task PlayerReady(PlayerReadyUsecase usecase, SignalrDefaultPresenter<PlayerReadyResponse> presenter)
{
await usecase.ExecuteAsync(
new PlayerPreparedRequest(GameId, PlayerId),
new PlayerReadyRequest(GameId, PlayerId),
presenter
);
}
Expand Down
8 changes: 4 additions & 4 deletions Test/DomainTests/Testcases/PraparedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void 玩家成功準備()
.Build();

// Act
monopoly.PlayerPrepare(B.Id);
monopoly.PlayerReady(B.Id);

// Assert
Assert.AreEqual(B.preparedState, monopoly.Players.First(p => p.Id == B.Id).State);
Expand Down Expand Up @@ -58,7 +58,7 @@ public void 玩家取消準備()
.Build();

// Act
monopoly.PlayerPrepare(A.Id);
monopoly.PlayerReady(A.Id);

// Assert
Assert.AreEqual(A.preparingState, monopoly.Players.First(p => p.Id == A.Id).State);
Expand Down Expand Up @@ -95,7 +95,7 @@ public void 玩家未選擇位置按下準備()
.Build();

// Act
monopoly.PlayerPrepare(B.Id);
monopoly.PlayerReady(B.Id);

// Assert
Assert.AreEqual(B.preparingState, monopoly.Players.First(p => p.Id == B.Id).State);
Expand Down Expand Up @@ -131,7 +131,7 @@ public void 玩家未選擇角色按下準備()
.Build();

// Act
monopoly.PlayerPrepare(B.Id);
monopoly.PlayerReady(B.Id);

// Assert
Assert.AreEqual(B.preparingState, monopoly.Players.First(p => p.Id == B.Id).State);
Expand Down

0 comments on commit ef1c72e

Please sign in to comment.