Ejemplo n.º 1
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)));
    }
Ejemplo n.º 2
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)));
    }
Ejemplo n.º 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)));
    }
Ejemplo n.º 4
0
    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)));
    }
Ejemplo n.º 5
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);
    }