diff --git a/BackendTests/Services/GameGroupTests.cs b/BackendTests/Services/GameGroupTests.cs index 84fe963..70c70af 100644 --- a/BackendTests/Services/GameGroupTests.cs +++ b/BackendTests/Services/GameGroupTests.cs @@ -202,9 +202,24 @@ public class GameGroupTests public void SetAllInGame_SetsStateToInGame() { AddFullParty(); - Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).Not.EqualTo(State.Ready)); - _gameGroup.SetAllInGame(); - Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).EqualTo(State.InGame)); + _gameGroup.Players.ForEach(player => player.State = State.Ready); + Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).EqualTo(State.Ready)); + + var allInGame = _gameGroup.SetAllInGame(); + + Assert.Multiple(() => + { + Assert.That(allInGame, Is.True); + Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).EqualTo(State.InGame)); + }); + } + + [Test] + public void SetAllInGame_SetStateToInGame_WhenNotAllReady() + { + AddFullParty(); + var allInGame = _gameGroup.SetAllInGame(); + Assert.That(allInGame, Is.False); } [Test] diff --git a/pac-man-board-game/Services/GameGroup.cs b/pac-man-board-game/Services/GameGroup.cs index 5428cbf..c1cbdec 100644 --- a/pac-man-board-game/Services/GameGroup.cs +++ b/pac-man-board-game/Services/GameGroup.cs @@ -32,8 +32,11 @@ public class GameGroup // TODO tests return Players; } - public void SetAllInGame() + public bool SetAllInGame() { + if (Players.Any(player => player.State != State.Ready)) return false; + foreach (var player in Players) player.State = State.InGame; + return true; } }