From 4667c9296ae3025312c6266fec2c058194509bd8 Mon Sep 17 00:00:00 2001 From: aa89227 Date: Thu, 20 Jun 2024 22:17:06 +0800 Subject: [PATCH] refactor: remove gameStage of monopoly aggregate --- .../Common/IRepository.cs | 5 +- .../Common/RepositoryExtensions.cs | 50 +------------ .../DataModels/MonopolyDataModel.cs | 10 +-- .../Usecases/BidUsecase.cs | 2 +- .../Usecases/BuildHouseUsecase.cs | 2 +- .../Usecases/ChooseDirectionUsecase.cs | 2 +- .../Usecases/EndAuctionUsecase.cs | 2 +- .../Usecases/EndRoundUsecase.cs | 2 +- .../Usecases/MortgageUsecase.cs | 2 +- .../Usecases/PayTollUsecase.cs | 2 +- .../Usecases/PlayerBuyLandUsecase.cs | 2 +- .../Usecases/PlayerRollDiceUsecase.cs | 2 +- .../Usecases/RedeemUsecase.cs | 2 +- .../Usecases/SettlementUsecase.cs | 2 +- .../Pages/Ready/ReadyPage.razor.cs | 15 +++- .../Builders/MonopolyBuilder.cs | 71 ++++++++----------- .../Monopoly.DomainLayer.Domain/GameStage.cs | 6 -- .../MonopolyAggregate.cs | 4 +- .../Repositories/InMemoryRepository.cs | 11 +-- .../Testcases/AuctionTest.cs | 2 - .../Testcases/MortgageTest.cs | 3 - .../Testcases/PayTollTest.cs | 5 -- .../Testcases/RollDiceTest.cs | 5 -- .../Testcases/SelectDirectionTest.cs | 6 -- .../AcceptanceTests/SelectDirectionTest.cs | 4 +- .../Usecases/MockPlayerRollDiceUsecase.cs | 2 +- .../Utils.cs | 12 +--- 27 files changed, 73 insertions(+), 160 deletions(-) delete mode 100644 DomainLayer/Monopoly.DomainLayer.Domain/GameStage.cs diff --git a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/IRepository.cs b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/IRepository.cs index 6e904eb..8953d64 100644 --- a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/IRepository.cs +++ b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/IRepository.cs @@ -1,13 +1,14 @@ using Monopoly.ApplicationLayer.Application.DataModels; +using Monopoly.DomainLayer.Domain; namespace Monopoly.ApplicationLayer.Application.Common; public interface IRepository { - public MonopolyDataModel FindGameById(string id); + public MonopolyAggregate FindGameById(string id); public string[] GetRooms(); public bool IsExist(string id); - public string Save(MonopolyDataModel monopolyDataModel); + public string Save(MonopolyAggregate monopoly); } public interface ICommandRepository : IRepository diff --git a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/RepositoryExtensions.cs b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/RepositoryExtensions.cs index 0c20b4f..0254fd0 100644 --- a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/RepositoryExtensions.cs +++ b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Common/RepositoryExtensions.cs @@ -6,7 +6,6 @@ using Block = Monopoly.ApplicationLayer.Application.DataModels.Block; using Chess = Monopoly.ApplicationLayer.Application.DataModels.Chess; using CurrentPlayerState = Monopoly.ApplicationLayer.Application.DataModels.CurrentPlayerState; -using GameStage = Monopoly.DomainLayer.Domain.GameStage; using Jail = Monopoly.DomainLayer.Domain.Jail; using Land = Monopoly.DomainLayer.Domain.Land; using LandContract = Monopoly.ApplicationLayer.Application.DataModels.LandContract; @@ -21,18 +20,12 @@ namespace Monopoly.ApplicationLayer.Application.Common; public static class RepositoryExtensions { - public static string Save(this IRepository repository, MonopolyAggregate domainMonopolyAggregate) - { - var monopoly = domainMonopolyAggregate.ToApplication(); - return repository.Save(monopoly); - } - /// /// (Monopoly) Domain to Application /// /// /// - private static MonopolyDataModel ToApplication(this MonopolyAggregate domainMonopolyAggregate) + public static MonopolyDataModel ToApplication(this MonopolyAggregate domainMonopolyAggregate) { var players = domainMonopolyAggregate.Players.Select(player => { @@ -58,18 +51,6 @@ private static MonopolyDataModel ToApplication(this MonopolyAggregate domainMono Map map = new(domainMonopolyAggregate.Map.Id, domainMonopolyAggregate.Map.Blocks .Select(row => { return row.Select(block => block?.ToApplicationBlock()).ToArray(); }).ToArray() ); - var gamestage = domainMonopolyAggregate.GameStage switch - { - GameStage.Ready => DataModels.GameStage.Preparing, - GameStage.Gaming => DataModels.GameStage.Gaming, - _ => throw new NotImplementedException(), - }; - if (gamestage == DataModels.GameStage.Preparing) - { - return new MonopolyDataModel(domainMonopolyAggregate.Id, [..players], map, domainMonopolyAggregate.HostId, null!, - null!, gamestage); - } - var currentPlayer = domainMonopolyAggregate.Players.First(player => player.Id == domainMonopolyAggregate.CurrentPlayerState.PlayerId); @@ -90,8 +71,8 @@ domainMonopolyAggregate.CurrentPlayerState.Auction is null .Select(land => new LandHouse(land.Id, land.House)).ToArray(); - return new DataModels.MonopolyDataModel(domainMonopolyAggregate.Id, players, map, domainMonopolyAggregate.HostId, - currentPlayerState, LandHouses, gamestage); + return new MonopolyDataModel(domainMonopolyAggregate.Id, players, map, domainMonopolyAggregate.HostId, + currentPlayerState, LandHouses); } private static Block ToApplicationBlock(this DomainLayer.Domain.Block domainBlock) @@ -137,16 +118,6 @@ public static MonopolyAggregate ToDomain(this MonopolyDataModel monopolyDataMode .WithRole(p.RoleId) .WithState(p.PlayerState) )); - builder.WithGameStage(monopolyDataModel.GameStage switch - { - DataModels.GameStage.Preparing => GameStage.Ready, - DataModels.GameStage.Gaming => GameStage.Gaming, - _ => throw new NotImplementedException(), - }); - if (monopolyDataModel.GameStage == DataModels.GameStage.Preparing) - { - return builder.Build(); - } var cps = monopolyDataModel.CurrentPlayerState; if (cps.Auction is null) @@ -177,21 +148,6 @@ private static PlayerBuilder WithLandContracts(this PlayerBuilder builder, return builder; } - private static DomainLayer.Domain.Block? ToDomainBlock(this Block? block) - { - return block switch - { - DataModels.StartPoint startBlock => new StartPoint(startBlock.Id), - DataModels.Station stationBlock => new Station(stationBlock.Id), - DataModels.Land landBlock => new Land(landBlock.Id), - DataModels.ParkingLot parkingLotBlock => new ParkingLot(parkingLotBlock.Id), - DataModels.Jail prisonBlock => new Jail(prisonBlock.Id), - DataModels.Road roadBlock => new Road(roadBlock.Id), - EmptyBlock => null, - _ => throw new NotImplementedException(), - }; - } - private static Direction ToApplicationDirection(this DomainLayer.Domain.Map.Direction direction) { return direction switch diff --git a/ApplicationLayer/Monopoly.ApplicationLayer.Application/DataModels/MonopolyDataModel.cs b/ApplicationLayer/Monopoly.ApplicationLayer.Application/DataModels/MonopolyDataModel.cs index 7c98fc1..87f6edf 100644 --- a/ApplicationLayer/Monopoly.ApplicationLayer.Application/DataModels/MonopolyDataModel.cs +++ b/ApplicationLayer/Monopoly.ApplicationLayer.Application/DataModels/MonopolyDataModel.cs @@ -2,7 +2,7 @@ namespace Monopoly.ApplicationLayer.Application.DataModels; -public record MonopolyDataModel(string Id, Player[] Players, Map Map, string HostId, CurrentPlayerState CurrentPlayerState, LandHouse[] LandHouses, GameStage GameStage); +public record MonopolyDataModel(string Id, Player[] Players, Map Map, string HostId, CurrentPlayerState CurrentPlayerState, LandHouse[] LandHouses); public record Player(string Id, decimal Money, Chess Chess, LandContract[] LandContracts, PlayerState PlayerState, int BankruptRounds, int LocationId, string? RoleId); public record CurrentPlayerState(string PlayerId, bool IsPayToll, bool IsBoughtLand, bool IsUpgradeLand, Auction? Auction, int RemainingSteps, bool HadSelectedDirection); @@ -34,10 +34,4 @@ public record StartPoint(string Id) : Block(Id); public record Station(string Id) : Land(Id); -public record Road(string Id) : Block(Id); - -public enum GameStage -{ - Preparing, - Gaming, -} \ No newline at end of file +public record Road(string Id) : Block(Id); \ No newline at end of file diff --git a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/BidUsecase.cs b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/BidUsecase.cs index bdc7de8..4d65d4c 100644 --- a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/BidUsecase.cs +++ b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/BidUsecase.cs @@ -15,7 +15,7 @@ public override async Task ExecuteAsync(BidRequest request, IPresenter presenter, CancellationToken cancellationToken = default) { //查 - var game = Repository.FindGameById(request.GameId).ToDomain(); + var game = Repository.FindGameById(request.GameId); //改 game.PlayerSelectDirection(request.PlayerId, request.Direction); //存 diff --git a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/EndAuctionUsecase.cs b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/EndAuctionUsecase.cs index 3a658ea..d17bd95 100644 --- a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/EndAuctionUsecase.cs +++ b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/EndAuctionUsecase.cs @@ -15,7 +15,7 @@ public override async Task ExecuteAsync(EndAuctionRequest request, IPresenter presenter, CancellationToken cancellationToken = default) { //查 - var game = Repository.FindGameById(request.GameId).ToDomain(); + var game = Repository.FindGameById(request.GameId); //改 game.PlayerRollDice(request.PlayerId); diff --git a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/RedeemUsecase.cs b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/RedeemUsecase.cs index 824e7fb..cc1cd38 100644 --- a/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/RedeemUsecase.cs +++ b/ApplicationLayer/Monopoly.ApplicationLayer.Application/Usecases/RedeemUsecase.cs @@ -15,7 +15,7 @@ public override async Task ExecuteAsync(RedeemRequest request, IPresenter LandHouses { get; private set; } = new(); - internal GameStage GameStage { get; private set; } public MonopolyBuilder() { PlayerBuilders = new(); - GameStage = GameStage.Ready; } public MonopolyBuilder WithId(string id) @@ -52,7 +50,8 @@ public MonopolyBuilder WithPlayer(string id, Expression>? expression = null) + public MonopolyBuilder WithCurrentPlayer(string id, + Expression>? expression = null) { var currentPlayerStateBuilder = new CurrentPlayerStateBuilder(id); if (expression is not null) @@ -60,6 +59,7 @@ public MonopolyBuilder WithCurrentPlayer(string id, Expression p.Id == CurrentPlayerStateBuilder.PlayerId); + var landContract = currentPlayer.FindLandContract(LandId) ?? + throw new InvalidOperationException("LandContract not found"); + var highestBidder = players.FirstOrDefault(p => p.Id == HighestBidder); + auction = new Auction(landContract, highestBidder, HighestPrice); + } + + foreach (var landHouse in LandHouses) { - Auction? auction = null; - if (CurrentPlayerStateBuilder.HasAuction) - { - var (LandId, HighestBidder, HighestPrice) = CurrentPlayerStateBuilder.Auction; - var currentPlayer = players.First(p => p.Id == CurrentPlayerStateBuilder.PlayerId); - var landContract = currentPlayer.FindLandContract(LandId) ?? throw new InvalidOperationException("LandContract not found"); - var highestBidder = players.FirstOrDefault(p => p.Id == HighestBidder); - auction = new Auction(landContract, highestBidder, HighestPrice); - } - foreach (var landHouse in LandHouses) - { - var land = Map.FindBlockById(landHouse.LandId); - for (int i = 0; i < landHouse.House; i++) land.Upgrade(); - } - return new MonopolyAggregate(GameId, - players.ToArray(), - GameStage, - Map, - HostId, - CurrentPlayerStateBuilder.Build(auction), - Dices, - Rounds - ); + var land = Map.FindBlockById(landHouse.LandId); + for (var i = 0; i < landHouse.House; i++) land.Upgrade(); } + return new MonopolyAggregate(GameId, - players.ToArray(), - GameStage, - Map, - HostId, - null!, - Dices, - Rounds - ); + players.ToArray(), + Map, + HostId, + CurrentPlayerStateBuilder.Build(auction), + Dices, + Rounds + ); } public MonopolyBuilder WithRounds(int rounds) @@ -131,10 +124,4 @@ public MonopolyBuilder WithDices(IDice[] dices) Dices = dices; return this; } - - public MonopolyBuilder WithGameStage(GameStage gameStage) - { - GameStage = gameStage; - return this; - } -} +} \ No newline at end of file diff --git a/DomainLayer/Monopoly.DomainLayer.Domain/GameStage.cs b/DomainLayer/Monopoly.DomainLayer.Domain/GameStage.cs deleted file mode 100644 index 6839f14..0000000 --- a/DomainLayer/Monopoly.DomainLayer.Domain/GameStage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Monopoly.DomainLayer.Domain; -public enum GameStage -{ - Ready, - Gaming -} diff --git a/DomainLayer/Monopoly.DomainLayer.Domain/MonopolyAggregate.cs b/DomainLayer/Monopoly.DomainLayer.Domain/MonopolyAggregate.cs index 389cf8c..950b05a 100644 --- a/DomainLayer/Monopoly.DomainLayer.Domain/MonopolyAggregate.cs +++ b/DomainLayer/Monopoly.DomainLayer.Domain/MonopolyAggregate.cs @@ -9,7 +9,6 @@ namespace Monopoly.DomainLayer.Domain; public class MonopolyAggregate : AbstractAggregateRoot { public string Id { get; set; } - public GameStage GameStage { get; private set; } public int[]? CurrentDice { get; set; } = null; public CurrentPlayerState CurrentPlayerState => _currentPlayerState; public IDice[] Dices { set; get; } @@ -28,10 +27,9 @@ public class MonopolyAggregate : AbstractAggregateRoot public int Rounds { get; private set; } - internal MonopolyAggregate(string gameId, Player[] players, GameStage gameStage, Map map, string hostId, CurrentPlayerState currentPlayerState, IDice[]? dices = null, int rounds = 0) + internal MonopolyAggregate(string gameId, Player[] players, Map map, string hostId, CurrentPlayerState currentPlayerState, IDice[]? dices = null, int rounds = 0) { Id = gameId; - GameStage = gameStage; _players = players.ToList(); _map = map; HostId = hostId; diff --git a/InterfaceAdapterLayer/Monopoly.InterfaceAdapterLayer.Server/Repositories/InMemoryRepository.cs b/InterfaceAdapterLayer/Monopoly.InterfaceAdapterLayer.Server/Repositories/InMemoryRepository.cs index 07a2ac9..a8f76a9 100644 --- a/InterfaceAdapterLayer/Monopoly.InterfaceAdapterLayer.Server/Repositories/InMemoryRepository.cs +++ b/InterfaceAdapterLayer/Monopoly.InterfaceAdapterLayer.Server/Repositories/InMemoryRepository.cs @@ -1,5 +1,6 @@ using Monopoly.ApplicationLayer.Application.Common; using Monopoly.ApplicationLayer.Application.DataModels; +using Monopoly.DomainLayer.Domain; namespace Monopoly.InterfaceAdapterLayer.Server.Repositories; @@ -7,7 +8,7 @@ public class InMemoryRepository : ICommandRepository, IQueryRepository { private readonly Dictionary games = new(); - public MonopolyDataModel FindGameById(string id) + public MonopolyAggregate FindGameById(string id) { games.TryGetValue(id, out var game); if (game == null) @@ -15,7 +16,7 @@ public MonopolyDataModel FindGameById(string id) throw new GameNotFoundException(id); } - return game; + return game.ToDomain(); } public string[] GetRooms() @@ -28,10 +29,10 @@ public bool IsExist(string id) return games.ContainsKey(id); } - public string Save(MonopolyDataModel monopolyDataModel) + public string Save(MonopolyAggregate monopoly) { - var id = GetGameId(monopolyDataModel.Id); - var game = monopolyDataModel with { Id = id }; + var id = GetGameId(monopoly.Id); + var game = monopoly.ToApplication() with { Id = id }; games[game.Id] = game; return game.Id; } diff --git a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/AuctionTest.cs b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/AuctionTest.cs index 33c3e01..3fd12d6 100644 --- a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/AuctionTest.cs +++ b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/AuctionTest.cs @@ -65,7 +65,6 @@ public void 拍賣結算時轉移金錢及地契() var game = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithMoney(A.Money).WithLandContract(A1.Id, false, 0)) .WithPlayer(B.Id, p => p.WithMoney(B.Money)) .WithCurrentPlayer(A.Id, p => p.WithAuction(A1.Id, B.Id, 600m)) @@ -157,7 +156,6 @@ private static MonopolyAggregate 玩家A持有1000元_玩家B持有2000元_玩 var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithMoney(A.Money).WithLandContract(A1.Id, false, 0)) .WithPlayer(B.Id, p => p.WithMoney(B.Money)) .WithCurrentPlayer(A.Id, p => p.WithAuction(A1.Id, null, 1000m)) diff --git a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/MortgageTest.cs b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/MortgageTest.cs index 556cf95..0791199 100644 --- a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/MortgageTest.cs +++ b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/MortgageTest.cs @@ -33,7 +33,6 @@ public void 玩家抵押房地產() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money).WithLandContract(A1.Id, false, 0)) .WithCurrentPlayer(A.Id) .Build(); @@ -72,7 +71,6 @@ public void 玩家不能抵押已抵押房地產() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money).WithLandContract(A1.Id, A1.IsMortgage, 5)) .WithCurrentPlayer(A.Id) .Build(); @@ -109,7 +107,6 @@ public void 玩家抵押非自有房地產() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money)) .WithCurrentPlayer(A.Id) .Build(); diff --git a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/PayTollTest.cs b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/PayTollTest.cs index 90c9c1e..4ce0e40 100644 --- a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/PayTollTest.cs +++ b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/PayTollTest.cs @@ -34,7 +34,6 @@ public void 玩家付過路費_無房_無同地段() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money).WithLandContract(A4.Id, false, 0)) .WithPlayer(B.Id, b => b.WithMoney(B.Money).WithPosition(B.CurrentBlockId, B.CurrentDirection)) .WithCurrentPlayer(B.Id) @@ -77,7 +76,6 @@ public void 玩家付過路費_有2房_有1同地段() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money) .WithLandContract(A1.Id, false, 10) .WithLandContract(A4.Id, false, 0)) @@ -123,7 +121,6 @@ public void 地主在監獄無需付過路費() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money).WithPosition(A.CurrentBlockId, A.CurrentDirection)) .WithPlayer(B.Id, b => b.WithMoney(B.Money) .WithPosition(B.CurrentBlockId, B.CurrentDirection) @@ -167,7 +164,6 @@ public void 地主在停車場無需付過路費() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money).WithPosition(A.CurrentBlockId, A.CurrentDirection)) .WithPlayer(B.Id, b => b.WithMoney(B.Money) .WithPosition(B.CurrentBlockId, B.CurrentDirection) @@ -211,7 +207,6 @@ public void 玩家不能重複支付過路費() var monopoly = new MonopolyBuilder() .WithMap(map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, a => a.WithMoney(A.Money) .WithLandContract(A1.Id, false, 0) .WithLandContract(A4.Id, false, 0)) diff --git a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/RollDiceTest.cs b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/RollDiceTest.cs index 64fbae8..cca736c 100644 --- a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/RollDiceTest.cs +++ b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/RollDiceTest.cs @@ -44,7 +44,6 @@ public void 玩家擲骰後移動棋子經過起點獲得獎勵金() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithMoney(A.Money) .WithPosition(A.CurrentBlockId, A.Direction)) .WithDices(Utils.MockDice(dicePoints)) @@ -101,7 +100,6 @@ public void 玩家擲骰後移動棋子到需要選擇方向的地方() .Build(); var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.Direction)) .WithCurrentPlayer(A.Id) .WithDices(Utils.MockDice(dicePoints)) @@ -158,7 +156,6 @@ public void 玩家擲骰後移動棋子經過起點獲得獎勵金3000() .Build(); var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.Direction).WithMoney(1000)) .WithCurrentPlayer(A.Id) .WithDices(Utils.MockDice(dicePoints)) @@ -218,7 +215,6 @@ public void 玩家擲骰後移動棋子到起點無法獲得獎勵金() .Build(); var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.Direction).WithMoney(A.Money)) .WithCurrentPlayer(A.Id) .WithDices(Utils.MockDice(dicePoints)) @@ -271,7 +267,6 @@ public void 玩家擲骰後移動棋子到自己擁有地() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.Direction).WithLandContract(A2.Id, false, 0)) .WithCurrentPlayer(A.Id) .WithDices(Utils.MockDice(dicePoints)) diff --git a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/SelectDirectionTest.cs b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/SelectDirectionTest.cs index e59134e..d8ff413 100644 --- a/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/SelectDirectionTest.cs +++ b/tests/Monopoly.DomainLayer.Domain.Tests/Testcases/SelectDirectionTest.cs @@ -29,7 +29,6 @@ public void 玩家選擇方向() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.CurrentDirection) .WithRemainingSteps(A.RemainingSteps)) .WithCurrentPlayer(A.Id, x => x.WithSelectedDirection(false)) @@ -74,7 +73,6 @@ public void 玩家選擇方向後會繼續前進到定點() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.CurrentDirection) .WithRemainingSteps(A.RemainingSteps)) .WithCurrentPlayer(A.Id, x => x.WithSelectedDirection(false)) @@ -123,7 +121,6 @@ public void 玩家選擇方向後會繼續前進到需要選擇方向的地方() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.CurrentDirection) .WithRemainingSteps(A.RemainingSteps)) .WithCurrentPlayer(A.Id, x => x.WithSelectedDirection(false)) @@ -169,7 +166,6 @@ public void 玩家選擇方向後會停止() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.CurrentDirection) .WithRemainingSteps(A.RemainingSteps)) .WithCurrentPlayer(A.Id, x => x.WithSelectedDirection(false)) @@ -208,7 +204,6 @@ public void 玩家選擇方向後不能再次選擇方向() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.CurrentDirection) .WithRemainingSteps(A.RemainingSteps)) .WithCurrentPlayer(A.Id) @@ -246,7 +241,6 @@ public void 玩家無法選擇反方向走回頭路() var monopoly = new MonopolyBuilder() .WithMap(Map) - .WithGameStage(GameStage.Gaming) .WithPlayer(A.Id, p => p.WithPosition(A.CurrentBlockId, A.CurrentDirection) .WithRemainingSteps(A.RemainingSteps)) .WithCurrentPlayer(A.Id, x => x.WithSelectedDirection(false)) diff --git a/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/AcceptanceTests/SelectDirectionTest.cs b/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/AcceptanceTests/SelectDirectionTest.cs index 915032d..df1d78c 100644 --- a/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/AcceptanceTests/SelectDirectionTest.cs +++ b/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/AcceptanceTests/SelectDirectionTest.cs @@ -66,7 +66,7 @@ public async Task 玩家選擇方向後在監獄停住() var repo = server.GetRequiredService(); var game = repo.FindGameById("1"); var player = game.Players.First(p => p.Id == a.Id); - Assert.AreEqual("Jail", player.Chess.CurrentPosition); + Assert.AreEqual("Jail", player.Chess.CurrentBlockId); } [TestMethod] @@ -118,6 +118,6 @@ public async Task 玩家選擇方向後在停車場停住() var repo = server.GetRequiredService(); var game = repo.FindGameById("1"); var player = game.Players.First(p => p.Id == a.Id); - Assert.AreEqual("ParkingLot", player.Chess.CurrentPosition); + Assert.AreEqual("ParkingLot", player.Chess.CurrentBlockId); } } \ No newline at end of file diff --git a/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Usecases/MockPlayerRollDiceUsecase.cs b/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Usecases/MockPlayerRollDiceUsecase.cs index 1ca24d6..e01f90c 100644 --- a/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Usecases/MockPlayerRollDiceUsecase.cs +++ b/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Usecases/MockPlayerRollDiceUsecase.cs @@ -13,7 +13,7 @@ public override async Task ExecuteAsync(PlayerRollDiceRequest request, IPresenter presenter, CancellationToken cancellationToken) { //查 - var game = Repository.FindGameById(request.GameId).ToDomain(); + var game = Repository.FindGameById(request.GameId); // Mock Dice game.Dices = mockDiceService.Dices; diff --git a/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Utils.cs b/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Utils.cs index 78695b6..41e51a9 100644 --- a/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Utils.cs +++ b/tests/Monopoly.InterfaceAdapterLayer.Server.Tests/Utils.cs @@ -8,7 +8,6 @@ using Auction = Monopoly.ApplicationLayer.Application.DataModels.Auction; using Chess = Monopoly.ApplicationLayer.Application.DataModels.Chess; using CurrentPlayerState = Monopoly.ApplicationLayer.Application.DataModels.CurrentPlayerState; -using GameStage = Monopoly.ApplicationLayer.Application.DataModels.GameStage; using LandContract = Monopoly.ApplicationLayer.Application.DataModels.LandContract; using Map = Monopoly.ApplicationLayer.Application.DataModels.Map; using Player = Monopoly.ApplicationLayer.Application.DataModels.Player; @@ -52,12 +51,10 @@ public class MonopolyBuilder private CurrentPlayerState CurrentPlayerState { get; set; } private List LandHouses { get; set; } = []; public Map Map { get; private set; } - private GameStage GameStage { get; set; } public MonopolyBuilder(string id) { GameId = id; - GameStage = GameStage.Gaming; } public MonopolyBuilder WithPlayer(Player player) @@ -96,7 +93,6 @@ private MonopolyDataModel Build() Players: [..Players], Map: Map, HostId: HostId, - GameStage: GameStage, CurrentPlayerState: CurrentPlayerState, LandHouses: LandHouses.ToArray()); } @@ -104,16 +100,10 @@ private MonopolyDataModel Build() internal void Save(MonopolyTestServer server) { var monopoly = Build(); - server.GetRequiredService().Save(monopoly); + server.GetRequiredService().Save(monopoly.ToDomain()); server.GetRequiredService().Dices = Dices.Select(value => new MockDice(value)).ToArray(); } - - internal MonopolyBuilder WithGameStage(GameStage gameStage) - { - GameStage = gameStage; - return this; - } } public class PlayerBuilder(string id)