Example #1
0
        public async Task StopsBackgroundServices()
        {
            var startupTaskExecutor   = Substitute.For <IStartupTaskExecutor>();
            var backgroundServiceHost = Substitute.For <IBackgroundServiceHost>();

            var adapter = new MicrosoftHostingAdapter(startupTaskExecutor, backgroundServiceHost);
            await adapter.StopAsync(CancellationToken.None);

            await backgroundServiceHost.Received(1)
            .StopAsync(Arg.Any <CancellationToken>());
        }
Example #2
0
        public async Task DoesNotStartupBackgroundServicesWhenStartupTaskThrows()
        {
            var startupTaskExecutor = Substitute.For <IStartupTaskExecutor>();

            startupTaskExecutor.ExecuteAsync(Arg.Any <CancellationToken>())
            .Throws(new InvalidOperationException());

            var backgroundServiceHost = Substitute.For <IBackgroundServiceHost>();

            var adapter = new MicrosoftHostingAdapter(startupTaskExecutor, backgroundServiceHost);

            try
            {
                await adapter.StartAsync(CancellationToken.None);
            }
            catch
            {
                // ignored
            }

            await backgroundServiceHost.DidNotReceive()
            .StartAsync(Arg.Any <CancellationToken>());
        }