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_stop_all_stoppables() { var startable1 = new Startable1(); var startable2 = new Startable2(); var thingsToBeStarted = new IWantToRunWhenEndpointStartsAndStops[] { startable1, startable2 }; var runner = new StartableAndStoppableRunner(thingsToBeStarted); await runner.Start(null); await runner.Stop(null); Assert.True(startable1.Stopped); Assert.True(startable2.Stopped); }
#pragma warning disable 0618 static async Task <Mock <ILog> > RunStartableWarningTest(IWantToRunWhenEndpointStartsAndStops instanceToTest) { var thingsToBeStarted = new[] { instanceToTest }; var mockLogger = new Mock <ILog>(); var runner = new StartableAndStoppableRunner(thingsToBeStarted) { LongRunningWarningTimeSpan = TimeToWarn }; StartableAndStoppableRunner.Log = mockLogger.Object; await runner.Start(null); await runner.Stop(null); return(mockLogger); }
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); }