示例#1
0
        public void GetProxyCommand_WithNoRegisteredRealCommand_HasCommandIsFalse()
        {
            ApplicationCommandManager cm = new ApplicationCommandManager();

            var proxyCmd = (CommandProxy)cm[TestCommands.New];

            Assert.IsFalse(proxyCmd.HasCommand);
        }
示例#2
0
        public void UnregisterCommand_CommandRegisteredIsFired()
        {
            bool regsiteredCommandsChangedRaised = false;

            ApplicationCommandManager cm = new ApplicationCommandManager();

            cm.RegisteredCommandsChanged += (s, e) => regsiteredCommandsChangedRaised = true;

            cm.UnregisterCommand(TestCommands.Close);
            Assert.IsTrue(regsiteredCommandsChangedRaised);
        }
示例#3
0
        public void GetProxyCommand_WithRegisteredRealCommand_HasCommandIsTrue()
        {
            ApplicationCommandManager cm = new ApplicationCommandManager();

            TestCommand cmd = new TestCommand();

            cm.RegisterCommand(TestCommands.New, cmd);

            var proxyCmd = (CommandProxy)cm[TestCommands.New];

            Assert.IsTrue(proxyCmd.HasCommand);
        }
示例#4
0
        public void CheckCanExecuteChanged()
        {
            ApplicationCommandManager cm = new ApplicationCommandManager();

            ICommand proxy = cm[TestCommands.Close];

            TestCommand cmd = new TestCommand();

            cm.RegisterCommand(TestCommands.Close, cmd);

            bool raised = false;

            proxy.CanExecuteChanged += delegate {
                raised = true;
            };

            cmd.RaiseCanExecuteChanged();

            Assert.IsTrue(raised);
        }
示例#5
0
        public void TestCommandManager()
        {
            ApplicationCommandManager cm = new ApplicationCommandManager();

            ICommand newCommand = cm[TestCommands.New];

            Assert.AreEqual(newCommand, cm[TestCommands.New]);

            ICommand saveCommand = cm[TestCommands.Save];

            Assert.AreNotEqual(newCommand, saveCommand);

            var actualNewCommand = new Mock <ICommand>();

            actualNewCommand.Setup(x => x.CanExecute(It.IsAny <Object>())).Returns(true);

            Assert.IsFalse(newCommand.CanExecute(null));
            AssertHelper.Throws <InvalidOperationException>(() => {
                newCommand.Execute(null);
            });

            cm.RegisterCommand(TestCommands.New, actualNewCommand.Object);

            Assert.IsTrue(newCommand.CanExecute(null));
            actualNewCommand.Verify(x => x.CanExecute(null), Times.Once());

            newCommand.Execute(null);
            actualNewCommand.Verify(x => x.Execute(null), Times.Once());

            cm.UnregisterCommand(TestCommands.New);

            Assert.IsFalse(newCommand.CanExecute(null));
            AssertHelper.Throws <InvalidOperationException>(() => {
                newCommand.Execute(null);
            });

            // Verify that these method were not called
            actualNewCommand.Verify(x => x.CanExecute(null), Times.Once());
            actualNewCommand.Verify(x => x.Execute(null), Times.Once());
        }