Esempio n. 1
0
        public void IndirectComputedObjectCanBeGarbageCollected()
        {
            GC.Collect();
            SourceData       observable       = new SourceData();
            DirectComputed   intermediate     = new DirectComputed(observable);
            IndirectComputed indirectComputed = new IndirectComputed(intermediate);

            observable.SourceProperty = 42;
            Assert.AreEqual(42, indirectComputed.ComputedProperty);
            WeakReference weakIndirectComputed = new WeakReference(indirectComputed);

            GC.Collect();
            Assert.IsTrue(weakIndirectComputed.IsAlive, "Since we hold a strong reference to the dependent, the object should still be alive.");
            // This assertion here to make sure the dependent is not optimized away.
            Assert.AreEqual(42, indirectComputed.ComputedProperty);

            indirectComputed = null;
            GC.Collect();
            Assert.IsFalse(weakIndirectComputed.IsAlive, "Since we released the strong reference to the dependent, the object should not be alive.");

            // Make sure we can still modify the observable, and that the intermediate still depends upon it.
            observable.SourceProperty = 32;
            Assert.AreEqual(32, observable.SourceProperty);
            Assert.AreEqual(32, intermediate.ComputedProperty);
        }
Esempio n. 2
0
        public void DirectComputedObjectCanBeGarbageCollected()
        {
            GC.Collect();
            SourceData observable = new SourceData();
            DirectComputed computed = new DirectComputed(observable);
            observable.SourceProperty = 42;
            Assert.AreEqual(42, computed.ComputedProperty);
            WeakReference weakComputed = new WeakReference(computed);

            GC.Collect();
            Assert.IsTrue(weakComputed.IsAlive, "Since we hold a strong reference to the dependent, the object should still be alive.");
            // This assertion here to make sure the dependent is not optimized away.
            Assert.AreEqual(42, computed.ComputedProperty);

            computed = null;
            GC.Collect();
            Assert.IsFalse(weakComputed.IsAlive, "Since we released the strong reference to the dependent, the object should not be alive.");

            // Make sure we can still modify the observable.
            observable.SourceProperty = 32;
            Assert.AreEqual(32, observable.SourceProperty);
        }
 public void Initialize()
 {
     _source = new SourceData();
     _intermediateComputed = new DirectComputed(_source);
     _computed = new IndirectComputed(_intermediateComputed);
 }
Esempio n. 4
0
 public IndirectComputed(DirectComputed indermediateComputed)
 {
     _indermediateComputed = indermediateComputed;
     _property = new Computed<int>(() => _indermediateComputed.ComputedProperty);
 }
Esempio n. 5
0
 public void Initialize()
 {
     _source = new SourceData();
     _intermediateComputed = new DirectComputed(_source);
     _computed             = new IndirectComputed(_intermediateComputed);
 }
 public void Initialize()
 {
     _source = new SourceData();
     _computed = new DirectComputed(_source);
 }
 public void Initialize()
 {
     _source   = new SourceData();
     _computed = new DirectComputed(_source);
 }
 public IndirectComputed(DirectComputed indermediateComputed)
 {
     _indermediateComputed = indermediateComputed;
     _property             = new Computed <int>(() => _indermediateComputed.ComputedProperty);
 }