Exemple #1
0
        public void StopOperation_EntersCanceledState()
        {
            var command   = new CancelCommand();
            var operation = command.StartOperation();

            var          token              = command.CancellationToken;
            object       observedSender     = null;
            bool         observedCanExecute = true;
            EventHandler subscription       = (s, _) =>
            {
                observedSender     = s;
                observedCanExecute = ((ICommand)command).CanExecute(null);
            };

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

            operation.Dispose();

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

            ((ICommand)command).CanExecuteChanged -= subscription;
        }
Exemple #2
0
        public void Operations_AreReferenceCounted()
        {
            var command    = new CancelCommand();
            var operation1 = command.StartOperation();
            var operation2 = command.StartOperation();

            operation2.Dispose();

            Assert.False(command.CancellationToken.IsCancellationRequested);
            Assert.False(command.IsCancellationRequested);
            Assert.True(((ICommand)command).CanExecute(null));

            operation1.Dispose();

            Assert.True(command.CancellationToken.IsCancellationRequested);
            Assert.True(command.IsCancellationRequested);
            Assert.False(((ICommand)command).CanExecute(null));
        }