public async Task Should_stop_only_successfully_started()
        {
            var startable1        = new Startable1();
            var startable2        = new Startable2();
            var syncThrows        = new SyncThrowingStart();
            var thingsToBeStarted = new IWantToRunWhenEndpointStartsAndStops[] { startable1, startable2, syncThrows };

            var runner = new StartableAndStoppableRunner(thingsToBeStarted);

            try
            {
                await runner.Start(null);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (InvalidOperationException)
            {
                // ignored
            }

            await runner.Stop(null);

            Assert.True(startable1.Stopped);
            Assert.True(startable2.Stopped);
            Assert.False(syncThrows.Stopped);
        }
        public async Task Should_start_all_startables()
        {
            var startable1        = new Startable1();
            var startable2        = new Startable2();
            var thingsToBeStarted = new IWantToRunWhenEndpointStartsAndStops[] { startable1, startable2 };

            var runner = new StartableAndStoppableRunner(thingsToBeStarted);

            await runner.Start(null);

            Assert.True(startable1.Started);
            Assert.True(startable2.Started);
        }
        public void Should_throw_if_startable_fails_synchronously()
        {
            var startable1        = new Startable1();
            var syncThrowable     = new SyncThrowingStart();
            var startable2        = new Startable2();
            var thingsToBeStarted = new IWantToRunWhenEndpointStartsAndStops[] { startable1, syncThrowable, startable2 };

            var runner = new StartableAndStoppableRunner(thingsToBeStarted);

            Assert.That(async() => await runner.Start(null), Throws.InvalidOperationException);

            Assert.True(startable1.Started);
            Assert.False(startable2.Started);
        }
        public async Task Should_not_rethrow_sync_exceptions_when_stopped()
        {
            var startable1        = new Startable1();
            var startable2        = new Startable2();
            var syncThrows        = new SyncThrowingStop();
            var thingsToBeStarted = new IWantToRunWhenEndpointStartsAndStops[] { startable1, syncThrows, startable2 };

            var runner = new StartableAndStoppableRunner(thingsToBeStarted);

            try
            {
                await runner.Start(null);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (InvalidOperationException)
            {
                // ignored
            }

            Assert.That(async() => await runner.Stop(null), Throws.Nothing);
            Assert.True(startable1.Stopped);
            Assert.True(startable2.Stopped);
        }