public void Validate_ShouldFail_WhenInvalidRowVersion() { const string invalidRowVersion = "String"; var command = new DeleteActionAttachmentCommand(_tagId, _actionId, _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!")); }
public void Setup() { _command = new DeleteActionAttachmentCommand(1, 2, 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 tagMock = new Mock <Tag>(); tagMock.SetupGet(t => t.Plant).Returns(TestPlant); _action = new Action(TestPlant, "T", "D", null); _action.SetProtectedIdForTesting(_command.ActionId); tagMock.Object.AddAction(_action); var attachment = new ActionAttachment(TestPlant, Guid.Empty, "Fil.txt"); attachment.SetProtectedIdForTesting(_command.AttachmentId); _action.AddAttachment(attachment); _projectRepositoryMock .Setup(r => r.GetTagByTagIdAsync(_command.TagId)) .Returns(Task.FromResult(tagMock.Object)); _dut = new DeleteActionAttachmentCommandHandler( _projectRepositoryMock.Object, UnitOfWorkMock.Object, _blobStorageMock.Object, attachmentOptionsMock.Object); }
public void Setup_OkState() { _projectValidatorMock = new Mock <IProjectValidator>(); _command = new DeleteActionAttachmentCommand(_tagId, _actionId, _attachmentId, _rowVersion); _tagValidatorMock = new Mock <ITagValidator>(); _tagValidatorMock.Setup(r => r.ExistsActionAttachmentAsync(_tagId, _actionId, _attachmentId, default)).Returns(Task.FromResult(true)); _actionValidatorMock = new Mock <IActionValidator>(); _rowVersionValidatorMock = new Mock <IRowVersionValidator>(); _rowVersionValidatorMock.Setup(r => r.IsValid(_rowVersion)).Returns(true); _dut = new DeleteActionAttachmentCommandValidator( _projectValidatorMock.Object, _tagValidatorMock.Object, _actionValidatorMock.Object, _rowVersionValidatorMock.Object); }
public async Task <ActionResult <int> > DeleteActionAttachment( [FromHeader(Name = CurrentPlantMiddleware.PlantHeader)] [Required] [StringLength(PlantEntityBase.PlantLengthMax, MinimumLength = PlantEntityBase.PlantLengthMin)] string plant, [FromRoute] int id, [FromRoute] int actionId, [FromRoute] int attachmentId, [FromBody] DeleteActionAttachmentDto dto) { var actionCommand = new DeleteActionAttachmentCommand( id, actionId, attachmentId, dto.RowVersion); var result = await _mediator.Send(actionCommand); return(this.FromResult(result)); }