public async Task RunAsync_Should_Throw_IfCancellationRequested() { // arrange var token = new CancellationTokenSource(); // act token.Cancel(); // assert await Assert.ThrowsAsync <OperationCanceledException>(() => _target.RunAsync(token.Token)); }
public static void Main(string[] args) { Configuration = GetConfig(args); IEmailTransportFactory transportFactory = EmailTransportFactory.Instance; Logger.LogInformation("Loading dependencies..."); SetupDependencies( out IEmailQueueReceiver <AzureEmailQueueMessage> receiver, out IEmailQueueBlobStore blobStore, out EmailServiceContext context, out IMemoryCache cache, out IEmailLogWriter logWriter); Logger.LogInformation("Intializing queue processor..."); var processor = new QueueProcessor <AzureEmailQueueMessage>( context, receiver, blobStore, transportFactory, logWriter, LoggerFactory); Logger.LogInformation("Listening for messages", ConsoleColor.Cyan); var task = processor.RunAsync(Cancellation.Token); task.ContinueWith(t => { var ex = t.Exception; if (ex != null) { Logger.LogCritical("Error listening to messages:\n{0}", ex); } Cancellation.Cancel(); }, TaskContinuationOptions.OnlyOnFaulted); Console.ReadLine(); Logger.LogInformation("Stopping service..."); Cancellation.Cancel(); }