Beispiel #1
0
        public void AutomaticModeDependentWithSetter()
        {
            var efficientMode = new AutomaticMode();
            var counter       = 0;

            ObservableUtility.FromProperty(() => efficientMode.DependentWithSetter).Subscribe(_ => counter++);

            Assert.AreEqual(1, counter);
            efficientMode.Source = !efficientMode.Source;
            Assert.AreEqual(2, counter);
        }
        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);
        }