Beispiel #1
0
        public void CanExecute()
        {
            var fake = new FakeInpc {
                Prop1 = false
            };
            var observable = fake.ToObservable(x => x.Prop1);
            var condition  = new Condition(observable, () => fake.Prop1);
            var command    = new ConditionRelayCommand(_ => { }, condition, false);

            Assert.IsFalse(command.CanExecute(null));

            fake.Prop1 = true;
            Assert.IsTrue(command.CanExecute(null));
        }
        public void NotifiesOnConditionChanged()
        {
            int count = 0;
            var fake  = new Fake {
                IsTrue = false
            };
            var observable = fake.ObservePropertyChanged(x => x.IsTrue);
            var condition  = new Condition(observable, () => fake.IsTrue);
            var command    = new ConditionRelayCommand(() => { }, condition);

            command.CanExecuteChanged += (sender, args) => count++;
            Assert.AreEqual(0, count);
            Assert.IsFalse(command.CanExecute());

            fake.IsTrue = true;
            Assert.AreEqual(1, count);
            Assert.IsTrue(command.CanExecute());
        }
        public async Task NotifiesOnConditionChanged()
        {
            var count = 0;
            var fake  = new Fake {
                IsTrue = false
            };

            using var condition        = new Condition(fake.ObservePropertyChangedSlim(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());
        }
        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());
        }
        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));
                }
            }
        }
 public void CanExecute(bool expected)
 {
     _fake.IsTrueOrNull = expected;
     Assert.AreEqual(expected, _command.CanExecute());
 }