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);
    }
    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);
    }
Beispiel #3
0
    public void GetGamesTest()
    {
        var gamesReturnedByRepository = RepositoryTestService.GetGames();

        this.moqGamesRepository.Setup(m => m.GetGames()).Returns(gamesReturnedByRepository);
        GamesController gameController = new GamesController(this.moqGamesRepository.Object, this.autoMapper);
        var             result         = gameController.GetGames();

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

        Assert.AreEqual(okObjectResult.StatusCode, 200);
        Assert.Greater((okObjectResult.Value as IList <GameDTO>).Count, 0);
    }
    public void AddPlayerWithWrongGameIdTest()
    {
        var player         = RepositoryTestService.GetRandomPlayer("Test Player");
        var playerToCreate = this.autoMapper.Map <PlayerToCreateDTO>(player);

        this.moqPlayersRepository.Setup(m => m.AddPlayer(It.IsAny <Guid>(), It.IsAny <Player>())).Returns(() => null);
        PlayersController playersController = new PlayersController(this.moqPlayersRepository.Object, this.autoMapper, this.moqGameStateManager.Object, null);

        playersController = RepositoryTestService.AssignMockProblemDetailsFactoryToController <PlayersController>(playersController);

        var result = playersController.AddPlayer(Guid.NewGuid(), playerToCreate);

        Assert.IsNotNull(result);
        Assert.That(result.Result, Is.InstanceOf(typeof(NotFoundResult)));
    }
    public void GetPlayersTest()
    {
        var player1 = RepositoryTestService.GetRandomPlayer("Player 1");
        var player2 = RepositoryTestService.GetRandomPlayer("Player 2");

        this.moqPlayersRepository.Setup(m => m.GetPlayers(It.IsAny <Guid>())).Returns(new Player[] { player1, player2 });
        PlayersController playersController = new PlayersController(this.moqPlayersRepository.Object, this.autoMapper, this.moqGameStateManager.Object, null);
        var result = playersController.GetPlayers(Guid.NewGuid());

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

        Assert.AreEqual(okObjectResult.StatusCode, 200);
        Assert.AreEqual((okObjectResult.Value as IList <PlayerDTO>).Count, 2);
    }
Beispiel #6
0
    public void AddPawnsWithGameIdOrPlayerIdProblemTest()
    {
        var playerId             = Guid.NewGuid();
        IEnumerable <Pawn> pawns = RepositoryTestService.GetPawns(playerId, 5);
        var pawnsToCreate        = this.autoMapper.Map <IEnumerable <PawnToCreateDTO> >(pawns);

        this.moqPawnsRepository.Setup(m => m.AddPawns(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <IEnumerable <Pawn> >())).Returns(() => null);
        PawnsController pawnsController = new PawnsController(this.moqPawnsRepository.Object, this.autoMapper, this.moqGameStateManager.Object, this.moqBattleActionSimulator.Object);

        pawnsController = RepositoryTestService.AssignMockProblemDetailsFactoryToController <PawnsController>(pawnsController);

        var result = pawnsController.AddPawns(Guid.NewGuid(), playerId, pawnsToCreate);

        Assert.IsNotNull(result);
        Assert.That(result.Result, Is.InstanceOf(typeof(NotFoundResult)));
    }
Beispiel #7
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)));
    }
    public void AddPlayerWithDatabaseProblemTest()
    {
        var player         = RepositoryTestService.GetRandomPlayer("Test Player");
        var playerToCreate = this.autoMapper.Map <PlayerToCreateDTO>(player);

        this.moqPlayersRepository.Setup(m => m.AddPlayer(It.IsAny <Guid>(), It.IsAny <Player>())).Throws(new Exception());
        PlayersController playersController = new PlayersController(this.moqPlayersRepository.Object, this.autoMapper, this.moqGameStateManager.Object, null);

        playersController = RepositoryTestService.AssignMockProblemDetailsFactoryToController <PlayersController>(playersController);

        var result = playersController.AddPlayer(Guid.NewGuid(), playerToCreate);

        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)));
    }
    public void AddPlayerTest()
    {
        var player         = RepositoryTestService.GetRandomPlayer("Test Player");
        var playerToCreate = this.autoMapper.Map <PlayerToCreateDTO>(player);

        this.moqPlayersRepository.Setup(m => m.AddPlayer(It.IsAny <Guid>(), It.IsAny <Player>())).Returns(player);
        this.moqPlayersRepository.Setup(m => m.Save()).Returns(1);
        PlayersController playersController = new PlayersController(this.moqPlayersRepository.Object, this.autoMapper, this.moqGameStateManager.Object, null);

        var result = playersController.AddPlayer(Guid.NewGuid(), playerToCreate);

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

        Assert.AreEqual(createdAtRouteResult.RouteName, "GetPlayer");
        Assert.AreEqual(createdAtRouteResult.StatusCode, 201);
        Assert.That((createdAtRouteResult.Value as PlayerDTO).Id, Is.InstanceOf(typeof(Guid)));
    }
