Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Activate Hangfire in Tests #6040


User avatar
0
statuscast created

Hi,

I have been partially successful at getting Hangfire working within the XUnit tests. However, I am having one last (I hope) issue. I simply added the following to MyProjectTestModule.cs Preinitialize:

Configuration.BackgroundJobs.UseHangfire(); GlobalConfiguration.Configuration.UseSqlServerStorage(configuration["ConnectionStrings:Hangfire"]);

However, since the structure of the Xunit app does not provide a Configure startup mechanism, where do we put startup code:

                var options = new BackgroundJobServerOptions
                {
                    WorkerCount = Environment.ProcessorCount * threads,
                    Queues = queues,
                    ServerTimeout = new TimeSpan(0, 2, 0)
                };
                app.UseHangfireServer(options);
            
            

Thank you.


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Your can refer this issue:https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3772

  • User Avatar
    0
    statuscast created

    I'm sorry but I have no clue how that article helps me get access to the IApplicationBuilder app in to an Xunit application that has no Configure() method in the first place.

    I apologize for missing something....?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @statuscast,

    I haven't tried this but you should do something like this I guess;

    http://docs.hangfire.io/en/latest/background-processing/processing-jobs-in-console-app.html