From 177c717f4a8513aa35c1b247baa1bf1410b61040 Mon Sep 17 00:00:00 2001 From: Felix Detig Date: Mon, 14 Feb 2022 23:43:47 +0100 Subject: [PATCH] TicTacToe.SpielerInput wechselt nur bei validem Input den Spieler --- .../MiniGames/Client/ViewModel/TicTacToe.cs | 6 ++++-- .../MiniGamesTests/TicTacToeTest.cs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/BlazorSolution/MiniGames/Client/ViewModel/TicTacToe.cs b/BlazorSolution/MiniGames/Client/ViewModel/TicTacToe.cs index 611c364..81eea92 100644 --- a/BlazorSolution/MiniGames/Client/ViewModel/TicTacToe.cs +++ b/BlazorSolution/MiniGames/Client/ViewModel/TicTacToe.cs @@ -25,8 +25,10 @@ namespace MiniGames.Client.ViewModel public void SpielerInput(int posIndex) { - Brett.Set(posIndex, AktiverSpielerIndex); - SpielerWechsel(); + if (Brett.Set(posIndex, AktiverSpielerIndex)) + { + SpielerWechsel(); + } } public void SpielerWechsel() diff --git a/BlazorSolution/MiniGamesTests/TicTacToeTest.cs b/BlazorSolution/MiniGamesTests/TicTacToeTest.cs index cefd005..f9e25ce 100644 --- a/BlazorSolution/MiniGamesTests/TicTacToeTest.cs +++ b/BlazorSolution/MiniGamesTests/TicTacToeTest.cs @@ -82,5 +82,24 @@ namespace MiniGamesTests Assert.True(spiel.Brett.Gleich(erwartetesBrett)); Assert.Equal(erwarteterSpielerIndex, spiel.AktiverSpielerIndex); } + + [Fact] + public void SpielerInput_InvalidesInputTest() + { + // arrange + TicTacToe spiel = StandardSpiel(); + spiel.AktiverSpielerIndex = 0; + int erwarteterSpielerIndex = 0; + + int pos = -1; + TicTacToeBrett erwartetesBrett = StandardBrett(); + + // act + spiel.SpielerInput(pos); + + // assert + Assert.True(spiel.Brett.Gleich(erwartetesBrett)); + Assert.Equal(erwarteterSpielerIndex, spiel.AktiverSpielerIndex); + } } }