private HttpClient CreateClient( DownloadJob.JobId newDownloadId, DownloadJobsDictionary downloadJobsDictionary, IFileSystem fileSystem, DelegatingHandler downloadsHttpClient, IHubContext <NotificationsHub, NotificationsHub.IClient> notificationsHubContext) { return (_factory .WithSettings( ("DownloadDirectories:Incomplete", "/incomplete"), ("DownloadDirectories:Completed", "/completed"), /* One millisecond interval to give ProgressNotificationsBackgroundService a chance to iterate * through dictionary while the test is executing - this can potentially cause a flaky test. * See SignalRMessagesShouldBeSent() verification for SendProgress in the Assert block below. */ ("PushNotifications:ProgressIntervalInMilliseconds", "1")) .WithServices(services => services .ReplaceAllWithSingleton(new DownloadManager.DownloadIdGenerator(() => newDownloadId)) .ReplaceAllWithSingleton(new DownloadManager.DateTimeUtcNowTicks(() => 42)) .ReplaceAllWithSingleton(downloadJobsDictionary) .ReplaceAllWithSingleton(fileSystem) .ReplaceAllWithSingleton(notificationsHubContext) .ReplaceHttpMessageHandlerFor <DownloadStarter>(downloadsHttpClient)) .CreateDefaultClient()); }
/// <summary> /// Async event handlers are not awaited so any exceptions thrown are lost. There's nothing more we can do /// but to log them. /// </summary> private void LogError <TMessage>( Exception exception, DownloadJob.JobId id) { _logger.LogError( exception, "Failed to send {messageType} for job {id}", typeof(TMessage).Name, id); }
private static Mock <IFileSystem> CreateAndSetupFileSystemMock( ISpecimenBuilder fixture, DownloadJob.JobId newDownloadId) { var fileSystemMock = fixture.Create <Mock <IFileSystem> >(); fileSystemMock .SetupGet(fs => fs.FileStream.Create($"/incomplete/{newDownloadId}", FileMode.CreateNew).CanWrite) .Returns(true); fileSystemMock /* Simulate saveAsFile.iso already existing to test name incrementing logic */ .Setup(fs => fs.File.Move( $"/incomplete/{newDownloadId}", "/completed/saveAsFile.iso", false)) .Throws <IOException>(); return(fileSystemMock); }