public void removeWhere_numElements(int numElementsToRemove)
        {
            var        collection   = new MyObservableCollection <int>();
            List <int> removedItems = new List <int>();

            collection.ItemDetached += (sender, oldItem, index) =>
            {
                removedItems.Add(oldItem);
            };
            int maxCount = 30;

            collection.AddRange(Enumerable.Range(0, maxCount));
            int initCount = collection.Count;
            int multiple  = 3;

            collection.RemoveWhere(val =>
            {
                int remainder;
                int div = Math.DivRem(val, multiple, out remainder);
                return(remainder == 0);
            }, numElementsToRemove);
            Assert.IsTrue(collection.Count == initCount - numElementsToRemove);
            var xRemovedItems = Enumerable.Range(0, numElementsToRemove)
                                .Select(val => val * multiple)
                                .ToArray();

            Assert.AreEqual(removedItems.Count, xRemovedItems.Length);
            Assert.IsTrue(!removedItems.Except(xRemovedItems).Any());
            Assert.IsTrue(!xRemovedItems.Except(removedItems).Any());
            Enumerable.Range(0, maxCount)
            .Except(xRemovedItems)
            .ForEach(val => Assert.IsTrue(collection.Contains(val)));
            xRemovedItems.ForEach(val => Assert.IsFalse(collection.Contains(val)));
        }
        public void AddRangeTest2()
        {
            var collection = new MyObservableCollection <int>();

            Enumerable.Range(10, 15).ForEach(val => collection.Add(val));
            int initCount     = collection.Count;
            int attachedCount = 0;

            collection.ItemAttached += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                attachedCount++;
            };
            int addedCount = 0;

            collection.ItemAdded += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                addedCount++;
            };

            var newItems = Enumerable.Range(0, 5).ToArray();

            collection.AddRange(newItems);
            Assert.AreEqual(attachedCount, newItems.Length);
            Assert.AreEqual(addedCount, newItems.Length);
            Assert.AreEqual(newItems.Length, collection.Count - initCount);
            foreach (var item in newItems)
            {
                Assert.IsTrue(collection.Contains(item));
            }
        }
        public void ClearTest()
        {
            var collection = new MyObservableCollection <int>();
            var newItems   = Enumerable.Range(0, 5).ToArray();

            collection.AddRange(newItems);
            int detachedCount = 0;

            collection.ItemDetached += (sender, oldItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                detachedCount++;
            };
            int removeCount = 0;

            collection.ItemRemoved += (sender, oldItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                removeCount++;
            };

            collection.Clear();
            Assert.AreEqual(detachedCount, newItems.Length);
            Assert.AreEqual(removeCount, newItems.Length);
        }
        public override async Task NavigatedToAsync(object parameter = null)
        {
            await base.NavigatedToAsync(parameter);

            Addresses.AddRange(Persona.Addresses, true);
            Contacts.AddRange(Persona.Contacts, true);
            Emails.AddRange(Persona.Emails, true);
        }
        public void AddRangeTest()
        {
            var collection    = new MyObservableCollection <int>();
            int attachedCount = 0;

            collection.ItemAttached += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                attachedCount++;
            };
            int addedCount = 0;

            collection.ItemAdded += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                addedCount++;
            };

            var newItems = Enumerable.Range(0, 5).ToArray();

            collection.AddRange(newItems);
            Assert.AreEqual(attachedCount, newItems.Length);
            Assert.AreEqual(addedCount, newItems.Length);
            Assert.AreEqual(newItems.Length, collection.Count);
            foreach (var item in newItems)
            {
                Assert.IsTrue(collection.Contains(item));
            }
            bool exceptionThrow = false;

            try
            {
                collection.AddRange(null);
            }
            catch (Exception)
            {
                exceptionThrow = true;
            }
            Assert.IsFalse(exceptionThrow);
        }
        public override async Task NavigatedToAsync(object parameter = null)
        {
            await base.NavigatedToAsync(parameter);

            if (RadioList.Count == 0)
            {
                var radios = AssemblyFileReader.ReadLocalJson <List <RadioItem> >("radio.json");
                Device.BeginInvokeOnMainThread(() =>
                {
                    RadioList.AddRange(radios);
                });
            }
        }
        public void RemoveWhereTest()
        {
            var collection = new MyObservableCollection <int>();

            collection.AddRange(Enumerable.Range(0, 31));
            collection.RemoveWhere(val =>
            {
                int remainder;
                int div = Math.DivRem(val, 3, out remainder);
                return(remainder == 0);
            });
            collection.ForEach(val =>
            {
                int remainder;
                int div = Math.DivRem(val, 3, out remainder);
                Assert.IsFalse(remainder == 0);
            });
        }
 public override Task NavigatedToAsync(object parameter = null)
 {
     return(Task.Factory.StartNew(async() =>
     {
         do
         {
             await Task.Delay(100);
         } while (ComposerList.Count == 0);
         Device.BeginInvokeOnMainThread(() =>
         {
             if (Device.RuntimePlatform.Equals(Device.iOS)) //iOS
             {
                 if (ComposerSimpleList.Any())
                 {
                     return;
                 }
                 ComposerSimpleList.AddRange(ComposerList);
             }
             else
             {
                 if (Composers.Any())
                 {
                     return;
                 }
                 var groups = ComposerList.GroupBy(x => x.Name.First().ToString());
                 foreach (var group in groups)
                 {
                     var coll = new ComposerGroup();
                     coll.AddRange(group);
                     coll.ShortName = group.Key;
                     Composers.Add(coll);
                 }
             }
         });
     }));
 }
Beispiel #9
0
 public void UpdateListEmployees(List <Employee> employees)
 {
     _observeEmployees.Clear();
     _observeEmployees.AddRange(employees);
 }
Beispiel #10
0
        public override async Task NavigatedToAsync(object parameter = null)
        {
            await base.NavigatedToAsync(parameter);

            Documents.AddRange(Persona.Identifications, true);
        }