public async Task SendFile_Exception_ShouldAddToFailedTransmission() { var transmissionLinkMock = new Mock <ITransmissionLink>(); transmissionLinkMock.Setup(x => x.SendFile(It.IsAny <Recipient>(), It.IsAny <Folder>(), It.IsAny <File>())) .Callback <Recipient, Folder, File>((x, y, z) => { throw new InvalidOperationException(); }); Guid transmittedFileId = Guid.Empty; Guid transmittedRecipientId = Guid.Empty; var transmissionRepositoryMock = new Mock <ITransmissionRepository>(); transmissionRepositoryMock.Setup(x => x.AddFailedFileTransmission(It.IsAny <Guid>(), It.IsAny <Guid>())) .Callback <Guid, Guid>((x, y) => { transmittedFileId = x; transmittedRecipientId = y; }) .ReturnsAsync(() => Result.Success()); var recipient = Helper.GetRecipientModel("testRecipient"); var folder = Helper.GetFolderModel("testFolder"); var file = Helper.GetFileModel(); var transmissionService = new TransmissionService(transmissionLinkMock.Object, transmissionRepositoryMock.Object); var canContinue = await transmissionService.SendFile(recipient, folder, file); Assert.AreEqual(recipient.Id, transmittedRecipientId); Assert.AreEqual(file.Id, transmittedFileId); Assert.IsTrue(canContinue); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var th = new Thread(async() => { WorkerLog.Instance.Information($"Starting {nameof(FileExportWorker)}"); var incomingQueue = _workerQueueContainer.ToSendFiles.Reader; var outgoingQueue = _workerQueueContainer.ToProcessFiles.Writer; while (await incomingQueue.WaitToReadAsync() || !stoppingToken.IsCancellationRequested) { var file = await incomingQueue.ReadAsync(); var folderResult = await _folderRepository.GetFolder(file.FolderId); if (folderResult.WasSuccessful) { var recipients = file is RequestFile rf ? rf.Recipients : folderResult.Data.Recipients; foreach (var recipient in recipients) { await _communicationService.SendFile(recipient, folderResult.Data, file); } if (await outgoingQueue.WaitToWriteAsync()) { await outgoingQueue.WriteAsync(file); } } } }); th.Start(); await Task.Delay(Timeout.Infinite); _recipientsAddedNotificationSubscription.Dispose(); }
public async Task SendFile_ShouldCallTransmissionLinkSendFile() { Recipient transmittedRecipient = null; Folder transmittedFolder = null; File transmittedFile = null; var transmissionLinkMock = new Mock <ITransmissionLink>(); transmissionLinkMock.Setup(x => x.SendFile(It.IsAny <Recipient>(), It.IsAny <Folder>(), It.IsAny <File>())) .Callback <Recipient, Folder, File>((x, y, z) => { transmittedRecipient = x; transmittedFolder = y; transmittedFile = z; }); var transmissionRepositoryMock = new Mock <ITransmissionRepository>(); transmissionRepositoryMock.Setup(x => x.AddFailedFileTransmission(It.IsAny <Guid>(), It.IsAny <Guid>())); var recipient = Helper.GetRecipientModel("testRecipient"); var folder = Helper.GetFolderModel("testFolder"); var file = Helper.GetFileModel(); var transmissionService = new TransmissionService(transmissionLinkMock.Object, transmissionRepositoryMock.Object); await transmissionService.SendFile(recipient, folder, file); Assert.AreSame(recipient, transmittedRecipient); Assert.AreSame(folder, transmittedFolder); Assert.AreSame(file, transmittedFile); }
private async Task RetryFailedTransmisionFiles() { WorkerLog.Instance.Information($"Retrying to send files that have failed"); var failedFilesResult = await _transmissionRepository.GetFailedFileTransmission(); if (failedFilesResult.WasSuccessful) { foreach (var ff in failedFilesResult.Data) { var wasSucessful = await _transmissionService.SendFile(ff.Item3, ff.Item2, ff.Item1); if (wasSucessful) { await _transmissionRepository.DeleteFailedFileTransmission(ff.Item1.Id, ff.Item3.Id); } } } }
public async Task SendFile_ExceptionDuringAddFailedTransmission_ShouldNotContinue() { var transmissionLinkMock = new Mock <ITransmissionLink>(); transmissionLinkMock.Setup(x => x.SendFile(It.IsAny <Recipient>(), It.IsAny <Folder>(), It.IsAny <File>())) .Callback <Recipient, Folder, File>((x, y, z) => { throw new InvalidOperationException(); }); var transmissionRepositoryMock = new Mock <ITransmissionRepository>(); transmissionRepositoryMock.Setup(x => x.AddFailedFileTransmission(It.IsAny <Guid>(), It.IsAny <Guid>())) .ReturnsAsync(() => Result.Failure()); var recipient = Helper.GetRecipientModel("testRecipient"); var folder = Helper.GetFolderModel("testFolder"); var file = Helper.GetFileModel(); var transmissionService = new TransmissionService(transmissionLinkMock.Object, transmissionRepositoryMock.Object); var canContinue = await transmissionService.SendFile(recipient, folder, file); Assert.IsFalse(canContinue); }