private void InitializeProviderThatIsGettingFieldInfosOnRefresh()
        {
            var fieldInfoProvider = new FieldDescriptionProviderBaseStub();

            fieldInfoProvider.ActionOnGetDescriptionsDataAsync = (s) => { /* do not return */ };

            var engine = new PivotEngineMock();

            this.provider = new LocalDataSourceProvider(engine, fieldInfoProvider);
            this.provider.GroupFactory = new DataGroupFactory();
            this.provider.DeferUpdates = true;
            this.provider.RowGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Product"
            });
            this.provider.ColumnGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Promotion"
            });
            this.provider.AggregateDescriptions.Add(new PropertyAggregateDescription()
            {
                PropertyName = "Quantity"
            });
            this.provider.StatusChanged += OnProviderStatusChanged;
        }
        private void InitializeProviderThatWillRetrieveDataOnRefresh()
        {
            var fieldInfoProvider = new FieldDescriptionProviderBaseStub();

            fieldInfoProvider.DataToReturn = new EmptyFieldInfoData();

            var engine = new PivotEngineMock();

            engine.SetToReturnResponse();

            this.provider = new LocalDataSourceProvider(engine, fieldInfoProvider);
            this.provider.GroupFactory = new DataGroupFactory();
            this.provider.DeferUpdates = true;
            this.provider.RowGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Product"
            });
            this.provider.ColumnGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Promotion"
            });
            this.provider.AggregateDescriptions.Add(new PropertyAggregateDescription()
            {
                PropertyName = "Quantity"
            });
            this.provider.StatusChanged += OnProviderStatusChanged;
        }
        private void InitializeProviderThatCannotRetrieveFieldInfosOnRefresh()
        {
            var fieldInfoProvider = new FieldDescriptionProviderBaseStub();

            fieldInfoProvider.ErrorToReturn = new Exception("Dummy exception");

            var engine = new PivotEngineMock();

            this.provider = new LocalDataSourceProvider(engine, fieldInfoProvider);
            this.provider.GroupFactory = new DataGroupFactory();
            this.provider.DeferUpdates = true;
            this.provider.RowGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Product"
            });
            this.provider.ColumnGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Promotion"
            });
            this.provider.AggregateDescriptions.Add(new PropertyAggregateDescription()
            {
                PropertyName = "Quantity"
            });
            this.provider.StatusChanged += OnProviderStatusChanged;
        }
        private void InitializeProviderWithXmlaClientThatReturnsErrorOnSendRequestCompleted()
        {
            var fieldInfoProvider = new FieldDescriptionProviderBaseStub();

            fieldInfoProvider.DataToReturn = new EmptyFieldInfoData();

            var engine = new PivotEngineMock();

            engine.SetToReturnErrorResponse();

            this.provider = new LocalDataSourceProvider(engine, fieldInfoProvider);
            this.provider.GroupFactory = new DataGroupFactory();
            this.provider.DeferUpdates = true;
            this.provider.RowGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Product"
            });
            this.provider.ColumnGroupDescriptions.Add(new PropertyGroupDescription()
            {
                PropertyName = "Promotion"
            });
            this.provider.AggregateDescriptions.Add(new PropertyAggregateDescription()
            {
                PropertyName = "Quantity"
            });
            this.provider.StatusChanged += OnProviderStatusChanged;
        }
        public void CompletedEvent_WhenEngineCompletedEventIsRaised_IsRaised()
        {
            var engine = new PivotEngineMock();

            this.provider = new LocalDataSourceProvider(engine);
            this.provider.GroupFactory   = new DataGroupFactory();
            this.provider.StatusChanged += this.OnProviderStatusChanged;

            engine.RaiseCompletedEvent(new DataEngineCompletedEventArgs(null, DataEngineStatus.Completed));

            Assert.IsTrue(this.StatuschangedEventWasRaised());
        }
        public void Status_WhenEngineCompletedEventIsRaisedWithFaulted_IsSetToFaulted()
        {
            var engine = new PivotEngineMock();

            this.provider = new LocalDataSourceProvider(engine);
            this.provider.GroupFactory = new DataGroupFactory();
            var expectedStatus = DataProviderStatus.Faulted;

            engine.RaiseCompletedEvent(new DataEngineCompletedEventArgs(null, DataEngineStatus.Faulted));
            var actualStatus = this.provider.Status;

            Assert.AreEqual(expectedStatus, actualStatus);
        }
        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]);
            };
        }