public void UnregisterCommand_CommandRegisteredIsFired() { bool regsiteredCommandsChangedRaised = false; ApplicationCommandManager cm = new ApplicationCommandManager(); cm.RegisteredCommandsChanged += (s, e) => regsiteredCommandsChangedRaised = true; cm.UnregisterCommand(TestCommands.Close); Assert.IsTrue(regsiteredCommandsChangedRaised); }
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()); }