Beispiel #1
0
        public void Validate_ShouldFail_WhenInvalidRowVersion()
        {
            const string invalidRowVersion = "String";

            var command = new DeleteTagAttachmentCommand(_tagId, _attachmentId, 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!"));
        }
Beispiel #2
0
        public void Setup_OkState()
        {
            _projectValidatorMock = new Mock <IProjectValidator>();

            _command = new DeleteTagAttachmentCommand(_tagId, _attachmentId, _rowVersion);

            _tagValidatorMock = new Mock <ITagValidator>();
            _tagValidatorMock.Setup(r => r.ExistsTagAttachmentAsync(_command.TagId, _command.AttachmentId, default)).Returns(Task.FromResult(true));

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

            _dut = new DeleteTagAttachmentCommandValidator(
                _projectValidatorMock.Object,
                _tagValidatorMock.Object,
                _rowVersionValidatorMock.Object);
        }
Beispiel #3
0
        public void Setup()
        {
            _command = new DeleteTagAttachmentCommand(1, 3, _rowVersion);

            _projectRepositoryMock = new Mock <IProjectRepository>();
            _blobStorageMock       = new Mock <IBlobStorage>();

            var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >();
            var options = new AttachmentOptions
            {
                MaxSizeMb         = 2,
                BlobContainer     = BlobContainer,
                ValidFileSuffixes = new[] { ".gif", ".jpg" }
            };

            attachmentOptionsMock
            .Setup(x => x.CurrentValue)
            .Returns(options);

            var stepMock = new Mock <Step>();

            stepMock.SetupGet(s => s.Plant).Returns(TestPlant);

            var reqMock = new Mock <TagRequirement>();

            reqMock.SetupGet(s => s.Plant).Returns(TestPlant);

            _tag = new Tag(TestPlant, TagType.Standard, "", "", stepMock.Object, new List <TagRequirement> {
                reqMock.Object
            });

            var attachment = new TagAttachment(TestPlant, Guid.Empty, "Fil.txt");

            attachment.SetProtectedIdForTesting(_command.AttachmentId);
            _tag.AddAttachment(attachment);

            _projectRepositoryMock
            .Setup(r => r.GetTagByTagIdAsync(_command.TagId))
            .Returns(Task.FromResult(_tag));

            _dut = new DeleteTagAttachmentCommandHandler(
                _projectRepositoryMock.Object,
                UnitOfWorkMock.Object,
                _blobStorageMock.Object,
                attachmentOptionsMock.Object);
        }
        public async Task <ActionResult <int> > DeleteTagAttachment(
            [FromHeader(Name = CurrentPlantMiddleware.PlantHeader)]
            [Required]
            [StringLength(PlantEntityBase.PlantLengthMax, MinimumLength = PlantEntityBase.PlantLengthMin)]
            string plant,
            [FromRoute] int id,
            [FromRoute] int attachmentId,
            [FromBody] DeleteTagAttachmentDto dto)
        {
            var command = new DeleteTagAttachmentCommand(
                id,
                attachmentId,
                dto.RowVersion);

            var result = await _mediator.Send(command);

            return(this.FromResult(result));
        }