public void ExecutionTestMasterOnly() { StringBuilder strBld = new StringBuilder(1000); HierarchyCommand hierCmd = new HierarchyCommand( new Action <object>(p1 => strBld.Append("Master")), new Predicate <object>(p2 => true), HierarchyExecuteStrategy.MasterCommandOnly, HierarchyCanExecuteStrategy.DependsOnAllChilds); var child1 = new RelayCommand(new Action <object>(p1 => strBld.Append("1")), new Predicate <object>(p2 => true)); var child2 = new RelayCommand(new Action <object>(p1 => strBld.Append("2")), new Predicate <object>(p2 => true)); var child3 = new RelayCommand(new Action <object>(p1 => strBld.Append("3")), new Predicate <object>(p2 => true)); hierCmd.AddChildsCommand(new List <ICommand> { child1, child2, child3 }); Assert.AreEqual(3, hierCmd.ChildCommands.Count()); hierCmd.Execute(null); Assert.IsFalse(strBld.ToString().Contains("1")); Assert.IsFalse(strBld.ToString().Contains("2")); Assert.IsFalse(strBld.ToString().Contains("3")); Assert.IsTrue(strBld.ToString().Contains("Master")); }
public void ChildCommandsTest() { StringBuilder strBld = new StringBuilder(1000); HierarchyCommand hierCmd = new HierarchyCommand( new Action <object>(p1 => strBld.Append("Master")), new Predicate <object>(p2 => true), HierarchyExecuteStrategy.AllChildsOnly, HierarchyCanExecuteStrategy.DependsOnAllChilds); Assert.IsNotNull(hierCmd.ChildCommands); hierCmd.ChildCommands = null; Assert.IsNotNull(hierCmd.ChildCommands); Assert.IsFalse(hierCmd.ChildCommands.Any()); hierCmd.Execute(null); Assert.IsTrue(string.IsNullOrEmpty(strBld.ToString())); }