|
|
|
@ -1,35 +1,81 @@
|
|
|
|
|
namespace Tests;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Models.Game;
|
|
|
|
|
using Models.Interfaces;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using static System.Type;
|
|
|
|
|
|
|
|
|
|
namespace Tests;
|
|
|
|
|
|
|
|
|
|
public class GameTests
|
|
|
|
|
{
|
|
|
|
|
private readonly Mock<IPersistence> _mockPersistence; // Mocking (faking) the persistence layer to allow for testing without a persistent connection
|
|
|
|
|
private readonly Game _game;
|
|
|
|
|
|
|
|
|
|
public GameTests()
|
|
|
|
|
{
|
|
|
|
|
_mockPersistence = new Mock<IPersistence>();
|
|
|
|
|
_game = new Game(_mockPersistence.Object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Game_Initialization_SetsPlayer()
|
|
|
|
|
public void AddPlayer_ShouldAddPlayerToList()
|
|
|
|
|
{
|
|
|
|
|
Player player = new Player("test_player");
|
|
|
|
|
Map map = new Map("test_background");
|
|
|
|
|
var player = new Player();
|
|
|
|
|
|
|
|
|
|
var game = new Game(player, map);
|
|
|
|
|
_game.AddPlayer(player);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(player, game.CurrentPlayer);
|
|
|
|
|
Assert.Contains(player, _game.Players);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Initialize_Turn_1()
|
|
|
|
|
public void AddGame_ShouldAddGameToList()
|
|
|
|
|
{
|
|
|
|
|
Player player = new Player("test_player");
|
|
|
|
|
Map map = new Map("test_background");
|
|
|
|
|
var game = new Game(new Player(), new Map("test_background"));
|
|
|
|
|
|
|
|
|
|
_game.AddGame(game);
|
|
|
|
|
|
|
|
|
|
Assert.Contains(game, _game.Games);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Game test = new Game(player, map);
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AddMap_ShouldAddMapToList()
|
|
|
|
|
{
|
|
|
|
|
var map = new Map("test_background.png");
|
|
|
|
|
|
|
|
|
|
_game.AddMap(map);
|
|
|
|
|
|
|
|
|
|
Assert.Contains(map, _game.Maps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AddBestScore_ShouldAddBestScoreToList()
|
|
|
|
|
{
|
|
|
|
|
var bestScore = new BestScore(3, 125);
|
|
|
|
|
|
|
|
|
|
typeof(Game).GetProperty("Turn").SetValue(test, 1);
|
|
|
|
|
_game.AddBestScore(bestScore);
|
|
|
|
|
|
|
|
|
|
Assert.Contains(bestScore, _game.BestScores);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = test.GetResult();
|
|
|
|
|
[Fact]
|
|
|
|
|
public void LoadData_ShouldLoadDataFromPersistence()
|
|
|
|
|
{
|
|
|
|
|
var players = new List<Player> { new Player() };
|
|
|
|
|
var games = new List<Game> { new Game(new Player(), new Map("test_background")) };
|
|
|
|
|
var maps = new List<Map> { new Map("test_background") };
|
|
|
|
|
var bestScores = new List<BestScore> { new BestScore(1, 26) };
|
|
|
|
|
|
|
|
|
|
Assert.Equal(typeof(Game).GetProperty("Turn").GetValue(test.Turn), 1);
|
|
|
|
|
_mockPersistence.Setup(p => p.LoadData()).Returns((players, games, maps, bestScores));
|
|
|
|
|
|
|
|
|
|
_game.LoadData();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(players, _game.Players);
|
|
|
|
|
Assert.Equal(games, _game.Games);
|
|
|
|
|
Assert.Equal(maps, _game.Maps);
|
|
|
|
|
Assert.Equal(bestScores, _game.BestScores);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Game_Initialization_SetsMap()
|
|
|
|
|