Пример #1
0
        public void RegisterACommandShouldRaiseCanExecuteEvent()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommand = new TestCommand();

            multiCommand.RegisterCommand(new TestCommand());
            Assert.True(multiCommand.CanExecuteChangedRaised);
        }
Пример #2
0
        public void ShouldDelegateCanExecuteToSingleRegistrant()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommand = new TestCommand();

            multiCommand.RegisterCommand(testCommand);

            Assert.False(testCommand.CanExecuteCalled);
            multiCommand.CanExecute(null);
            Assert.True(testCommand.CanExecuteCalled);
        }
Пример #3
0
        public void ShouldBubbleException()
        {
            Assert.Throws <DivideByZeroException>(() =>
            {
                TestableCompositeCommand multiCommand = new TestableCompositeCommand();
                BadDivisionCommand testCommand        = new BadDivisionCommand();

                multiCommand.RegisterCommand(testCommand);
                multiCommand.Execute(null);
            });
        }
Пример #4
0
        public void CanExecuteShouldReturnTrueIfAllRegistrantsTrue()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne = new TestCommand() { CanExecuteValue = true };
            TestCommand testCommandTwo = new TestCommand() { CanExecuteValue = true };

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.RegisterCommand(testCommandTwo);

            Assert.True(multiCommand.CanExecute(null));
        }
Пример #5
0
        public void ShouldDelegateCanExecuteToSingleRegistrant()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommand = new TestCommand();

            multiCommand.RegisterCommand(testCommand);

            Assert.False(testCommand.CanExecuteCalled);
            multiCommand.CanExecute(null);
            Assert.True(testCommand.CanExecuteCalled);
        }
Пример #6
0
        public void UnregisterCommandShouldRaiseCanExecuteEvent()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne            = new TestCommand();

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.CanExecuteChangedRaised = false;
            multiCommand.UnregisterCommand(testCommandOne);

            Assert.True(multiCommand.CanExecuteChangedRaised);
        }
Пример #7
0
        public void ExecuteDoesNotThrowWhenAnExecuteCommandModifiesTheCommandsCollection()
        {
            TestableCompositeCommand  multiCommand = new TestableCompositeCommand();
            SelfUnregisterableCommand commandOne   = new SelfUnregisterableCommand(multiCommand);
            SelfUnregisterableCommand commandTwo   = new SelfUnregisterableCommand(multiCommand);

            multiCommand.RegisterCommand(commandOne);
            multiCommand.RegisterCommand(commandTwo);

            multiCommand.Execute(null);

            Assert.True(commandOne.ExecutedCalled);
            Assert.True(commandTwo.ExecutedCalled);
        }
Пример #8
0
        public void UnregisterCommandDisconnectsCanExecuteChangedDelegate()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne            = new TestCommand()
            {
                CanExecuteValue = true
            };

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.UnregisterCommand(testCommandOne);
            multiCommand.CanExecuteChangedRaised = false;
            testCommandOne.FireCanExecuteChanged();
            Assert.False(multiCommand.CanExecuteChangedRaised);
        }
Пример #9
0
        public void ShouldReraiseCanExecuteChangedEvent()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne            = new TestCommand()
            {
                CanExecuteValue = true
            };

            Assert.False(multiCommand.CanExecuteChangedRaised);
            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.CanExecuteChangedRaised = false;

            testCommandOne.FireCanExecuteChanged();
            Assert.True(multiCommand.CanExecuteChangedRaised);
        }
Пример #10
0
        public void ShouldReraiseDelegateCommandCanExecuteChangedEventAfterCollect()
        {
            TestableCompositeCommand multiCommand    = new TestableCompositeCommand();
            DelegateCommand <object> delegateCommand = new DelegateCommand <object>(delegate { });

            Assert.False(multiCommand.CanExecuteChangedRaised);
            multiCommand.RegisterCommand(delegateCommand);
            multiCommand.CanExecuteChangedRaised = false;

            GC.Collect();

            delegateCommand.RaiseCanExecuteChanged();

            Assert.True(multiCommand.CanExecuteChangedRaised);
        }
Пример #11
0
        public void UnregisterCommandRemovesFromExecuteDelegation()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne            = new TestCommand()
            {
                CanExecuteValue = true
            };

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.UnregisterCommand(testCommandOne);

            Assert.False(testCommandOne.ExecuteCalled);
            multiCommand.Execute(null);
            Assert.False(testCommandOne.ExecuteCalled);
        }
Пример #12
0
        public void ShouldDelegateCanExecuteToMultipleRegistrants()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne            = new TestCommand();
            TestCommand testCommandTwo            = new TestCommand();

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.RegisterCommand(testCommandTwo);

            Assert.False(testCommandOne.CanExecuteCalled);
            Assert.False(testCommandTwo.CanExecuteCalled);
            multiCommand.CanExecute(null);
            Assert.True(testCommandOne.CanExecuteCalled);
            Assert.True(testCommandTwo.CanExecuteCalled);
        }
