예제 #1
0
        public void ParameterOfTypeInt()
        {
            var vm       = new ViewModelCoffe();
            var behavior = new EventToCommandBehavior <int>
            {
                EventName        = nameof(ListView.ItemTapped),
                Command          = vm.SelectedCommand,
                CommandParameter = 2
            };

            var nullArgs = new object?[] { null, null };

            TriggerEventToCommandBehavior(behavior, nullArgs);
        }
예제 #2
0
        public void NoExceptionWhenTheSelectedItemIsNull()
        {
            var vm       = new ViewModelCoffe();
            var behavior = new EventToCommandBehavior <Coffee>
            {
                EventName          = nameof(ListView.ItemTapped),
                EventArgsConverter = new ItemSelectedEventArgsConverter(),
                Command            = vm.SelectedCommand
            };

            Assert.Null(vm.CoffeeName);
            var coffeNull   = default(Coffee);
            var notNullArgs = new object?[] { null, new SelectedItemChangedEventArgs(coffeNull, -1) };

            TriggerEventToCommandBehavior(behavior, notNullArgs);

            Assert.Null(vm.CoffeeName);
        }
예제 #3
0
        public void NoExceptionWhenTheEventArgsAreNotNull_InheritedType()
        {
            var vm       = new ViewModelCoffe();
            var behavior = new EventToCommandBehavior <Coffee>
            {
                EventName          = nameof(ListView.ItemTapped),
                EventArgsConverter = new ItemSelectedEventArgsConverter(),
                Command            = vm.SelectedCommand
            };

            Assert.Null(vm.CoffeeName);
            var coffe = new Starbucks {
                Id = 1, Name = "Latte"
            };
            var eventArgs = new SelectedItemChangedEventArgs(coffe, 1);

            var notNullArgs = new object?[] { null, eventArgs };

            TriggerEventToCommandBehavior(behavior, notNullArgs);

            Assert.AreEqual(coffe.Name, vm.CoffeeName);
        }