예제 #1
0
        public void Cancel_TriggersCommandCancellationToken()
        {
            // Arrange
            using (EventWaitHandle executeStarted = new ManualResetEvent(initialState: false))
                using (EventWaitHandle executeFinished = new ManualResetEvent(initialState: false))
                {
                    bool cancellationTokenSignalled = false;

                    ITaskSeriesCommand command = CreateCommand((cancellationToken) =>
                    {
                        Assert.True(executeStarted.Set());  // Guard
                        cancellationTokenSignalled = cancellationToken.WaitHandle.WaitOne(1000);
                        Assert.True(executeFinished.Set()); // Guard
                        return(new TaskSeriesCommandResult(wait: Task.Delay(0)));
                    });

                    using (ITaskSeriesTimer product = CreateProductUnderTest(command))
                    {
                        product.Start();
                        Assert.True(executeStarted.WaitOne(1000)); // Guard

                        // Act
                        product.Cancel();

                        // Assert
                        Assert.True(executeFinished.WaitOne(1000)); // Guard
                        Assert.True(cancellationTokenSignalled);

                        // Cleanup
                        product.StopAsync(CancellationToken.None).GetAwaiter().GetResult();
                    }
                }
        }
예제 #2
0
        public void Cancel_IfDisposed_Throws()
        {
            // Arrange
            ITaskSeriesCommand command = CreateDummyCommand();
            ITaskSeriesTimer   product = CreateProductUnderTest(command);

            product.Dispose();

            // Act & Assert
            ExceptionAssert.ThrowsObjectDisposed(() => product.Cancel());
        }
예제 #3
0
 public void Cancel()
 {
     ThrowIfDisposed();
     _timer.Cancel();
 }
예제 #4
0
 public void EnsureAllCanceled()
 {
     _strategy.Cancel();
     _timer.Cancel();
 }
 public void Cancel()
 {
     _timer.Cancel();
     _innerListener.Cancel();
 }