public void ExecuteCommand_WithNestedPropertyPath() { var listView = new ListView(); var command = new Mock <ICommand>(); command.Setup(x => x.CanExecute(It.IsAny <object>())).Returns(true); var behavior = new SelectedItemBehavior { Command = command.Object, PropertyPath = "NestedSelectedItem.Value" }; listView.Behaviors.Add(behavior); var selectedItem = new SelectedItem { NestedSelectedItem = new SelectedItem { Value = "Hello" } }; listView.SelectedItem = selectedItem; command.Verify(x => x.CanExecute("Hello"), Times.Once); command.Verify(x => x.Execute("Hello"), Times.Once); Assert.Null(listView.SelectedItem); }
public void OnDetachingFrom() { var listView = new ListView(); var command = new Mock <ICommand>(); command.Setup(x => x.CanExecute(It.IsAny <object>())).Returns(true); var behavior = new SelectedItemBehavior { Command = command.Object }; listView.Behaviors.Add(behavior); listView.Behaviors.Remove(behavior); listView.SelectedItem = "One"; command.Verify(x => x.CanExecute("One"), Times.Never); command.Verify(x => x.Execute("One"), Times.Never); Assert.NotNull(listView.SelectedItem); }
public void NotExecuteCommand() { var listView = new ListView(); var command = new Mock <ICommand>(); command.Setup(x => x.CanExecute(It.IsAny <object>())).Returns(false); var behavior = new SelectedItemBehavior { Command = command.Object, ClearSelected = false }; listView.Behaviors.Add(behavior); listView.SelectedItem = "One"; command.Verify(x => x.CanExecute("One"), Times.Once); command.Verify(x => x.Execute("One"), Times.Never); Assert.NotNull(listView.SelectedItem); }