Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
 /// <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);
 }
Exemplo n.º 3
0
        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);
        }