Example #1
0
        public async Task ValueAsyncDisposal()
        {
            var john    = AsyncDisposableTestPerson.CreateJohn();
            var emily   = AsyncDisposableTestPerson.CreateEmily();
            var options = new ActiveExpressionOptions();

            options.AddExpressionValueDisposal(() => CombineAsyncDisposablePeople(null !, null !));
            AsyncDisposableTestPerson?first, second;
            var disposedTcs = new TaskCompletionSource <object?>();

            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);
                first.Disposed += (sender, e) => disposedTcs.SetResult(null);
                john.Name       = string.Empty;
                await Task.WhenAny(disposedTcs.Task, Task.Delay(TimeSpan.FromSeconds(1)));

                Assert.IsNull(expr.Fault);
                second = expr.Value;
                Assert.IsFalse(second !.IsDisposed);
                Assert.IsTrue(first.IsDisposed);
                disposedTcs      = new TaskCompletionSource <object?>();
                second.Disposed += (sender, e) => disposedTcs.SetResult(null);
            }
            await Task.WhenAny(disposedTcs.Task, Task.Delay(TimeSpan.FromSeconds(1)));

            Assert.IsTrue(second.IsDisposed);
        }
Example #2
0
        public void SelectorsOptions()
        {
            var people  = TestPerson.CreatePeopleCollection();
            var options = new ActiveExpressionOptions();

            using var expr = people.ActiveOrderBy(new ActiveOrderingKeySelector <TestPerson>(person => person.Name !.Length, options), new ActiveOrderingKeySelector <TestPerson>(person => person.Name !, options));
            void checkMergedNames(string against) => Assert.AreEqual(against, string.Join(string.Empty, expr.Select(person => person.Name)));

            checkMergedNames("BenErinJohnBryanCliffCraigEmilyJamesSteveGeorgeHunterBridgetCharlesNanette");
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
0
 public static EnumerableRangeActiveExpression <TElement, TResult> Create <TElement, TResult>(IEnumerable <TElement> source, Expression <Func <TElement, TResult> > expression, ActiveExpressionOptions options = null) => EnumerableRangeActiveExpression <TElement, TResult> .Create(source, expression, options);
Example #7
0
 public static ReadOnlyDictionaryRangeActiveExpression <TKey, TValue, TResult> Create <TKey, TValue, TResult>(IReadOnlyDictionary <TKey, TValue> source, Expression <Func <TKey, TValue, TResult> > expression, ActiveExpressionOptions options = null) => ReadOnlyDictionaryRangeActiveExpression <TKey, TValue, TResult> .Create(source, expression, options);
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActiveOrderingKeySelector{T}"/> class with the specified key extraction expression for sorting in the specified order
 /// </summary>
 /// <param name="expression">An expression to extract a key from an element</param>
 /// <param name="expressionOptions">Options governing the behavior of active expressions created using <paramref name="expression"/></param>
 /// <param name="isDescending"><c>true</c> to sort in descending order; otherwise, sort in ascending order</param>
 public ActiveOrderingKeySelector(Expression <Func <T, IComparable> > expression, ActiveExpressionOptions expressionOptions, bool isDescending)
 {
     Expression        = expression;
     ExpressionOptions = expressionOptions;
     IsDescending      = isDescending;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActiveOrderingKeySelector{T}"/> class with the specified key extraction expression for sorting in ascending order
 /// </summary>
 /// <param name="expression">An expression to extract a key from an element</param>
 /// <param name="expressionOptions">Options governing the behavior of active expressions created using <paramref name="expression"/></param>
 public ActiveOrderingKeySelector(Expression <Func <T, IComparable> > expression, ActiveExpressionOptions expressionOptions) : this(expression, expressionOptions, false)
 {
 }