public void LocalDataSourceProvider_ThrowException_In_Finalize()
        {
            try
            {
                LocalDataSourceProvider provider = new LocalDataSourceProvider()
                {
                    ItemsSource = Enumerable.Range(0, 10).Select(t => new Tuple <int, int>(t, t)).ToList()
                };

                var description = new PropertyGroupDescription()
                {
                    PropertyName = "Item1"
                };
                ((IGroupDescription)description).GroupComparer = new BrokenComparer();
                provider.RowGroupDescriptions.Add(description);

                provider.Refresh();
                provider.BlockUntilRefreshCompletes();

                Assert.AreEqual(DataProviderStatus.Faulted, provider.Status);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }
        public void Status_WhenRefreshIsCalled_WhenItemsSourceIsNull_ShouldRemainUninitialized()
        {
            LocalDataSourceProvider provider = new LocalDataSourceProvider();

            provider.AggregateDescriptions.Add(new ListAggregateDescription()
            {
                PropertyName = "Item1"
            });

            this.provider.ItemsSource = Order.GetData();
            provider.Refresh();
            provider.BlockUntilRefreshCompletes();

            Assert.AreEqual(DataProviderStatus.Uninitialized, provider.Status);
        }
        public void LocalDataSourceProvider_FilterDescriptions()
        {
            LocalDataSourceProvider provider = new LocalDataSourceProvider();

            using (provider.DeferRefresh())
            {
                provider.ItemsSource  = Enumerable.Range(0, 10).Select(t => new Tuple <int, int>(t, t)).ToList();
                provider.GroupFactory = new DataGroupFactory();

                provider.AggregateDescriptions.Add(new ListAggregateDescription()
                {
                    PropertyName = "Item1"
                });

                provider.FilterDescriptions.Add(new PropertyFilterDescription()
                {
                    PropertyName = "Item1", Condition = new DelegateCondition((i) => Convert.ToInt32(i) % 3 != 0)
                });
                provider.FilterDescriptions.Add(new PropertyFilterDescription()
                {
                    PropertyName = "Item1", Condition = new DelegateCondition((i) => Convert.ToInt32(i) % 5 != 0)
                });
                provider.FilterDescriptions.Add(new PropertyFilterDescription()
                {
                    PropertyName = "Item1", Condition = new DelegateCondition((i) => Convert.ToInt32(i) % 7 != 0)
                });
                // will pass: 1, 2, 4, 8
            }

            provider.BlockUntilRefreshCompletes();

            var         r      = ((IDataProvider)provider).Results;
            IList <int> values = r.GetAggregateResult(0, r.Root).GetValue() as IList <int>;

            Assert.AreEqual(4, values.Count);
            Assert.IsTrue(values.Contains(1));
            Assert.IsTrue(values.Contains(2));
            Assert.IsTrue(values.Contains(4));
            Assert.IsTrue(values.Contains(8));
        }
        public void LocalDataSourceProvider_SortDescriptions_NoGrouping_Ascending()
        {
            var data = Enumerable.Range(0, 10000).Select((i) => new DataItem {
                ID = i, Name = "Name" + i % 500, Surname = "Surname" + (5000 - i) % 1000
            }).ToList();

            LocalDataSourceProvider provider = new LocalDataSourceProvider();

            using (provider.DeferRefresh())
            {
                provider.GroupFactory = new DataGroupFactory();
                provider.SortDescriptions.Add(new PropertySortDescription()
                {
                    PropertyName = "Name", SortOrder = SortOrder.Descending
                });
                provider.SortDescriptions.Add(new PropertySortDescription()
                {
                    PropertyName = "ID", SortOrder = SortOrder.Descending
                });
                provider.ItemsSource = data;
            }
            provider.BlockUntilRefreshCompletes();

            DataItemComparer comparer = new DataItemComparer(new DataItemNameComparer()
            {
                Descending = true
            }, new DataItemIDComparer()
            {
                Descending = true
            });

            data.Sort(comparer);

            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreSame(data[i], provider.Results.Root.RowGroup.Items[i]);
            }
        }