Exemplo n.º 1
0
        public void Setup()
        {
            _projectRepositoryMock = new Mock <IProjectRepository>();

            var tagId   = 2;
            var tagMock = new Mock <Tag>();

            tagMock.SetupGet(t => t.Plant).Returns(TestPlant);
            tagMock.SetupGet(t => t.Id).Returns(tagId);
            var actionId = 12;

            _action = new Action(TestPlant, _oldTitle, _oldDescription, _oldDueTimeUtc);
            _action.SetProtectedIdForTesting(actionId);
            tagMock.Object.AddAction(_action);

            _projectRepositoryMock
            .Setup(r => r.GetTagByTagIdAsync(tagId))
            .Returns(Task.FromResult(tagMock.Object));

            _command = new UpdateActionCommand(tagId, actionId, _newTitle, _newDescription, _newDueTimeUtc, _rowVersion);

            _dut = new UpdateActionCommandHandler(
                _projectRepositoryMock.Object,
                UnitOfWorkMock.Object
                );
        }
Exemplo n.º 2
0
        public void Setup_OkState()
        {
            _projectValidatorMock = new Mock <IProjectValidator>();

            _tagValidatorMock = new Mock <ITagValidator>();
            _tagValidatorMock.Setup(r => r.ExistsActionAsync(_tagId, _actionId, default)).Returns(Task.FromResult(true));

            _actionValidatorMock = new Mock <IActionValidator>();

            _rowVersionValidatorMock = new Mock <IRowVersionValidator>();
            _rowVersionValidatorMock.Setup(r => r.IsValid(_rowVersion)).Returns(true);

            _command = new UpdateActionCommand(
                _tagId,
                _actionId,
                "",
                "",
                null,
                _rowVersion);

            _dut = new UpdateActionCommandValidator(
                _projectValidatorMock.Object,
                _tagValidatorMock.Object,
                _actionValidatorMock.Object,
                _rowVersionValidatorMock.Object
                );
        }
Exemplo n.º 3
0
        public void Constructor_ShouldSetProperties()
        {
            var dueTimeUtc = new DateTime(2020, 1, 1, 1, 1, 1, DateTimeKind.Utc);
            var dut        = new UpdateActionCommand(2, 1, "Title", "Description", dueTimeUtc, "AAAAAAAAABA=");

            Assert.AreEqual(2, dut.TagId);
            Assert.AreEqual(1, dut.ActionId);
            Assert.AreEqual("Title", dut.Title);
            Assert.AreEqual("Description", dut.Description);
            Assert.AreEqual(dueTimeUtc, dut.DueTimeUtc);
            Assert.AreEqual("AAAAAAAAABA=", dut.RowVersion);
        }
Exemplo n.º 4
0
        public void Validate_ShouldFail_WhenInvalidRowVersion()
        {
            const string invalidRowVersion = "String";

            var command = new UpdateActionCommand(_tagId, _actionId, "", "", null, invalidRowVersion);

            _rowVersionValidatorMock.Setup(r => r.IsValid(invalidRowVersion)).Returns(false);

            var result = _dut.Validate(command);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("Not a valid row version!"));
        }
        public async Task <ActionResult <string> > UpdateAction(
            [FromHeader(Name = CurrentPlantMiddleware.PlantHeader)]
            [Required]
            string plant,
            [FromRoute] int id,
            [FromRoute] int actionId,
            [FromBody] UpdateActionDto dto)
        {
            var command = new UpdateActionCommand(
                id,
                actionId,
                dto.Title,
                dto.Description,
                dto.DueTimeUtc,
                dto.RowVersion);

            var result = await _mediator.Send(command);

            return(this.FromResult(result));
        }