예제 #1
0
    internal static Game GetGame(Guid gameId, IList <Player> players, IList <Pawn> pawns)
    {
        var game = RepositoryTestService.GetGame(gameId, players);

        foreach (var pawn in pawns)
        {
            pawn.GameId = game.Id;
            game.Pawns.Add(pawn);
        }

        return(game);
    }
예제 #2
0
    internal static Game GetGame(Guid gameId, IList <Player> players)
    {
        var game = RepositoryTestService.GetGame(gameId);

        foreach (var player in players)
        {
            game.Players.Add(new GamePlayer()
            {
                GameId = gameId, Player = player, PlayerId = player.Id
            });
        }

        return(game);
    }
예제 #3
0
    public void AddGameWithDatabaseExceptionTest()
    {
        var game         = RepositoryTestService.GetGame(Guid.NewGuid());
        var gameToCreate = this.autoMapper.Map <GameToCreateDTO>(game);

        this.moqGamesRepository.Setup(m => m.AddGame(It.IsAny <Game>())).Throws(new Exception());
        GamesController gameController = new GamesController(this.moqGamesRepository.Object, this.autoMapper);

        gameController = RepositoryTestService.AssignMockProblemDetailsFactoryToController <GamesController>(gameController);

        var result = gameController.AddGame(gameToCreate);

        Assert.IsNotNull(result);
        Assert.That(result.Result, Is.InstanceOf(typeof(ObjectResult)));
        ObjectResult problemResult = result.Result as ObjectResult;

        Assert.That(problemResult.Value, Is.InstanceOf(typeof(ProblemDetails)));
    }
예제 #4
0
    public void AddGameTest()
    {
        var game         = RepositoryTestService.GetGame(Guid.NewGuid());
        var gameToCreate = this.autoMapper.Map <GameToCreateDTO>(game);

        this.moqGamesRepository.Setup(m => m.AddGame(It.IsAny <Game>())).Returns(game);
        this.moqGamesRepository.Setup(m => m.Save()).Returns(1);
        GamesController gameController = new GamesController(this.moqGamesRepository.Object, this.autoMapper);

        var result = gameController.AddGame(gameToCreate);

        Assert.IsNotNull(result);
        Assert.That(result.Result, Is.InstanceOf(typeof(CreatedAtRouteResult)));
        CreatedAtRouteResult createdAtRouteResult = result.Result as CreatedAtRouteResult;

        Assert.AreEqual(createdAtRouteResult.RouteName, "GetGame");
        Assert.AreEqual(createdAtRouteResult.StatusCode, 201);
        Assert.That((createdAtRouteResult.Value as GameDTO).Id, Is.InstanceOf(typeof(Guid)));
    }
예제 #5
0
    public void GetGameByGuidTest()
    {
        var player = new Player()
        {
            Name = "TestPlayer", Id = Guid.NewGuid()
        };
        var gameId = Guid.NewGuid();
        var game   = RepositoryTestService.GetGame(gameId, new Player[] { player });

        this.moqGamesRepository.Setup(m => m.GetGame(It.IsAny <Guid>())).Returns(game);
        GamesController gameController = new GamesController(this.moqGamesRepository.Object, this.autoMapper);

        var result = gameController.GetGame(gameId);

        Assert.IsNotNull(result);
        Assert.That(result.Result, Is.InstanceOf(typeof(OkObjectResult)));
        OkObjectResult okObjectResult = result.Result as OkObjectResult;

        Assert.AreEqual(okObjectResult.StatusCode, 200);
        Assert.That(okObjectResult.Value, Is.InstanceOf(typeof(GameDTO)));
        Assert.AreEqual((okObjectResult.Value as GameDTO).Id, gameId);
    }
예제 #6
0
    internal static IEnumerable <Game> GetGames()
    {
        var player1 = RepositoryTestService.GetRandomPlayer("Player1");
        var pawns1  = RepositoryTestService.GetPawns(player1.Id, 1);
        var game1   = RepositoryTestService.GetGame(Guid.NewGuid(), new Player[] { player1 }, pawns1);

        var player2 = RepositoryTestService.GetRandomPlayer("Player2");
        var pawns2  = RepositoryTestService.GetPawns(player2.Id, 2);
        var game2   = RepositoryTestService.GetGame(Guid.NewGuid(), new Player[] { player2 }, pawns2);

        var player3 = RepositoryTestService.GetRandomPlayer("Player3");
        var pawns3  = RepositoryTestService.GetPawns(player3.Id, 3);
        var game3   = RepositoryTestService.GetGame(Guid.NewGuid(), new Player[] { player3 }, pawns3);


        var games = new List <Game>();

        games.Add(game1);
        games.Add(game2);
        games.Add(game3);

        return(games);
    }