public void InvokeCommandActionTest() { var textBox = new TextBox(); var eventTrigger = new EventTrigger(nameof(textBox.TextChanged)); var action = new InvokeCommandAction(); bool invoked = false; action.Command = new RelayCommand <bool>(b => invoked = b); action.CommandParameter = true; eventTrigger.Actions.Add(action); eventTrigger.Attach(textBox); textBox.RaiseEvent(new TextChangedEventArgs(TextBoxBase.TextChangedEvent, UndoAction.None)); Assert.IsTrue(invoked); // for code coverage action = new InvokeCommandAction("test1") { Command = null, CommandName = "test" }; action.CommandName = "test"; eventTrigger.Actions.Add(action); Assert.AreEqual(action.CommandName, "test"); textBox.RaiseEvent(new TextChangedEventArgs(TextBoxBase.TextChangedEvent, UndoAction.None)); action.IsEnabled = false; textBox.RaiseEvent(new TextChangedEventArgs(TextBoxBase.TextChangedEvent, UndoAction.None)); action.IsEnabled = true; action.Detach(); textBox.RaiseEvent(new TextChangedEventArgs(TextBoxBase.TextChangedEvent, UndoAction.None)); }
public void WhenDetatched_ThenSetsCommandAndCommandParameterToNull() { var someControl = new TextBox(); var command = new MockCommand(); var parameter = new object(); var commandAction = new InvokeCommandAction(); commandAction.Attach(someControl); commandAction.Command = command; commandAction.CommandParameter = parameter; Assert.NotNull(commandAction.Command); Assert.NotNull(commandAction.CommandParameter); commandAction.Detach(); Assert.Null(commandAction.Command); Assert.Null(commandAction.CommandParameter); }
public void WhenDetatched_ThenSetsCommandAndCommandParameterToNull() { var someControl = new TextBox(); var command = new MockCommand(); var parameter = new object(); var commandAction = new InvokeCommandAction(); commandAction.Attach(someControl); commandAction.Command = command; commandAction.CommandParameter = parameter; Assert.IsNotNull(commandAction.Command); Assert.IsNotNull(commandAction.CommandParameter); commandAction.Detach(); Assert.IsNull(commandAction.Command); Assert.IsNull(commandAction.CommandParameter); }