public void Scheduled_Task_Null_Test() { IServiceCollection services = new ServiceCollection(); services.AddHostedService <QueuedHostedService>(); services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>(); var serviceProvider = services.BuildServiceProvider(); var service = serviceProvider.GetService <IHostedService>() as QueuedHostedService; var backgroundQueue = serviceProvider.GetService <IBackgroundTaskQueue>(); ScheduledTask testScheduledTask = new ScheduledTask(backgroundQueue); var ex = Assert.ThrowsException <ArgumentNullException>(() => testScheduledTask.AddScheduledTask(null)); Assert.IsTrue(ex.Message.Contains("ScheduledTask cannot be null!")); }
public void Scheduled_Task_Null_Expression_Test() { IServiceCollection services = new ServiceCollection(); services.AddHostedService <QueuedHostedService>(); services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>(); var serviceProvider = services.BuildServiceProvider(); var service = serviceProvider.GetService <IHostedService>() as QueuedHostedService; var backgroundQueue = serviceProvider.GetService <IBackgroundTaskQueue>(); var taskModel = new ScheduledTaskModel(); ScheduledTask testScheduledTask = new ScheduledTask(backgroundQueue); var ex = Assert.ThrowsException <ArgumentException>(() => testScheduledTask.AddScheduledTask(taskModel)); Assert.IsTrue(ex.Message.Contains("ScheduledTask has to have a schedule expression!")); }