public async Task HostedServiceBase_WhenStartAndStopThrows_ShouldFireEvents()
        {
            // arrange
            var hostedService = new HostedServiceTest {
                StopShouldFail = true
            };
            var host = HostHelper.Build(hostedService);
            List <TelemetryEvent> events = new List <TelemetryEvent>();

            // act
            var hostStart = host.StartAsync();
            var start     = await hostedService.WaitStart;

            ApplicationEventSource.Log.Listen(listener =>
            {
                var hostStop = host.StopAsync();
                Task.Delay(100).GetAwaiter().GetResult();

                events.AddRange(listener
                                .OrderedEvents
                                .Select(e => e.Map("test"))
                                .ToArray());
            });

            // assert
            Assert.True(start);
            Assert.NotNull(events
                           .FirstOrDefault(e => e.Message == "Unhandled exception occurred."));
        }
        public async Task HostedServiceBase_WhenStartAndStop_ShouldPass()
        {
            // arrange
            var hostedService = new HostedServiceTest();
            var host          = HostHelper.Build(hostedService);

            // act
            var hostStart = host.StartAsync();
            var start     = await hostedService.WaitStart;
            var hostStop  = host.StopAsync();
            var stop      = await hostedService.WaitStop;

            // assert
            Assert.True(start);
            Assert.True(stop);
        }