コード例 #1
0
 public void RegisteringCommandWithNullThrows()
 {
     Assert.Throws<ArgumentNullException>(() =>
     {
         var compositeCommand = new CompositeCommand();
         compositeCommand.RegisterCommand(null);
     });
 }
コード例 #2
0
        public void RegisteringCommandTwiceThrows()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                var compositeCommand = new CompositeCommand();
                var duplicateCommand = new TestCommand();
                compositeCommand.RegisterCommand(duplicateCommand);

                compositeCommand.RegisterCommand(duplicateCommand);
            });

        }
コード例 #3
0
        public void ShouldIgnoreChangesToIsActiveDuringExecution()
        {
            var firstCommand = new MockActiveAwareCommand { IsActive = true };
            var secondCommand = new MockActiveAwareCommand { IsActive = true };

            // During execution set the second command to inactive, this should not affect the currently
            // executed selection.  
            firstCommand.ExecuteAction += new Action<object>((object parameter) => secondCommand.IsActive = false);

            var compositeCommand = new CompositeCommand(true);

            compositeCommand.RegisterCommand(firstCommand);
            compositeCommand.RegisterCommand(secondCommand);

            compositeCommand.Execute(null);

            Assert.True(secondCommand.WasExecuted);
        }
コード例 #4
0
 public void RegisteringCommandInItselfThrows()
 {
     Assert.Throws<ArgumentException>(() =>
     {
         var compositeCommand = new CompositeCommand();
         compositeCommand.RegisterCommand(compositeCommand);
     });
 }
コード例 #5
0
        public void ShouldNotMonitorActivityIfUseActiveMonitoringFalse()
        {
            var mockCommand = new MockActiveAwareCommand();
            mockCommand.IsValid = true;
            mockCommand.IsActive = true;
            var nonActiveAwareCompositeCommand = new CompositeCommand(false);
            bool canExecuteChangedRaised = false;
            nonActiveAwareCompositeCommand.RegisterCommand(mockCommand);
            nonActiveAwareCompositeCommand.CanExecuteChanged += delegate
            {
                canExecuteChangedRaised = true;
            };

            mockCommand.IsActive = false;

            Assert.False(canExecuteChangedRaised);

            nonActiveAwareCompositeCommand.Execute(null);

            Assert.True(mockCommand.WasExecuted);
        }
コード例 #6
0
        public void ShouldRemoveCanExecuteChangedHandler()
        {
            bool canExecuteChangedRaised = false;

            var compositeCommand = new CompositeCommand();
            var commmand = new DelegateCommand(() => { });
            compositeCommand.RegisterCommand(commmand);

            EventHandler handler = (s, e) => canExecuteChangedRaised = true;

            compositeCommand.CanExecuteChanged += handler;
            commmand.RaiseCanExecuteChanged();

            Assert.True(canExecuteChangedRaised);

            canExecuteChangedRaised = false;
            compositeCommand.CanExecuteChanged -= handler;
            commmand.RaiseCanExecuteChanged();

            Assert.False(canExecuteChangedRaised);
        }
コード例 #7
0
        public void DispatchCommandShouldIgnoreInactiveCommandsInCanExecuteVote()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand commandOne = new MockActiveAwareCommand() { IsActive = false, IsValid = false };
            MockActiveAwareCommand commandTwo = new MockActiveAwareCommand() { IsActive = true, IsValid = true };

            activeAwareCommand.RegisterCommand(commandOne);
            activeAwareCommand.RegisterCommand(commandTwo);

            Assert.True(activeAwareCommand.CanExecute(null));
        }
コード例 #8
0
 public void RegisteringCommandWithNullThrows()
 {
     var compositeCommand = new CompositeCommand();
     compositeCommand.RegisterCommand(null);
 }
コード例 #9
0
        public void MultiDispatchCommandDoesNotExecutesInactiveRegisteredCommands()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            command.IsActive = false;
            activeAwareCommand.RegisterCommand(command);

            activeAwareCommand.Execute(null);

            Assert.False(command.WasExecuted);
        }
コード例 #10
0
        public void DispatchCommandDoesNotIncludeInactiveRegisteredCommandInVoting()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            activeAwareCommand.RegisterCommand(command);
            command.IsValid = true;
            command.IsActive = false;

            Assert.False(activeAwareCommand.CanExecute(null), "Registered Click is inactive so should not participate in CanExecute vote");

            command.IsActive = true;

            Assert.True(activeAwareCommand.CanExecute(null));

            command.IsValid = false;

            Assert.False(activeAwareCommand.CanExecute(null));

        }
コード例 #11
0
        public void MultiDispatchCommandExecutesActiveRegisteredCommands()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand();
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            command.IsActive = true;
            activeAwareCommand.RegisterCommand(command);

            activeAwareCommand.Execute(null);

            Assert.True(command.WasExecuted);
        }
コード例 #12
0
        public void UnregisterCommandDisconnectsIsActiveChangedDelegate()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand commandOne = new MockActiveAwareCommand() { IsActive = true, IsValid = true };
            MockActiveAwareCommand commandTwo = new MockActiveAwareCommand() { IsActive = false, IsValid = false };
            activeAwareCommand.RegisterCommand(commandOne);
            activeAwareCommand.RegisterCommand(commandTwo);

            Assert.True(activeAwareCommand.CanExecute(null));

            activeAwareCommand.UnregisterCommand(commandOne);

            Assert.False(activeAwareCommand.CanExecute(null));
        }
コード例 #13
0
        public void RegisteringCommandTwiceThrows()
        {
            var compositeCommand = new CompositeCommand();
            var duplicateCommand = new TestCommand();
            compositeCommand.RegisterCommand(duplicateCommand);

            compositeCommand.RegisterCommand(duplicateCommand);
        }
コード例 #14
0
        public void ShouldGetRegisteredCommands()
        {
            var firstCommand = new TestCommand();
            var secondCommand = new TestCommand();

            var compositeCommand = new CompositeCommand();
            compositeCommand.RegisterCommand(firstCommand);
            compositeCommand.RegisterCommand(secondCommand);

            var commands = compositeCommand.RegisteredCommands;

            Assert.True(commands.Count > 0);
        }
コード例 #15
0
        public void ActivityCausesActiveAwareCommandToRequeryCanExecute()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            activeAwareCommand.RegisterCommand(command);
            command.IsActive = true;

            bool globalCanExecuteChangeFired = false;
            activeAwareCommand.CanExecuteChanged += delegate
                                                        {
                                                            globalCanExecuteChangeFired = true;
                                                        };

            Assert.False(globalCanExecuteChangeFired);
            command.IsActive = false;
            Assert.True(globalCanExecuteChangeFired);
        }
コード例 #16
0
 public SelfUnregisterableCommand(CompositeCommand command)
 {
     Command = command;
 }
コード例 #17
0
        public void RegisteringCommandInItselfThrows()
        {
            var compositeCommand = new CompositeCommand();

            compositeCommand.RegisterCommand(compositeCommand);
        }