Esempio n. 1
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);
    }
Esempio n. 2
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);
    }