Пример #13
0
        public void ShouldDelegateCanExecuteToMultipleRegistrants()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne = new TestCommand();
            TestCommand testCommandTwo = new TestCommand();

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.RegisterCommand(testCommandTwo);

            Assert.False(testCommandOne.CanExecuteCalled);
            Assert.False(testCommandTwo.CanExecuteCalled);
            multiCommand.CanExecute(null);
            Assert.True(testCommandOne.CanExecuteCalled);
            Assert.True(testCommandTwo.CanExecuteCalled);
        }
Пример #14
0
        public void CanExecuteShouldReturnFalseIfASingleRegistrantsFalse()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne            = new TestCommand()
            {
                CanExecuteValue = true
            };
            TestCommand testCommandTwo = new TestCommand()
            {
                CanExecuteValue = false
            };

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.RegisterCommand(testCommandTwo);

            Assert.False(multiCommand.CanExecute(null));
        }
Пример #15
0
        public void ShouldReraiseCanExecuteChangedEventAfterCollect()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne = new TestCommand() { CanExecuteValue = true };

            Assert.False(multiCommand.CanExecuteChangedRaised);
            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.CanExecuteChangedRaised = false;

            GC.Collect();

            testCommandOne.FireCanExecuteChanged();
            Assert.True(multiCommand.CanExecuteChangedRaised);
        }
Пример #16
0
 public void CanExecuteShouldReturnFalseWithNoCommandsRegistered()
 {
     TestableCompositeCommand multiCommand = new TestableCompositeCommand();
     Assert.False(multiCommand.CanExecute(null));
 }
Пример #17
0
        public void ShouldReraiseDelegateCommandCanExecuteChangedEventAfterCollect()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            DelegateCommand<object> delegateCommand = new DelegateCommand<object>(delegate { });

            Assert.False(multiCommand.CanExecuteChangedRaised);
            multiCommand.RegisterCommand(delegateCommand);
            multiCommand.CanExecuteChangedRaised = false;

            GC.Collect();

            delegateCommand.RaiseCanExecuteChanged();

            Assert.True(multiCommand.CanExecuteChangedRaised);
        }
Пример #18
0
        public void CanExecuteShouldReturnFalseWithNoCommandsRegistered()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();

            Assert.False(multiCommand.CanExecute(null));
        }
Пример #19
0
        public void UnregisterCommandRemovesFromExecuteDelegation()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne = new TestCommand() { CanExecuteValue = true };

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.UnregisterCommand(testCommandOne);

            Assert.False(testCommandOne.ExecuteCalled);
            multiCommand.Execute(null);
            Assert.False(testCommandOne.ExecuteCalled);
        }
Пример #20
0
        public void UnregisterCommandShouldRaiseCanExecuteEvent()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne = new TestCommand();

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.CanExecuteChangedRaised = false;
            multiCommand.UnregisterCommand(testCommandOne);

            Assert.True(multiCommand.CanExecuteChangedRaised);
        }
Пример #21
0
        public void ExecuteDoesNotThrowWhenAnExecuteCommandModifiesTheCommandsCollection()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            SelfUnregisterableCommand commandOne = new SelfUnregisterableCommand(multiCommand);
            SelfUnregisterableCommand commandTwo = new SelfUnregisterableCommand(multiCommand);

            multiCommand.RegisterCommand(commandOne);
            multiCommand.RegisterCommand(commandTwo);

            multiCommand.Execute(null);

            Assert.True(commandOne.ExecutedCalled);
            Assert.True(commandTwo.ExecutedCalled);
        }
Пример #22
0
        public void UnregisterCommandDisconnectsCanExecuteChangedDelegate()
        {
            TestableCompositeCommand multiCommand = new TestableCompositeCommand();
            TestCommand testCommandOne = new TestCommand() { CanExecuteValue = true };

            multiCommand.RegisterCommand(testCommandOne);
            multiCommand.UnregisterCommand(testCommandOne);
            multiCommand.CanExecuteChangedRaised = false;
            testCommandOne.FireCanExecuteChanged();
            Assert.False(multiCommand.CanExecuteChangedRaised);
        }
Пример #23
0
        public void ShouldBubbleException()
        {
            Assert.Throws<DivideByZeroException>(() =>
            {
                TestableCompositeCommand multiCommand = new TestableCompositeCommand();
                BadDivisionCommand testCommand = new BadDivisionCommand();

                multiCommand.RegisterCommand(testCommand);
                multiCommand.Execute(null);
            });
        }