Example #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);
        }
Example #2
0
        public void ExpressionlessEmptySource()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>();

            using var query = numbers.ActiveLast();
            Assert.IsNotNull(query.OperationFault);
            Assert.AreEqual(0, query.Value);
        }
Example #3
0
        public void Multiple()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>(Enumerable.Range(1, 3).Select(i => i * 3));

            using var expr = numbers.ActiveSingle(i => i % 3 == 0);
            Assert.IsNotNull(expr.OperationFault);
            Assert.AreEqual(0, expr.Value);
        }
Example #4
0
        public void ExpressionlessMultiple()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>(new int[] { 1, 1 });

            using var expr = numbers.ActiveSingle();
            Assert.IsNotNull(expr.OperationFault);
            Assert.AreEqual(0, expr.Value);
        }
Example #5
0
        public void EmptySource()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>();

            using var expr = numbers.ActiveSingle(i => i % 3 == 0);
            Assert.IsNotNull(expr.OperationFault);
            Assert.AreEqual(0, expr.Value);
        }
Example #6
0
        public void NonGenericEmpty()
        {
            var people = new SynchronizedRangeObservableCollection <TestPerson>();

            using (var query = ((IEnumerable)people).ActiveSelect(person => 3 / (person as TestPerson).Name.Length))
            {
            }
        }
Example #7
0
        public void ExpressionlessEmptySource()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>();

            using var expr = numbers.ActiveSingleOrDefault();
            Assert.IsNull(expr.OperationFault);
            Assert.AreEqual(0, expr.Value);
        }
Example #8
0
        public void EnumerableOutOfRange()
        {
            var numbers    = new SynchronizedRangeObservableCollection <int>(System.Linq.Enumerable.Range(0, 5));
            var enumerable = (IEnumerable <int>)numbers;

            using var query = enumerable.ActiveElementAtOrDefault(9);
            Assert.IsNull(query.OperationFault);
            Assert.AreEqual(0, query.Value);
        }
Example #9
0
        public void SourceManipulation()
        {
            var numbers = new SynchronizedRangeObservableCollection <int>(System.Linq.Enumerable.Range(1, 10));

            using var query = numbers.ActiveCast <object>();
            Assert.AreEqual(0, query.GetElementFaults().Count);
            Assert.AreEqual(55, query.Cast <int>().Sum());
            Assert.IsInstanceOfType(query[0], typeof(object));
            numbers[0] += 10;
            Assert.AreEqual(0, query.GetElementFaults().Count);
            Assert.AreEqual(65, query.Cast <int>().Sum());
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
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);
        }
Example #13
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);
        }
Example #14
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);
            }
        }
Example #15
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);
        }
Example #16
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);
        }
Example #17
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);
        }
Example #18
0
        public void Initializer()
        {
            var teams = new SynchronizedRangeObservableCollection <TestTeam>()
            {
                new TestTeam(new SynchronizedRangeObservableCollection <TestPerson>()
                {
                    new TestPerson("Emily")
                }),
                new TestTeam(new SynchronizedRangeObservableCollection <TestPerson>()
                {
                    new TestPerson("Charles")
                }),
                new TestTeam(new SynchronizedRangeObservableCollection <TestPerson>()
                {
                    new TestPerson("Erin")
                })
            };

            using (var expr = teams.ActiveSelectMany(team => team.People))
                Assert.AreEqual("EmilyCharlesErin", string.Join(string.Empty, expr.Select(person => person.Name)));
        }
Example #19
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);
        }
        public AddOnManager(DirectoryInfo storageDirectory, IWorldOfWarcraftInstallation worldOfWarcraftInstallation, SynchronizationContext synchronizationContext = null)
        {
            manifestsCheckTimer = new Timer(ManifestsCheckTimerCallback);

            WorldOfWarcraftInstallation = worldOfWarcraftInstallation;
            addOns = new SynchronizedObservableDictionary <Guid, AddOn>();
            addOnsWithUpdateAvailable = addOns.ActiveCount((addOnKey, addOn) => addOn.IsUpdateAvailable);
            addOnsWithUpdateAvailable.PropertyChanged  += AddOnsWithUpdateAvailablePropertyChanged;
            addOnsWithUpdateAvailable.PropertyChanging += AddOnsWithUpdateAvailablePropertyChanging;
            addOnsActiveEnumerable = addOns.ToActiveEnumerable();
            ManifestUrls           = new SynchronizedRangeObservableCollection <Uri>(DefaultManifestUrls);
            AddOns           = synchronizationContext == null ? addOnsActiveEnumerable : addOnsActiveEnumerable.SwitchContext(synchronizationContext);
            StorageDirectory = storageDirectory;
            if (StorageDirectory != null)
            {
                stateFile       = new FileInfo(Path.Combine(StorageDirectory.FullName, "addOnManagerState.json"));
                AddOnsDirectory = new DirectoryInfo(Path.Combine(StorageDirectory.FullName, "AddOnRepositories"));
            }

            initializationCompleteTaskCompletionSource = new TaskCompletionSource <object>();
            InitializationComplete = initializationCompleteTaskCompletionSource.Task;
            ThreadPool.QueueUserWorkItem(Initialize);
        }
Example #21
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");
        }
Example #22
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");
            }
        }
Example #23
0
 public TestTeam(SynchronizedRangeObservableCollection <TestPerson> people) => this.people = people;