Ejemplo n.º 1
0
        public void ValueDisposal()
        {
            var people = new ObservableCollection <SyncDisposableTestPerson>
            {
                SyncDisposableTestPerson.CreateJohn()
            };
            SyncDisposableTestPerson newPerson;

            using (var expr = ActiveExpression.Create(p => - p[0], people))
            {
                newPerson = expr.Value;
                Assert.IsFalse(newPerson.IsDisposed);
                people[0] = SyncDisposableTestPerson.CreateJohn();
                Assert.IsTrue(newPerson.IsDisposed);
                newPerson = expr.Value;
                Assert.IsFalse(newPerson.IsDisposed);
            }
            Assert.IsTrue(newPerson.IsDisposed);
        }
Ejemplo n.º 2
0
        public void ValueDisposal()
        {
            var john   = SyncDisposableTestPerson.CreateJohn();
            var emily  = SyncDisposableTestPerson.CreateEmily();
            var people = new ObservableCollection <SyncDisposableTestPerson> {
                john
            };
            var options = new ActiveExpressionOptions();

            options.AddExpressionValueDisposal(() => new ObservableCollection <SyncDisposableTestPerson>()[0]);
            using (var ae = ActiveExpression.Create(p => p[0], people, options))
            {
                Assert.AreSame(john, ae.Value);
                Assert.IsFalse(john.IsDisposed);
                people[0] = emily;
                Assert.AreSame(emily, ae.Value);
                Assert.IsTrue(john.IsDisposed);
            }
            Assert.IsTrue(emily.IsDisposed);
        }
Ejemplo n.º 3
0
        public void ValueDisposal()
        {
            var john    = SyncDisposableTestPerson.CreateJohn();
            var options = new ActiveExpressionOptions();

            options.AddConstructedTypeDisposal(typeof(SyncDisposableTestPerson));
            SyncDisposableTestPerson first, second;

            using (var expr = ActiveExpression.Create(() => new SyncDisposableTestPerson(john.Name.Length.ToString()), options))
            {
                Assert.IsNull(expr.Fault);
                first = expr.Value;
                Assert.IsFalse(first.IsDisposed);
                john.Name = string.Empty;
                Assert.IsNull(expr.Fault);
                second = expr.Value;
                Assert.IsFalse(second.IsDisposed);
                Assert.IsTrue(first.IsDisposed);
            }
            Assert.IsTrue(second.IsDisposed);
        }
Ejemplo n.º 4
0
        public void ValueDisposal()
        {
            var john    = SyncDisposableTestPerson.CreateJohn();
            var emily   = SyncDisposableTestPerson.CreateEmily();
            var options = new ActiveExpressionOptions();

            options.AddExpressionValueDisposal(() => CombineSyncDisposablePeople(null, null));
            SyncDisposableTestPerson first, second;

            using (var expr = ActiveExpression.Create(() => CombineSyncDisposablePeople(john.Name.Length > 3 ? john : emily, emily), options))
            {
                Assert.IsNull(expr.Fault);
                first = expr.Value;
                Assert.IsFalse(first.IsDisposed);
                john.Name = string.Empty;
                Assert.IsNull(expr.Fault);
                second = expr.Value;
                Assert.IsFalse(second.IsDisposed);
                Assert.IsTrue(first.IsDisposed);
            }
            Assert.IsTrue(second.IsDisposed);
        }
Ejemplo n.º 5
0
 SyncDisposableTestPerson CombineSyncDisposablePeople(SyncDisposableTestPerson a, SyncDisposableTestPerson b) => new SyncDisposableTestPerson
 {
     Name = $"{a.Name} {b.Name}"
 };