コード例 #1
0
        public void ValueAsyncDisposal()
        {
            var people = new ObservableCollection <AsyncDisposableTestPerson>
            {
                AsyncDisposableTestPerson.CreateJohn(),
            };
            AsyncDisposableTestPerson newPerson;

            using (var expr = ActiveExpression.Create(p => - p[0], people))
            {
                newPerson = expr.Value;
                Assert.IsFalse(newPerson.IsDisposed);
                people[0] = AsyncDisposableTestPerson.CreateJohn();
                Assert.IsTrue(newPerson.IsDisposed);
                newPerson = expr.Value;
                Assert.IsFalse(newPerson.IsDisposed);
            }
            Assert.IsTrue(newPerson.IsDisposed);
        }
コード例 #2
0
        public void ValueAsyncDisposal()
        {
            var john   = AsyncDisposableTestPerson.CreateJohn();
            var emily  = AsyncDisposableTestPerson.CreateEmily();
            var people = new ObservableCollection <AsyncDisposableTestPerson> {
                john
            };
            var options = new ActiveExpressionOptions();

            options.AddExpressionValueDisposal(() => new ObservableCollection <AsyncDisposableTestPerson>()[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);
        }
コード例 #3
0
        public void ValueAsyncDisposal()
        {
            var john    = AsyncDisposableTestPerson.CreateJohn();
            var options = new ActiveExpressionOptions();

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

            using (var expr = ActiveExpression.Create(() => new AsyncDisposableTestPerson(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);
        }
コード例 #4
0
        public void ValueAsyncDisposal()
        {
            var john    = AsyncDisposableTestPerson.CreateJohn();
            var emily   = AsyncDisposableTestPerson.CreateEmily();
            var options = new ActiveExpressionOptions();

            options.AddExpressionValueDisposal(() => CombineAsyncDisposablePeople(null, null));
            AsyncDisposableTestPerson first, second;

            using (var expr = ActiveExpression.Create(() => CombineAsyncDisposablePeople(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);
        }
コード例 #5
0
 AsyncDisposableTestPerson CombineAsyncDisposablePeople(AsyncDisposableTestPerson a, AsyncDisposableTestPerson b) => new AsyncDisposableTestPerson
 {
     Name = $"{a.Name} {b.Name}"
 };