Exemplo n.º 1
0
            public TestBackgroundJobServer(IFileSystem fileSystem, ServiceHost serviceHost, int startupDelay = 10000)
            {
                _memberName  = "QueueHangfireIntegrationTests";
                _fileSystem  = fileSystem;
                _serviceHost = serviceHost;

                // CleanupDatabase();

                var builder = new ContainerBuilder();

                builder.RegisterType <HangFireTestService>().As <IHangFireTestService>().InstancePerLifetimeScope();

                JobStorage = new SQLiteStorage(GetConnectionString());
                GlobalConfiguration.Configuration.UseStorage(JobStorage);
                GlobalConfiguration.Configuration.UseAutofacActivator(builder.Build());

                BackgroundJobServer = new BackgroundJobServer(JobStorage);

                BackgroundJobServer.Should().NotBeNull();
                Task.Delay(startupDelay).Wait();
            }
Exemplo n.º 2
0
        public async Task QueueHangfire_BackgroundServer_Run()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <HangFireTestService>().As <IHangFireTestService>().InstancePerLifetimeScope();

            GlobalConfiguration.Configuration.UseAutofacActivator(builder.Build());

            var storage = new SQLiteStorage(GetConnectionString(FileSystem, ServiceHost.HangfireTest));

            GlobalConfiguration.Configuration.UseStorage(storage);


            using (var server = new BackgroundJobServer())
            {
                server.Should().NotBeNull();

                var monitoringApi = storage.GetMonitoringApi();
                monitoringApi.Should().NotBeNull().And.Subject.Should().BeAssignableTo <IMonitoringApi>();

                const string testValue = "TestValue";

                var hangFireJob = new HangfireJob(testValue);

                var jobIdString = BackgroundJob.Enqueue <IHangFireTestService>(service =>
                                                                               service.ExecuteHangfireTestJobAsync(hangFireJob));

                jobIdString.Should().NotBeNull();
                int.TryParse(jobIdString, out var jobId).Should().BeTrue();
                jobId.Should().BeGreaterThan(0);

                var jobStatus = await JobQueueClient.WaitForJobToComplete(monitoringApi, jobIdString, 30 * 1000, CancellationToken.None);

                jobStatus.State.Should().Be(JobState.Succeeded);
            }
        }