Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Create PerformContext for unit tests for RecurringJob

Open netmajor opened this issue 3 years ago • 0 comments

Hi, I am using PerformContext to write message to dashboard console. It works fine ;) But I am wanted to write unit tests for job, so I need to mock somehow PerformContext. Currently it is injected as a parameter, but create new PerformContext in test it is problematic.... I dont know kow to create new instance od this class And second problem, hot to pass PerformContext in tests for GetForCurrentDay method?

RecurringJob.AddOrUpdate<Consumer>(x => x.Run(null), "30 8 * * TUE-SAT", TimeZoneInfo.Local);
[AutomaticRetry(Attempts = 5, DelaysInSeconds = new[] { 3600 })]
        public async Task Run(PerformContext context)
        {
            try
            {
                             var result = _service.GetForCurrentDay(context);     
        }
   Service service =
                newService();
       var result =     service.GetForCurrentDay(new PerformContext(JobStorage.Current, new SqlServerConnection(), ...));

netmajor avatar May 17 '22 11:05 netmajor