public async Task Validate_ValidCommand_ShouldBeTrueAsync() { //// Arrange var sut = new PinAttachFileCommandHandler(_context); var command = new PinAttachFileCommand { MessageId = validMessageId, BlobStorageUrl = validBlobStorageUrl, IsPinFile = true }; /// Act await sut.Handle(command, CancellationToken.None); var entity = _context.MessageChats.Find(validMessageId); entity.ShouldNotBeNull(); var attachFile = entity.AttachFileList .Where(file => file.BlobStorageUrl == validBlobStorageUrl) .FirstOrDefault(); attachFile.IsPin.ShouldBe(true); }
public void Validate_ValidCommand_ShouldBeTrue() { var command = new PinAttachFileCommand { MessageId = Guid.NewGuid(), BlobStorageUrl = "https://domain.com/blob-container/kxg5qfz4.jxl", IsPinFile = true }; var validator = new PinAttachFileCommandValidator(); var result = validator.Validate(command); result.IsValid.ShouldBe(true); }
public void Validate_BlobStorageUrlEmptyOrNull_ShouldBeFalse() { var command = new PinAttachFileCommand { MessageId = Guid.NewGuid(), BlobStorageUrl = null, IsPinFile = true }; var validator = new PinAttachFileCommandValidator(); var result = validator.Validate(command); result.IsValid.ShouldBe(false); }
public async Task Handle_GivenInvalidBlobStorageUrl_ShouldRaiseException() { //// Arrange var sut = new PinAttachFileCommandHandler(_context); var command = new PinAttachFileCommand { MessageId = validMessageId, BlobStorageUrl = "invalid-url/invalid-file-name", IsPinFile = true }; //// Act await Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(command, CancellationToken.None)); }
public async Task <ActionResult> PinAttachedFile(Guid messageId, PinAttachFileCommand command) { if (messageId != command.MessageId) { return(BadRequest()); } // cap nhat lai message chat await Mediator.Send(command); // query message chat var messageChat = await Mediator.Send(new GetMessageChatByIdQuery { MessageChatId = command.MessageId }); var attachFile = messageChat.AttachFileList? .Where(file => file.BlobStorageUrl == command.BlobStorageUrl) .FirstOrDefault(); // query other members of the conversation var conversation = await Mediator.Send(new GetConversationQuery { ConversationId = messageChat.ConversationId.ToString() }); // notify to other members of conversation about the new update message chat await _hubContext.Clients.Groups(conversation.Id.ToString()).SendAsync("PinFile", new PinMessageDto { PinnedFile = new FileDto { MessageId = messageChat.Id, ConversationId = messageChat.ConversationId, BlobStorageUrl = command.BlobStorageUrl, IsPin = command.IsPinFile, FileName = attachFile.FileName, FileSize = attachFile.FileSize, FileStorageName = attachFile.FileStorageName, LocalUrl = attachFile.LocalUrl, ThumbnailImage = attachFile.ThumbnailImage, }, PinnedMessage = messageChat, PinnedDiscriminator = "PinnedFile" }); return(Ok()); }
public async Task GivenInvalidMessageId_ShouldRaiseBadRequest() { var client = await _factory.GetAuthenticatedClientAsync(); // init DB for test var context = _factory.InitializeDbForTests(); var messageId = Guid.Parse("B73477A4-F61D-46FA-873C-7D71C01DFBDF"); PinAttachFileCommand command = new PinAttachFileCommand() { MessageId = Guid.NewGuid(), BlobStorageUrl = "", IsPinFile = true }; var content = IntegrationTestHelper.GetRequestContent(command); var response = await client.PutAsync($"/api/Messages/pin-attached-file/{messageId}", content); response.StatusCode.ShouldBe(HttpStatusCode.BadRequest); // release DB _factory.DisposeDbForTests(context); }