Exemplo n.º 1
0
        public void Reset_LeavesCanceledState()
        {
            var command = new CancelCommand();
            var token = command.CancellationToken;
            object observedSender = null;
            bool observedCanExecute = false;
            EventHandler subscription = (s, _) =>
            {
                observedSender = s;
                observedCanExecute = ((ICommand)command).CanExecute(null);
            };

            command.Cancel();
            ((ICommand)command).CanExecuteChanged += subscription;
            command.Reset();

            Assert.True(token.IsCancellationRequested);
            Assert.False(command.CancellationToken.IsCancellationRequested);
            Assert.False(command.IsCancellationRequested);
            Assert.True(((ICommand)command).CanExecute(null));
            Assert.Same(command, observedSender);
            Assert.True(observedCanExecute);

            ((ICommand)command).CanExecuteChanged -= subscription;
        }
Exemplo n.º 2
0
 public void AfterConstruction_IsNotCanceled()
 {
     var command = new CancelCommand();
     Assert.False(command.CancellationToken.IsCancellationRequested);
     Assert.False(command.IsCancellationRequested);
     Assert.True(command.CancellationToken.CanBeCanceled);
     Assert.True(((ICommand)command).CanExecute(null));
 }
Exemplo n.º 3
0
 public RefCountedCancellationTokenSource(CancelCommand parent)
 {
     _parent = parent;
 }