Beispiel #10
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)));
    }
Beispiel #11
0
    public void AddPawnsTest()
    {
        var playerId             = Guid.NewGuid();
        IEnumerable <Pawn> pawns = RepositoryTestService.GetPawns(playerId, 5);
        var pawnsToCreate        = this.autoMapper.Map <IEnumerable <PawnToCreateDTO> >(pawns);

        this.moqPawnsRepository.Setup(m => m.AddPawns(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <IEnumerable <Pawn> >())).Returns(pawns);
        this.moqPawnsRepository.Setup(m => m.Save()).Returns(1);
        PawnsController pawnsController = new PawnsController(this.moqPawnsRepository.Object, this.autoMapper, this.moqGameStateManager.Object, this.moqBattleActionSimulator.Object);

        var result = pawnsController.AddPawns(Guid.NewGuid(), playerId, pawnsToCreate);

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

        Assert.AreEqual(createdAtRouteResult.RouteName, "GetPawns");
        Assert.AreEqual(createdAtRouteResult.StatusCode, 201);
        Assert.That(createdAtRouteResult.Value, Is.InstanceOf(typeof(IEnumerable <PawnDTO>)));
    }
Beispiel #12
0
    public void GetPawnsTest()
    {
        var playerId = Guid.NewGuid();
        var gameId   = Guid.NewGuid();
        var pawns    = RepositoryTestService.GetPawns(playerId, 10);

        this.moqPawnsRepository.Setup(m => m.GetPawns(gameId, playerId)).Returns(pawns);
        PawnsController pawnsController = new PawnsController(this.moqPawnsRepository.Object, this.autoMapper, this.moqGameStateManager.Object, this.moqBattleActionSimulator.Object);

        pawnsController = RepositoryTestService.AssignUserToController(pawnsController, playerId.ToString(), "TestPlayer");
        ;
        var result = pawnsController.GetPawns(gameId, playerId);

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

        Assert.AreEqual(okObjectResult.StatusCode, 200);
        Assert.AreEqual((okObjectResult.Value as IList <PawnDTO>).Count, 10);
    }
Beispiel #13
0
    public void UpdatePawnWithTestOperationsCausingValidationProblemTest()
    {
        // [{"op": "test", "path": "row", "value": "4567"}]
        var pawn = RepositoryTestService.GetPawn(Guid.NewGuid());

        this.moqPawnsRepository.Setup(m => m.GetPawn(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(pawn);
        PawnsController pawnsController = new PawnsController(this.moqPawnsRepository.Object, this.autoMapper, this.moqGameStateManager.Object, this.moqBattleActionSimulator.Object);

        pawnsController = RepositoryTestService.AssignMockObjectValidatorToController <PawnsController>(pawnsController);
        pawnsController = RepositoryTestService.AssignMockProblemDetailsFactoryToController <PawnsController>(pawnsController);
        JsonPatchDocument <PawnToPatchDTO> patchDocument = new JsonPatchDocument <PawnToPatchDTO>();

        patchDocument.Test(p => p.Col, 4567);

        var result = pawnsController.UpdatePawn(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), patchDocument);

        Assert.IsNotNull(result);
        Assert.That(result, Is.InstanceOf(typeof(ObjectResult)));
        Assert.That((result as ObjectResult).Value, Is.InstanceOf(typeof(ValidationProblemDetails)));
        Assert.AreEqual(1, pawnsController.ModelState.ErrorCount);
    }
Beispiel #14
0
    public void UpdatePawnWithReplaceOperationTest()
    {
        // [{"op": "replace", "path": "row", "value": "6"}]
        int newColValue = 100;
        var pawn        = RepositoryTestService.GetPawn(Guid.NewGuid());

        this.moqPawnsRepository.Setup(m => m.GetPawn(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(pawn);
        PawnsController pawnsController = new PawnsController(this.moqPawnsRepository.Object, this.autoMapper, this.moqGameStateManager.Object, this.moqBattleActionSimulator.Object);

        pawnsController = RepositoryTestService.AssignMockObjectValidatorToController <PawnsController>(pawnsController);
        JsonPatchDocument <PawnToPatchDTO> patchDocument = new JsonPatchDocument <PawnToPatchDTO>();

        patchDocument.Replace(p => p.Col, newColValue);

        var result = pawnsController.UpdatePawn(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), patchDocument);

        Assert.IsNotNull(result);
        Assert.That(result, Is.InstanceOf(typeof(ActionResult)));
        Assert.AreEqual(0, pawnsController.ModelState.ErrorCount);
        Assert.AreEqual(newColValue, pawn.Col);
    }
Beispiel #15
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);
    }
Beispiel #16
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);
    }
Beispiel #17
0
 internal static Pawn GetPawn(Guid playerId)
 {
     return(RepositoryTestService.GetPawns(playerId, 1)[0]);
 }