Пример #1
0
        public async Task ExecutesStartupTasks()
        {
            var startupTaskExecutor   = Substitute.For <IStartupTaskExecutor>();
            var backgroundServiceHost = Substitute.For <IBackgroundServiceHost>();

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

            await startupTaskExecutor.Received(1)
            .ExecuteAsync(Arg.Any <CancellationToken>());
        }
Пример #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>());
        }