public void WhenOnEventRaised()
        {
            var commandExecuterMock         = new Mock <ICommandExecutor>();
            var command                     = new Mock <ICommand>().Object;
            var commandParameter            = new object();
            var eventArgs                   = new EventArgs();
            var eventArgsConverter          = new Mock <IValueConverter>().Object;
            var eventArgsConverterParameter = new object();
            var eventArgsPropertyPath       = "";

            var behavior =
                new EventToCommandBehaviorMock
            {
                CommandExecutor             = commandExecuterMock.Object,
                Command                     = command,
                CommandParameter            = commandParameter,
                EventArgsConverter          = eventArgsConverter,
                EventArgsConverterParameter = eventArgsConverterParameter,
                EventArgsPropertyPath       = eventArgsPropertyPath
            };

            behavior.Rise(this, eventArgs);

            commandExecuterMock.Verify(
                executer => executer.Execute(command, commandParameter, eventArgs, eventArgsConverter, eventArgsConverterParameter, eventArgsPropertyPath),
                Times.Once);
        }
        public void Command_CanExecute()
        {
            var behavior = new EventToCommandBehaviorMock
            {
                EventName = "ItemTapped",
                Command   = new DelegateCommand(() => Assert.True(false), () => false)
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, null);
        }
        public void Command_CanExecuteWithParameterShouldNotExeute()
        {
            var shouldExeute = bool.FalseString;
            var behavior     = new EventToCommandBehaviorMock
            {
                EventName        = "ItemTapped",
                CommandParameter = shouldExeute,
                Command          = new DelegateCommand <string>(o => Assert.True(false), o => o.Equals(bool.TrueString))
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, null);
        }
        public void Command_Execute()
        {
            var executedCommand = false;
            var behavior        = new EventToCommandBehaviorMock
            {
                EventName = "ItemTapped",
                Command   = new DelegateCommand(() =>
                {
                    executedCommand = true;
                    Assert.True(true);
                })
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, null);
            Assert.True(executedCommand);
        }
        public void Command_Converter()
        {
            const string item     = "ItemProperty";
            var          behavior = new EventToCommandBehaviorMock
            {
                EventName          = "ItemTapped",
                EventArgsConverter = new ItemTappedEventArgsConverter(false),
                Command            = new DelegateCommand <string>(o =>
                {
                    Assert.NotNull(o);
                    Assert.Equal(item, o);
                })
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, new ItemTappedEventArgs(listView, item));
        }
        public void Command_EventArgsParameterPath_Nested_When_ChildIsNull()
        {
            var executedCommand = false;
            var behavior        = new EventToCommandBehaviorMock
            {
                EventName = "ItemTapped",
                EventArgsParameterPath = "Item.AProperty",
                Command = new DelegateCommand <object>(o =>
                {
                    executedCommand = true;
                    Assert.Null(o);
                })
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, new ItemTappedEventArgs(listView, null));
            Assert.True(executedCommand);
        }
        public void Command_EventArgsParameterPath()
        {
            const string item            = "ItemProperty";
            var          executedCommand = false;
            var          behavior        = new EventToCommandBehaviorMock
            {
                EventName = "ItemTapped",
                EventArgsParameterPath = "Item",
                Command = new DelegateCommand <string>(o =>
                {
                    executedCommand = true;
                    Assert.NotNull(o);
                    Assert.Equal(item, o);
                })
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, new ItemTappedEventArgs(listView, item));
            Assert.True(executedCommand);
        }
        public void Command_OrderOfExecution()
        {
            const string commandParameter = "ItemProperty";
            var          converter        = new ItemTappedEventArgsConverter(false);
            var          behavior         = new EventToCommandBehaviorMock
            {
                EventName          = "ItemTapped",
                EventArgsConverter = converter,
                CommandParameter   = commandParameter,
                Command            = new DelegateCommand <string>(o =>
                {
                    Assert.NotNull(o);
                    Assert.Equal(commandParameter, o);
                    Assert.False(converter.HasConverted);
                })
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, new ItemTappedEventArgs(listView, commandParameter));
        }
        public void Command_EventArgsParameterPath_Nested()
        {
            dynamic item = new
            {
                AProperty = "Value"
            };
            var behavior = new EventToCommandBehaviorMock
            {
                EventName = "ItemTapped",
                EventArgsParameterPath = "Item.AProperty",
                Command = new DelegateCommand <object>(o =>
                {
                    Assert.NotNull(o);
                    Assert.Equal("Value", o);
                })
            };
            var listView = new ListView();

            listView.Behaviors.Add(behavior);
            behavior.RaiseEvent(listView, new ItemTappedEventArgs(listView, item));
        }