コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public void SimpleAddListenWithPropertyChangedEventManagerTest()
 {
     var fakeInpc = new FakeInpc();
     var oc = new ObservableCollection<FakeInpc>();
     var events = new List<ListenerAndChild<FakeInpc>>();
     var listener = OcNpcListener.Create(oc);
     PropertyChangedEventManager.AddHandler(listener, (sender, args) => events.Add((ListenerAndChild<FakeInpc>)sender), "");
     Assert.IsFalse(fakeInpc.HasHandler);
     oc.Add(fakeInpc);
     Assert.IsTrue(fakeInpc.HasHandler);
     fakeInpc.Raise1();
     Assert.AreEqual(fakeInpc, events.Single().Child);
 }
コード例 #7
0
 public void SimpleAddTest()
 {
     var fakeInpc = new FakeInpc();
     var oc = new ObservableCollection<FakeInpc>();
     var events = new List<FakeInpc>();
     var listener = OcNpcListener.Create(oc);
     listener.PropertyChanged += (sender, args) => events.Add((FakeInpc)((ChildPropertyChangedEventArgs)args).Child);
     Assert.IsFalse(fakeInpc.HasHandler);
     oc.Add(fakeInpc);
     Assert.IsTrue(fakeInpc.HasHandler);
     fakeInpc.Raise1();
     Assert.AreEqual(fakeInpc, events.Single());
 }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
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));
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }