public async Task WaitBlockersAsynс_DropBlockerCancelAwaitingOfBlockerRelease_WaitingContinuesExecution() { // ARRANGE using var animationBlockerService = new AnimationBlockerService(); var blockerMock = new Mock <ICommandBlocker>(); var blocker = blockerMock.Object; animationBlockerService.AddBlocker(blocker); using var semaphore = new SemaphoreSlim(0, 1); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { await Task.Delay(100).ConfigureAwait(false); await semaphore.WaitAsync().ConfigureAwait(false); animationBlockerService.DropBlockers(); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed // ACT var serviceTask = Task.Run(async() => { await animationBlockerService.WaitBlockersAsync().ConfigureAwait(false); }); semaphore.Release(); await serviceTask.ConfigureAwait(false); // ASSERT Assert.Pass(); }
private static async Task AddAndDropBlockerAsync(AnimationBlockerService animationBlockerService, SemaphoreSlim semaphore) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { await Task.Delay(100).ConfigureAwait(false); await semaphore.WaitAsync().ConfigureAwait(false); animationBlockerService.DropBlockers(); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed // ACT var serviceTask = Task.Run(async() => { await animationBlockerService.WaitBlockersAsync().ConfigureAwait(false); }); semaphore.Release(); await serviceTask.ConfigureAwait(false); }