public void CanExecute(bool expected)
        {
            var fake = new Fake {
                IsTrue = false
            };

            using var condition = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrue), () => fake.IsTrue);
            using var command   = new ConditionRelayCommand(() => { }, condition);
            fake.IsTrue         = expected;
            Assert.AreEqual(expected, command.CanExecute());
        }
示例#2
0
        public void Execute()
        {
            var i    = 0;
            var fake = new Fake {
                IsTrueOrNull = false
            };

            using var condition = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrueOrNull), () => fake.IsTrueOrNull);
            using var command   = new ConditionRelayCommand <int>(x => i = x, condition);
            command.Execute(1);
            Assert.AreEqual(1, i);
        }
        public void Execute()
        {
            var fake = new Fake {
                IsTrue = true
            };

            using var condition = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrue), () => fake.IsTrue);
            var i = 0;

            using var command = new ConditionRelayCommand(() => i++, condition);
            command.Execute();
            Assert.AreEqual(1, i);
        }
        public void CanExecute(bool expected)
        {
            var fake = new Fake {
                IsTrueOrNull = false
            };

            using (var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull))
            {
                using (var command = new ConditionRelayCommand <int>(x => { }, condition))
                {
                    fake.IsTrueOrNull = expected;
                    Assert.AreEqual(expected, command.CanExecute(0));
                }
            }
        }
示例#5
0
        public async Task NotifiesOnConditionChanged()
        {
            var count = 0;
            var fake  = new Fake {
                IsTrueOrNull = false
            };

            using var condition        = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrueOrNull), () => fake.IsTrueOrNull);
            using var command          = new ConditionRelayCommand <int>(x => { }, condition);
            command.CanExecuteChanged += (sender, args) => count++;
            fake.IsTrueOrNull          = true;
            await Application.Current.Dispatcher.SimulateYield();

            Assert.AreEqual(1, count);
        }
示例#6
0
        public async Task NotifiesOnConditionChanged()
        {
            var count = 0;
            var fake  = new Fake {
                IsTrue = false
            };

            using (var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrue), () => fake.IsTrue))
            {
                using (var command = new ConditionRelayCommand(() => { }, condition))
                {
                    command.CanExecuteChanged += (sender, args) => count++;
                    Assert.AreEqual(0, count);
                    Assert.IsFalse(command.CanExecute());

                    fake.IsTrue = true;
                    await Application.Current.Dispatcher.SimulateYield();

                    Assert.AreEqual(1, count);
                    Assert.IsTrue(command.CanExecute());
                }
            }
        }