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); }
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); }
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); }
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); }
AsyncDisposableTestPerson CombineAsyncDisposablePeople(AsyncDisposableTestPerson a, AsyncDisposableTestPerson b) => new AsyncDisposableTestPerson { Name = $"{a.Name} {b.Name}" };