Esempio n. 1
0
        public void TestComplexSink()
        {
            var first       = new Source();
            var second      = new Source();
            var sink        = new ComplexSink(first, second);
            var counter     = 0;
            var expectation = 0;

            Assert.AreEqual("zoo", sink.Complex);
            ObservableUtility.FromProperty(() => sink.Complex).Skip(1).Subscribe(value => { counter++; });
            Assert.AreEqual(expectation, counter);
            second.Woop = true;
            Assert.AreEqual(++expectation, counter);
            Assert.AreEqual("bar", sink.Complex);
            first.Woop = true;
            Assert.AreEqual("foo", sink.Complex);
            Assert.AreEqual(++expectation, counter);
            second.Woop = false;
            Assert.AreEqual("foo", sink.Complex);
            Assert.AreEqual(expectation, counter);
            second.Woop = true;
            Assert.AreEqual("foo", sink.Complex);
            Assert.AreEqual(expectation, counter);
            first.Woop = false;
            Assert.AreEqual("bar", sink.Complex);
            Assert.AreEqual(++expectation, counter);
            second.Woop = false;
            Assert.AreEqual("zoo", sink.Complex);
            Assert.AreEqual(++expectation, counter);

            sink.Source2 = new Source();
            Assert.AreEqual("zoo", sink.Complex);
            Assert.AreEqual(expectation += NotificationWhenDependentChangesToSameValue, counter);
        }
Esempio n. 2
0
        public void Reactive()
        {
            var source1 = new Source();
            var source2 = new Source();
            var user    = new SimpleSink(source1);
            var counter = 0;

            ObservableUtility.FromProperty(() => user.Boop).Skip(1).Subscribe(value => counter++);

            Assert.AreEqual(0, counter);
            Assert.AreEqual(false, user.Boop);

            source1.Woop = true;
            Assert.AreEqual(1, counter);
            Assert.AreEqual(true, user.Boop);

            source2.Woop = true;
            Assert.AreEqual(1, counter);
            Assert.AreEqual(true, user.Boop);

            source1.Woop = false;
            Assert.AreEqual(2, counter);
            Assert.AreEqual(false, user.Boop);

            user.Source = source2;
            Assert.AreEqual(3, counter);
            Assert.AreEqual(true, user.Boop);

            source2.Woop = false;
            Assert.AreEqual(4, counter);
            Assert.AreEqual(false, user.Boop);
        }
Esempio n. 3
0
        public void TestEventWithoutPropertyAccess()
        {
            var source = new Source();
            var sink   = new SimpleSink(source);

            var counter     = 0;
            var expectation = 0;

            ObservableUtility.FromProperty(() => sink.Boop, false).Subscribe(value => { counter++; });
            Assert.AreEqual(expectation, counter);
            source.FlipWoop();
            Assert.AreEqual(expectation += WorksWithoutInitialPropertyAccess, counter);
        }
Esempio n. 4
0
        public void TestSinkChain()
        {
            var sink         = new SinkChain();
            var outerCounter = 0;

            Assert.AreEqual(false, sink.OuterSink);
            Assert.AreEqual(true, sink.InnerSink);
            ObservableUtility.FromProperty(() => sink.OuterSink).Skip(1).Subscribe(value => outerCounter++);

            sink.Source = true;
            Assert.AreEqual(true, sink.OuterSink);
            Assert.AreEqual(false, sink.InnerSink);
            Assert.AreEqual(1, outerCounter);
        }
        public void TestDependentList()
        {
            var obj = new DependentList();
            var dependentCounter     = 0;
            var sourcesCounter       = 0;
            var dependentExpectation = 0;
            var sourcesExpectation   = 0;

            ObservableUtility.FromProperty(() => obj.DependentCount).Subscribe(_ => dependentCounter++);
            ObservableUtility.FromProperty(() => obj.Sources).Subscribe(_ => sourcesCounter++);

            Assert.AreEqual(++sourcesExpectation, sourcesCounter);
            Assert.AreEqual(++dependentExpectation, dependentCounter);
            Assert.AreEqual(0, obj.DependentCount);
            Assert.AreEqual(0, obj.SourcesCount);
            obj.Sources = new ObservableCollection <Source>();
            Assert.AreEqual(++sourcesExpectation, sourcesCounter);
            Assert.AreEqual(++dependentExpectation, dependentCounter);

            Assert.AreEqual(0, obj.DependentCount);
            Assert.AreEqual(0, obj.SourcesCount);
            obj.Sources.Add(new Source());
            Assert.AreEqual(1, obj.DependentCount);
            Assert.AreEqual(1, obj.SourcesCount);
            Assert.AreEqual(++sourcesExpectation, sourcesCounter);
            Assert.AreEqual(++dependentExpectation, dependentCounter);

            obj.Dependent.Add(new Source());
            Assert.AreEqual(++dependentExpectation, dependentCounter);

            Assert.AreEqual(2, obj.DependentCount);
            Assert.AreEqual(2, obj.SourcesCount);
            var newList = new ObservableCollection <Source>();

            obj.Sources = newList;
            Assert.AreEqual(0, obj.DependentCount);
            Assert.AreEqual(0, obj.SourcesCount);
            Assert.AreEqual(++dependentExpectation, dependentCounter);

            obj.Sources.Add(new Source());
            Assert.AreEqual(++dependentExpectation, dependentCounter);

            Assert.AreEqual(1, obj.DependentCount);
            Assert.AreEqual(1, obj.SourcesCount);
            obj.Sources.RemoveAt(0);
            Assert.AreEqual(++dependentExpectation, dependentCounter);
        }
Esempio n. 6
0
        public void TestChangingDependenciesForSinkTrap()
        {
            var first = new Source();

            first.Woop = true;
            var second      = new Source();
            var sink        = new ComplexSink(first, second);
            var counter     = 0;
            var expectation = 0;

            Assert.AreEqual("foo", sink.Complex);
            first.Woop = false;
            ObservableUtility.FromProperty(() => sink.Complex, false).Subscribe(value => { counter++; });
            Assert.AreEqual(expectation, counter);
            second.Woop = true;
            Assert.AreEqual(expectation += RecordsChangingDependenciesWithoutAccess, counter);
        }
Esempio n. 7
0
        public void TestTree()
        {
            var bottom1  = new Tree();
            var bottom2  = new Tree();
            var bottoms1 = new List <Tree> {
                bottom1, bottom2
            };
            var mid1 = new Tree(bottoms1);
            var mid2 = new Tree();
            var mids = new List <Tree> {
                mid1, mid2
            };
            var top = new Tree(mids);

            var counter = 0;

            ObservableUtility.FromProperty(() => top.HasSuccessfulBlood).Subscribe(_ => counter++);
            var expectation = 1;

            mid2.Successful = true;
            Assert.AreEqual(++expectation, counter);
            mid1.Successful = true;
            Assert.AreEqual(++expectation, counter);
            mid2.Successful = false;
            Assert.AreEqual(expectation, counter);

            Assert.AreEqual(true, top.HasSuccessfulBlood);
            mid1.Successful = false;
            Assert.AreEqual(++expectation, counter);

            Assert.AreEqual(false, top.HasSuccessfulBlood);
            bottom1.Successful = true;
            Assert.AreEqual(++expectation, counter);

            Assert.AreEqual(true, top.HasSuccessfulBlood);
            bottom2.Successful = true;
            Assert.AreEqual(expectation, counter);
        }