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]);
            }
        }
        public void LocalDataSourceProvider_Clones_Descriptions()
        {
            var engineMock = new PivotEngineMock();
            LocalDataSourceProvider provider = new LocalDataSourceProvider(engineMock);

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

                provider.FilterDescriptions.Add(new PropertyFilterDescription()
                {
                    PropertyName = "Item1", Condition = new DelegateCondition((i) => Convert.ToInt32(i) % 3 != 0)
                });
                provider.SortDescriptions.Add(new PropertySortDescription()
                {
                    PropertyName = "Item1", SortOrder = SortOrder.Descending
                });
                provider.GroupDescriptions.Add(new PropertyGroupDescription()
                {
                    PropertyName = "Item2", SortOrder = SortOrder.Descending
                });
                provider.ItemsSource = Enumerable.Range(0, 10).Select(t => new Tuple <int, int>(t, t)).ToList();
            }

            engineMock.ActionOnRebuildCube = (state) =>
            {
                Assert.AreNotSame(provider.AggregateDescriptions[0], state.AggregateDescriptions[0]);
                Assert.AreNotSame(provider.FilterDescriptions[0], state.FilterDescriptions[0]);
                Assert.AreNotSame(provider.GroupDescriptions[0], state.RowGroupDescriptions[0]);

                SortFieldComparer fieldComparer = state.ValueProvider.GetSortComparer() as SortFieldComparer;
                SortFieldComparer.InternalTestHook testHelper = new SortFieldComparer.InternalTestHook(fieldComparer);
                Assert.AreNotSame(provider.SortDescriptions[0], testHelper.SortDescriptions[0]);
            };
        }