コード例 #1
0
        public void ShouldReEnableButtonIfCanExecuteChangedRaises()
        {
            var clickableObject = new MockClickableObject();
            var mockCommand = new MockCommand() { CanExecuteReturnValue = false };

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = mockCommand;
            Assert.IsFalse(clickableObject.IsEnabled);

            mockCommand.CanExecuteReturnValue = true;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsTrue(clickableObject.IsEnabled);
        }
コード例 #2
0
        public void DisposedControlDoesNotThrowOnCanExecuteChanged()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            WeakReference controlWeakReference = new WeakReference(clickableObject);
            clickableObject = null;
            behavior = null;
            GC.Collect();

            command.CanExecuteReturnValue = false;
            command.RaiseCanExecuteChanged();
        }
コード例 #3
0
        public void DisposedControlStopsMonitoringCommandAfterFirstCanExecuteChanged()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            clickableObject = null;
            WeakReference commandReference = new WeakReference(command);
            GC.Collect();

            command.CanExecuteReturnValue = false;
            command.RaiseCanExecuteChanged();
            command = null;

            GC.Collect();

            Assert.IsFalse(commandReference.IsAlive);
        }
コード例 #4
0
        public void ShouldNotMonitorCanExecuteChangedOnDisconnectedCommand()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            behavior.Command = null;

            Assert.IsTrue(clickableObject.IsEnabled);
            command.CanExecuteReturnValue = false;
            command.RaiseCanExecuteChanged();
            Assert.IsTrue(clickableObject.IsEnabled);
        }