public void NegateCondition(bool?value, bool?expected) { var fake = new FakeInpc { Prop1 = value }; var condition = new Condition(fake.ToObservable(x => x.Prop1), () => fake.Prop1); var negatedCondition = condition.Negate(); Assert.AreEqual(expected, negatedCondition.IsSatisfied); }
public void Name() { var fake = new FakeInpc { Prop1 = false }; var condition = new Condition(fake.ToObservable(x => x.Prop1), () => fake.Prop1); var negatedCondition = condition.Negate(); Assert.AreEqual("Not_" + condition.Name, negatedCondition.Name); }
public void History() { var fake = new FakeInpc { Prop1 = false }; var observable = fake.ToObservable(x => x.Prop1, false); var condition = new Condition(observable, () => fake.Prop1); fake.Prop1 = true; CollectionAssert.AreEqual(new[] { false, true }, condition.History.Select(x => x.State)); }
public void NegateTwiceReturnsOriginal() { var fake = new FakeInpc { Prop1 = false }; var condition = new Condition(fake.ToObservable(x => x.Prop1), () => fake.Prop1); var negatedCondition = condition.Negate(); var negatedTwice = negatedCondition.Negate(); Assert.AreSame(condition, negatedTwice); }
public void ConditionTest() { var fake = new FakeInpc { Prop1 = false }; var observable = fake.ToObservable(x => x.Prop1); var condition = new Condition(observable, () => fake.Prop1); Assert.AreEqual(false, condition.IsSatisfied); fake.Prop1 = true; Assert.AreEqual(true, condition.IsSatisfied); }
public void MemoryLeakTest() { var dummy = new FakeInpc(); var wr = new WeakReference(dummy); Assert.IsTrue(wr.IsAlive); var condition = new Condition(dummy.ToObservable(x => x.Prop1, false), () => dummy.Prop1); dummy = null; condition.Dispose(); GC.Collect(); Assert.IsFalse(wr.IsAlive); }
public void Notifies() { var fake = new FakeInpc { Prop1 = false }; var observable = fake.ToObservable(x => x.Prop1, false); var condition = new Condition(observable, () => fake.Prop1); var argses = new List <PropertyChangedEventArgs>(); condition.PropertyChanged += (sender, args) => argses.Add(args); fake.Prop1 = true; Assert.AreEqual(1, argses.Count); }
public void NotifiesOnConditionChanged() { var fake = new FakeInpc { Prop1 = false }; var observable = fake.ToObservable(x => x.Prop1); var command = new ObservingRelayCommand(_ => { }, _ => false, observable, false); int count = 0; command.CanExecuteChanged += (sender, args) => count++; fake.Prop1 = true; Assert.AreEqual(1, count); }
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 Notifies() { var argses = new List <string>(); var fake1 = new FakeInpc { Prop1 = false }; var fake2 = new FakeInpc { Prop1 = false }; var fake3 = new FakeInpc { Prop1 = false }; var condition1 = new Condition(fake1.ToObservable(x => x.Prop1), () => fake1.Prop1); var condition2 = new Condition(fake2.ToObservable(x => x.Prop1), () => fake2.Prop1); var condition3 = new Condition(fake3.ToObservable(x => x.Prop1), () => fake3.Prop1); var collection = new AndCondition(condition1, condition2, condition3); collection.PropertyChanged += (sender, args) => argses.Add(args.PropertyName); Assert.AreEqual(false, collection.IsSatisfied); fake1.Prop1 = true; Assert.AreEqual(false, collection.IsSatisfied); Assert.AreEqual(0, argses.Count); fake2.Prop1 = true; Assert.AreEqual(false, collection.IsSatisfied); Assert.AreEqual(0, argses.Count); fake3.Prop1 = true; Assert.AreEqual(true, collection.IsSatisfied); Assert.AreEqual(1, argses.Count); fake1.Prop1 = false; Assert.AreEqual(false, collection.IsSatisfied); Assert.AreEqual(2, argses.Count); fake2.Prop1 = false; Assert.AreEqual(false, collection.IsSatisfied); Assert.AreEqual(2, argses.Count); fake3.Prop1 = false; Assert.AreEqual(false, collection.IsSatisfied); Assert.AreEqual(2, argses.Count); }
public void NegateOrCondition(bool?first, bool?other, bool?third, bool?expected) { var fake1 = new FakeInpc { Prop1 = first }; var condition1 = new Condition(fake1.ToObservable(x => x.Prop1), () => fake1.Prop1); var fake2 = new FakeInpc { Prop1 = other }; var condition2 = new Condition(fake2.ToObservable(x => x.Prop1), () => fake2.Prop1); var fake3 = new FakeInpc { Prop1 = third }; var condition3 = new Condition(fake3.ToObservable(x => x.Prop1), () => fake3.Prop1); var orCondition = new OrCondition(condition1, condition2, condition3); var negated = orCondition.Negate(); Assert.AreEqual(expected, negated.IsSatisfied); }
public void Notifies() { var argses = new List <PropertyChangedEventArgs>(); var negArgses = new List <PropertyChangedEventArgs>(); var fake = new FakeInpc { Prop1 = false }; var condition = new Condition(fake.ToObservable(x => x.Prop1), () => fake.Prop1 == true); var negatedCondition = condition.Negate(); condition.PropertyChanged += (_, e) => argses.Add(e); negatedCondition.PropertyChanged += (_, e) => negArgses.Add(e); Assert.AreEqual(0, argses.Count); Assert.AreEqual(0, negArgses.Count); fake.Prop1 = true; Assert.AreEqual(1, argses.Count); Assert.AreEqual(1, negArgses.Count); fake.Prop1 = null; Assert.AreEqual(2, argses.Count); Assert.AreEqual(2, negArgses.Count); }