Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }