public async Task HandleAsync(UpdateUserCommand command, CancellationToken cancellationToken = default) { var getUserResult = await _userGetterService.GetByIdAsync(command.UserId); if (!getUserResult.Success) { throw new ResourceNotFoundException(getUserResult.Errors); } UpdateAnnouncementPreferenceLimit(getUserResult.Value, command.AnnouncementPreferenceLimit, command.CorrelationId); UpdateAnnouncementSendingFrequency(getUserResult.Value, command.AnnouncementSendingFrequency, command.CorrelationId); getUserResult.Value.ChangeServiceActive(command.ServiceActive, command.CorrelationId); if (command.Picture != null && command.Picture.Data.Any()) { var pictureUrl = await _blobContainerService.UploadFileAsync(command.Picture.Data, $"image-{getUserResult.Value.Id.ToString().ToLower()}", command.Picture.ContentType); getUserResult.Value.ChangePicture(pictureUrl, command.CorrelationId); } await _communicationBus.DispatchDomainEventsAsync(getUserResult.Value, cancellationToken); await _userRepository.UpdateAsync(getUserResult.Value); var userUpdatedIntegrationEvent = new UserUpdatedIntegrationEvent(command.CorrelationId, getUserResult.Value.Id, getUserResult.Value.ServiceActive, getUserResult.Value.AnnouncementSendingFrequency.ConvertToEnum()); await _integrationEventBus.PublishIntegrationEventAsync(userUpdatedIntegrationEvent); }
public async Task UploadFileAsync_Should_Upload_File_To_Blob_Container() { const string fileName = "file123"; const string blobUri = "https://accountName/container/" + fileName; var expectedResult = $"/container/{fileName}"; var blobClientMock = new Mock <BlobClient>(); var uploadRespMock = new Mock <Response <BlobContentInfo> >(); var setMetadataRespMock = new Mock <Response <BlobInfo> >(); blobClientMock.Setup(x => x.UploadAsync(It.IsAny <Stream>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())) .ReturnsAsync(uploadRespMock.Object); blobClientMock.Setup(x => x.SetMetadataAsync(It.IsAny <IDictionary <string, string> >(), It.IsAny <BlobRequestConditions>(), It.IsAny <CancellationToken>())).ReturnsAsync(setMetadataRespMock.Object); blobClientMock.SetupGet(x => x.Uri).Returns(new Uri(blobUri)); _blobContainerClientMock.Setup(x => x.GetBlobClient(It.IsAny <string>())).Returns(blobClientMock.Object); var result = await _service.UploadFileAsync(Array.Empty <byte>(), fileName, "image/jpg"); result.Should().Be(expectedResult); }