Ejemplo n.º 1
0
    public void UpdatePawnWithNotFoundTest()
    {
        this.moqPawnsRepository.Setup(m => m.GetPawn(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(() => null);
        PawnsController pawnsController = new PawnsController(this.moqPawnsRepository.Object, this.autoMapper, this.moqGameStateManager.Object, this.moqBattleActionSimulator.Object);
        JsonPatchDocument <PawnToPatchDTO> patchDocument = new JsonPatchDocument <PawnToPatchDTO>();

        patchDocument.Add(p => p.Col, 100);

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

        Assert.IsNotNull(result);
        Assert.That(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 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>)));
    }
Ejemplo n.º 4
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);
    }
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);
    }
Ejemplo n.º 6
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);
    }