public void SourceManipulation() { var numbers = new SynchronizedRangeObservableCollection <int>(Enumerable.Range(1, 3)); using var expr = numbers.ActiveSingle(i => i % 3 == 0); Assert.IsNull(expr.OperationFault); Assert.AreEqual(3, expr.Value); numbers.RemoveAt(2); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value); numbers.Add(3); Assert.IsNull(expr.OperationFault); Assert.AreEqual(3, expr.Value); numbers.Add(5); Assert.IsNull(expr.OperationFault); Assert.AreEqual(3, expr.Value); numbers.Add(6); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value); numbers.Clear(); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value); numbers.Add(3); numbers.Add(6); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value); numbers.RemoveAt(0); Assert.IsNull(expr.OperationFault); Assert.AreEqual(6, expr.Value); }
public void ExpressionlessSourceManipulation() { var numbers = new SynchronizedRangeObservableCollection <decimal>(); using var aggregate = numbers.ActiveAverage(); Assert.IsNotNull(aggregate.OperationFault); Assert.AreEqual(0, aggregate.Value); numbers.Add(1m); Assert.IsNull(aggregate.OperationFault); Assert.AreEqual(1m, aggregate.Value); numbers.AddRange(System.Linq.Enumerable.Range(2, 3).Select(i => Convert.ToDecimal(i))); Assert.AreEqual(2.5m, aggregate.Value); numbers.RemoveRange(0, 2); Assert.AreEqual(3.5m, aggregate.Value); numbers.RemoveAt(0); Assert.AreEqual(4m, aggregate.Value); numbers.RemoveAt(0); Assert.IsNotNull(aggregate.OperationFault); Assert.AreEqual(0m, aggregate.Value); numbers.Reset(System.Linq.Enumerable.Range(2, 3).Select(i => Convert.ToDecimal(i))); Assert.IsNull(aggregate.OperationFault); Assert.AreEqual(3m, aggregate.Value); }
public void ExpressionlessSourceManipulation() { var numbers = new SynchronizedRangeObservableCollection <int>(new int[] { 1 }); using var expr = numbers.ActiveSingle(); Assert.IsNull(expr.OperationFault); Assert.AreEqual(1, expr.Value); numbers.Add(2); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value); numbers.RemoveAt(0); Assert.IsNull(expr.OperationFault); Assert.AreEqual(2, expr.Value); numbers.Clear(); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value); }
public void SourceManipulation() { var numbers = new SynchronizedRangeObservableCollection <int>(Enumerable.Range(1, 10).Select(i => i * 3)); using var query = numbers.ActiveAll(i => i % 3 == 0); Assert.IsNull(query.OperationFault); Assert.IsTrue(query.Value); numbers[0] = 2; Assert.IsFalse(query.Value); numbers.RemoveAt(0); Assert.IsTrue(query.Value); --numbers[0]; Assert.IsFalse(query.Value); numbers.Clear(); Assert.IsTrue(query.Value); numbers.Add(7); Assert.IsFalse(query.Value); }
public void SourceManipulation() { var numbers = new SynchronizedRangeObservableCollection <int>(null, System.Linq.Enumerable.Range(0, 10).SelectMany(i => i.Repeat(5))); using var query = numbers.ActiveDistinct(); Assert.AreEqual(0, query.GetElementFaults().Count); Assert.AreEqual(10, query.Count); numbers.RemoveAt(0); Assert.AreEqual(10, query.Count); numbers.RemoveRange(0, 4); Assert.AreEqual(9, query.Count); numbers.Add(10); Assert.AreEqual(10, query.Count); numbers.AddRange(10.Repeat(4)); Assert.AreEqual(10, query.Count); numbers.Reset(System.Linq.Enumerable.Range(0, 5).SelectMany(i => i.Repeat(2))); Assert.AreEqual(5, query.Count); }
public void ExpressionlessSourceManipulation() { var numbers = new SynchronizedRangeObservableCollection <int>(); using var aggregate = numbers.ActiveSum(); Assert.IsNull(aggregate.OperationFault); Assert.AreEqual(0, aggregate.Value); numbers.Add(1); Assert.IsNull(aggregate.OperationFault); Assert.AreEqual(1, aggregate.Value); numbers.AddRange(System.Linq.Enumerable.Range(2, 3)); Assert.AreEqual(10, aggregate.Value); numbers.RemoveRange(0, 2); Assert.AreEqual(7, aggregate.Value); numbers.RemoveAt(0); Assert.AreEqual(4, aggregate.Value); numbers.Reset(System.Linq.Enumerable.Range(1, 3)); Assert.AreEqual(6, aggregate.Value); }
public void SourceManipulation() { var teams = new SynchronizedRangeObservableCollection <TestTeam>(); using (var expr = teams.ActiveSelectMany(team => team.People)) { void checkMergedNames(string against) => Assert.AreEqual(against, string.Join(string.Empty, expr.Select(person => person.Name))); checkMergedNames(string.Empty); var management = new TestTeam(); management.People.Add(new TestPerson("Charles")); teams.Add(management); checkMergedNames("Charles"); management.People.Add(new TestPerson("Michael")); checkMergedNames("CharlesMichael"); management.People.RemoveAt(1); checkMergedNames("Charles"); var development = new TestTeam(); teams.Add(development); checkMergedNames("Charles"); development.People.AddRange(new TestPerson[] { new TestPerson("John"), new TestPerson("Emily"), new TestPerson("Edward"), new TestPerson("Andrew") }); checkMergedNames("CharlesJohnEmilyEdwardAndrew"); development.People.RemoveRange(2, 2); checkMergedNames("CharlesJohnEmily"); var qa = new TestTeam(); qa.People.AddRange(new TestPerson[] { new TestPerson("Aaron"), new TestPerson("Cliff") }); teams.Add(qa); checkMergedNames("CharlesJohnEmilyAaronCliff"); qa.People[0].Name = "Erin"; checkMergedNames("CharlesJohnEmilyErinCliff"); var bryan = new TestPerson("Brian"); var it = new TestTeam(); it.People.AddRange(new TestPerson[] { bryan, bryan }); teams.Add(it); checkMergedNames("CharlesJohnEmilyErinCliffBrianBrian"); bryan.Name = "Bryan"; checkMergedNames("CharlesJohnEmilyErinCliffBryanBryan"); it.People.Clear(); checkMergedNames("CharlesJohnEmilyErinCliff"); it.People = null; checkMergedNames("CharlesJohnEmilyErinCliff"); it.People = new SynchronizedRangeObservableCollection <TestPerson>() { new TestPerson("Paul") }; checkMergedNames("CharlesJohnEmilyErinCliffPaul"); it.People[0] = new TestPerson("Alex"); checkMergedNames("CharlesJohnEmilyErinCliffAlex"); development.People.Move(1, 0); checkMergedNames("CharlesEmilyJohnErinCliffAlex"); development.People.ReplaceRange(0, 2, development.People.GetRange(0, 1)); checkMergedNames("CharlesEmilyErinCliffAlex"); it.People.Clear(); it.People.Reset(new TestPerson[] { new TestPerson("Daniel") }); checkMergedNames("CharlesEmilyErinCliffDaniel"); teams.Add(management); checkMergedNames("CharlesEmilyErinCliffDanielCharles"); management.People.Insert(0, new TestPerson("George")); checkMergedNames("GeorgeCharlesEmilyErinCliffDanielGeorgeCharles"); var currentManagers = management.People; var otherManagers = new SynchronizedRangeObservableCollection <TestPerson>() { new TestPerson("Josh"), new TestPerson("Jessica") }; management.People = otherManagers; checkMergedNames("JoshJessicaEmilyErinCliffDanielJoshJessica"); management.People = currentManagers; teams.RemoveAt(teams.Count - 1); checkMergedNames("GeorgeCharlesEmilyErinCliffDaniel"); teams.Insert(0, management); checkMergedNames("GeorgeCharlesGeorgeCharlesEmilyErinCliffDaniel"); teams.Move(2, 1); checkMergedNames("GeorgeCharlesEmilyGeorgeCharlesErinCliffDaniel"); teams.Move(1, 2); checkMergedNames("GeorgeCharlesGeorgeCharlesEmilyErinCliffDaniel"); teams.RemoveAt(1); checkMergedNames("GeorgeCharlesEmilyErinCliffDaniel"); teams.RemoveAt(0); checkMergedNames("EmilyErinCliffDaniel"); } }