public void Flow_tests() { var putDocResponse = Client.Documents.PostAsync(TestData.Artists.Artist1Json).Result; var putCmd = new PutAttachmentCommand( putDocResponse.Id, putDocResponse.Rev, TestData.Attachments.One.Name, TestData.Attachments.One.ContentType, TestData.Attachments.One.ContentDecoded.AsBytes()); var putAttachmentResponse = SUT.PutAsync(putCmd).Result; putAttachmentResponse.Should().BeSuccessfulPut(TestData.Artists.Artist1Id); var getCmd = new GetAttachmentCommand( putAttachmentResponse.Id, putAttachmentResponse.Rev, TestData.Attachments.One.Name); var getResponse = SUT.GetAsync(getCmd).Result; getResponse.Should().BeSuccessfulGet(TestData.Artists.Artist1Id, TestData.Attachments.One.Name); var deleteCmd = new DeleteAttachmentCommand( putAttachmentResponse.Id, putAttachmentResponse.Rev, TestData.Attachments.One.Name); var deleteResponse = SUT.DeleteAsync(deleteCmd).Result; deleteResponse.Should().BeSuccessfulDelete(TestData.Artists.Artist1Id); }
public void Validate_Succeeds() { var command = new DeleteAttachmentCommand(1, 2, "ABC"); var result = _dut.Validate(command); Assert.IsTrue(result.IsValid); }
public void Constructor_SetsProperties() { var dut = new DeleteAttachmentCommand(1, 2, "3"); Assert.AreEqual(1, dut.InvitationId); Assert.AreEqual(2, dut.AttachmentId); Assert.AreEqual("3", dut.RowVersion); }
protected virtual HttpRequestMessage CreateRequest(DeleteAttachmentCommand cmd) { var req = new HttpRequest(HttpMethod.Delete, GenerateRequestUrl(cmd.DocId, cmd.DocRev, cmd.Name)); req.SetIfMatch(cmd.DocRev); return(req); }
public virtual async Task <DocumentHeaderResponse> DeleteAsync(DeleteAttachmentCommand cmd) { Ensure.That(cmd, "cmd").IsNotNull(); var req = CreateRequest(cmd); var res = SendAsync(req); return(ProcessDocumentHeaderResponse(await res.ForAwait())); }
protected override void RaiseAllCanExecuteChanged() { base.RaiseAllCanExecuteChanged(); ImportAttachmentFromDiskCommand.RaiseCanExecuteChanged(); ImportAttachmentFromClipboardCommand.RaiseCanExecuteChanged(); SaveAttachmentToDiskCommand.RaiseCanExecuteChanged(); OpenAttachmentCommand.RaiseCanExecuteChanged(); DeleteAttachmentCommand.RaiseCanExecuteChanged(); }
public void Validate_Fails_WhenInvitationDoesNotExist() { var command = new DeleteAttachmentCommand(0, 2, "ABC"); var result = _dut.Validate(command); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("Invitation with this ID does not exist")); }
public void Validate_Fails_WhenAttachmentDoesNotExist() { var command = new DeleteAttachmentCommand(1, 0, "ABC"); var result = _dut.Validate(command); Assert.IsFalse(result.IsValid); Assert.AreEqual(1, result.Errors.Count); Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("Attachment doesn't exist!")); }
public void Validate_Fails_WhenRowVersionIsInvalid() { var command = new DeleteAttachmentCommand(1, 2, "Invalid"); 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 <IActionResult> DeleteAsync(Guid id) { var cmd = new DeleteAttachmentCommand() { Id = id }; await DispatchAsync(cmd); return(Ok()); }
public NoteViewModel(INote model, MainViewModel main) : base(main) { if (model == null) throw new ArgumentNullException("model"); this.model = model; update = new UpdateLabelsCommand(this); newAttachment = new NewAttachmentCommand(this); deleteAttachment = new DeleteAttachmentCommand(this); main.RegisterViewModel(model, this); LoadViewModels(); }
public async Task ValidateAsync_OnDeleteAttachmentCommand_ShouldReturnFalse_WhenNoAccessToProject() { // Arrange var command = new DeleteAttachmentCommand(_invitationIdWithoutAccessToProject, 0, null); // act var result = await _dut.ValidateAsync(command); // Assert Assert.IsFalse(result); }
public async Task Handle_AttachmentNotFound_ShouldThrowNotFoundException() { // Arrange var attachment = await _wolkDbContext.CreateAndSaveAttachment(); var request = new DeleteAttachmentCommand { AttachmentId = attachment.Id + 1 }; // Act / Assert await Assert.ThrowsExceptionAsync <NotFoundException>(() => _handler.Handle(request, CancellationToken.None)); }
public async Task <ActionResult <int> > DeleteAttachment( [FromHeader(Name = CurrentPlantMiddleware.PlantHeader)] [Required] [StringLength(PlantEntityBase.PlantLengthMax, MinimumLength = PlantEntityBase.PlantLengthMin)] string plant, [FromRoute] int id, [FromRoute] int attachmentId, [FromBody] DeleteAttachmentDto dto) { var command = new DeleteAttachmentCommand( id, attachmentId, dto.RowVersion); var result = await _mediator.Send(command); return(this.FromResult(result)); }
public async Task Handle_AttachmentFound_FileNotFound_ShouldThrowInvalidOperationException() { // Arrange var attachment = await _wolkDbContext.CreateAndSaveAttachment(); var request = new DeleteAttachmentCommand { AttachmentId = attachment.Id }; var path = Path.Combine(_configuration.UploadsPath, attachment.InternalFilename); _mockFileService .Setup(m => m.FileExists(path)) .Returns(false); // Act / Assert await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => _handler.Handle(request, CancellationToken.None)); }
public void Setup() { _invitation = new Invitation( _plant, _projectName, "TestInvitation", "Description", DisciplineType.DP, new DateTime(), new DateTime(), null, new List <McPkg> { new McPkg(_plant, _projectName, "Comm", "Mc", "d", "1|2") }, null); _attachment = new Attachment(_plant, "ExistingFile.txt"); _attachment.SetProtectedIdForTesting(2); _invitation.AddAttachment(_attachment); _invitationRepositoryMock = new Mock <IInvitationRepository>(); _invitationRepositoryMock .Setup(x => x.GetByIdAsync(1)) .Returns(Task.FromResult(_invitation)); _unitOfWorkMock = new Mock <IUnitOfWork>(); _blobStorageMock = new Mock <IBlobStorage>(); var blobStorageOptions = new BlobStorageOptions() { BlobContainer = "TestContainer" }; _monitorMock = Mock.Of <IOptionsMonitor <BlobStorageOptions> >(x => x.CurrentValue == blobStorageOptions); _command = new DeleteAttachmentCommand(1, 2, "AAAAAAAAAAA="); _dut = new DeleteAttachmentCommandHandler( _invitationRepositoryMock.Object, _unitOfWorkMock.Object, _blobStorageMock.Object, _monitorMock); }
public void When_DELETE_of_an_existing_attachment_The_response_is_ok() { var putDocResponse = Client.Documents.PostAsync(TestData.Artists.Artist1Json).Result; var putCmd = new PutAttachmentCommand( putDocResponse.Id, putDocResponse.Rev, TestData.Attachments.One.Name, TestData.Attachments.One.ContentType, TestData.Attachments.One.ContentDecoded.AsBytes()); var putAttachmentResponse = SUT.PutAsync(putCmd).Result; var deleteCmd = new DeleteAttachmentCommand( putAttachmentResponse.Id, putAttachmentResponse.Rev, TestData.Attachments.One.Name); var deleteResponse = SUT.DeleteAsync(deleteCmd).Result; deleteResponse.Should().BeSuccessfulDelete(TestData.Artists.Artist1Id); }
public async Task Handle_AttachmentFound_FileFound_ShouldDeleteAttachmentAndFile() { // Arrange var attachment = await _wolkDbContext.CreateAndSaveAttachment(); var request = new DeleteAttachmentCommand { AttachmentId = attachment.Id }; var path = Path.Combine(_configuration.UploadsPath, attachment.InternalFilename); _mockFileService .Setup(m => m.FileExists(path)) .Returns(true); // Act await _handler.Handle(request, CancellationToken.None); // Assert Assert.IsFalse(await _wolkDbContext.Attachments.AnyAsync()); _mockFileService .Verify(m => m.DeleteFile(path), Times.Once); }
public async Task <ActionResult> DeleteAttachment([FromRoute] DeleteAttachmentCommand command) { await Mediator.Send(command); return(NoContent()); }
public static Task <DocumentHeaderResponse> ExecuteAsync(this IClient client, DeleteAttachmentCommand cmd) { return(client.Attachments.DeleteAsync(cmd)); }
public Task HandleAsync(DeleteAttachmentCommand command) => _genericCommandHandler.DeleteAsync <Attachment>(command.Id);