Continous Integration in der Praxis Gruppenarbeit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

  1. using MiniGames.Client.ViewModel;
  2. using MiniGames.Shared.Models;
  3. using Xunit;
  4. namespace MiniGamesTests
  5. {
  6. public class TicTacToeTest
  7. {
  8. TicTacToeBrett StandardBrett()
  9. {
  10. return new TicTacToeBrett();
  11. }
  12. SpielerModel[] StandardSpieler()
  13. {
  14. return new SpielerModel[]
  15. {
  16. new SpielerModel
  17. {
  18. SpielerName = "Spieler 1",
  19. Punkte = 0
  20. },
  21. new SpielerModel
  22. {
  23. SpielerName = "Spieler 2",
  24. Punkte = 1
  25. }
  26. };
  27. }
  28. TicTacToeModel StandardModel()
  29. {
  30. return new TicTacToeModel
  31. {
  32. Spieler = StandardSpieler(),
  33. Brett = StandardBrett(),
  34. };
  35. }
  36. TicTacToe StandardSpiel()
  37. {
  38. return new(StandardModel());
  39. }
  40. [Theory]
  41. [InlineData(0, 1)]
  42. [InlineData(1, 0)]
  43. public void SpielerWechselTest(int vorher, int nachher)
  44. {
  45. // arrange
  46. TicTacToe spiel = StandardSpiel();
  47. spiel.AktiverSpielerIndex = vorher;
  48. int erwarteterIndex = nachher;
  49. // act
  50. spiel.SpielerWechsel();
  51. // assert
  52. Assert.Equal(erwarteterIndex, spiel.AktiverSpielerIndex);
  53. }
  54. [Fact]
  55. public void SpielerInput_ValidesInputTest()
  56. {
  57. // arrange
  58. TicTacToe spiel = StandardSpiel();
  59. int pos = 2;
  60. TicTacToeBrett erwartetesBrett = new(new int[,]
  61. {
  62. { TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER, },
  63. { TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER, },
  64. { spiel.AktiverSpielerIndex, TicTacToeBrett.LEER, TicTacToeBrett.LEER, },
  65. });
  66. // act
  67. spiel.SpielerInput(pos);
  68. // assert
  69. Assert.True(spiel.Brett.Gleich(erwartetesBrett));
  70. }
  71. }
  72. }