Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void SourceManipulation()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>(System.Linq.Enumerable.Range(0, 10));

            using var query = numbers.ActiveLast(i => i % 3 == 0);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(9, query.Value);
            numbers.Remove(9);
            Assert.AreEqual(6, query.Value);
            numbers.RemoveAll(i => i % 3 == 0);
            Assert.IsNotNull(query.OperationFault);
            Assert.AreEqual(0, query.Value);
            numbers.Add(30);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(30, query.Value);
        }
Esempio n. 3
0
        public void ExpressionlessSourceManipulation()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>(System.Linq.Enumerable.Range(0, 10));

            using var query = numbers.ActiveFirst();
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(0, query.Value);
            numbers.Remove(0);
            Assert.AreEqual(1, query.Value);
            numbers.Clear();
            Assert.IsNotNull(query.OperationFault);
            Assert.AreEqual(0, query.Value);
            numbers.Add(30);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(30, query.Value);
        }
Esempio n. 4
0
        public void SourceManipulation()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>(System.Linq.Enumerable.Range(0, 10));

            using var query = numbers.ActiveElementAtOrDefault(9);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(9, query.Value);
            numbers.Remove(9);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(0, query.Value);
            numbers.Add(30);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(30, query.Value);
            numbers.Insert(9, 15);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(15, query.Value);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public void NullKeys()
        {
            var john   = new TestPerson(null);
            var people = new SynchronizedRangeObservableCollection <TestPerson>();

            using (var query = people.ToActiveDictionary(p => new KeyValuePair <string, TestPerson>(p.Name, p)))
            {
                Assert.IsNull(query.OperationFault);
                people.Add(john);
                Assert.IsNotNull(query.OperationFault);
                john.Name = "John";
                Assert.IsNull(query.OperationFault);
                john.Name = null;
                Assert.IsNotNull(query.OperationFault);
                people.Clear();
                Assert.IsNull(query.OperationFault);
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public void SourceManipulation()
        {
            var things = new SynchronizedRangeObservableCollection <object>(new object[]
            {
                0,
                false,
                "John",
                DateTime.Now,
                "Emily",
                Guid.NewGuid(),
                "Charles",
                TimeSpan.Zero,
                new object()
            });

            using var strings = things.ActiveOfType <string>();
            void checkStrings(params string[] against) => Assert.IsTrue(strings.OrderBy(s => s).SequenceEqual(against));

            checkStrings("Charles", "Emily", "John");
            things.Add("Bridget");
            things.Remove("John");
            things.Move(things.Count - 1, 0);
            checkStrings("Bridget", "Charles", "Emily");
            things.Reset(new object[]
            {
                new object(),
                TimeSpan.Zero,
                "George",
                Guid.NewGuid(),
                "Craig",
                DateTime.Now,
                "Cliff",
                false,
                0
            });
            checkStrings("Cliff", "Craig", "George");
        }
Esempio n. 12
0
        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");
            }
        }