public void TestGroupByOnExistingValues()
        {
            // Create group by
            var baseTable = TestTableHelper.CreateReactiveTable();

            // Add values
            var row1 = baseTable.AddRow();

            baseTable.SetValue(TestTableColumns.StringColumn, row1, "Value1");

            var row2 = baseTable.AddRow();

            baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value2");

            var row3 = baseTable.AddRow();

            baseTable.SetValue(TestTableColumns.StringColumn, row3, "Value1");

            // Modify grouped columns
            baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value1");
            baseTable.SetValue(TestTableColumns.StringColumn, row3, "Value3");

            // Now group it
            var groupedTable = new AggregatedTable(baseTable);

            groupedTable.GroupBy <string>(TestTableColumns.StringColumn);
            var countCol = "CountCol";

            groupedTable.AddAggregate((IReactiveColumn <string>)baseTable.GetColumnByName(TestTableColumns.StringColumn),
                                      countCol,
                                      () => new Count <string>());

            var rowUpdates = new RowUpdateHandler();

            groupedTable.Subscribe(rowUpdates);
            var colUpdates = new ColumnUpdateHandler();

            groupedTable.Subscribe(colUpdates.OnColumnUpdate);
            groupedTable.FinishInitialisation();

            Assert.AreEqual(2, groupedTable.RowCount);
            Assert.AreEqual(2, rowUpdates.CurrentRowCount);
            Assert.AreEqual("Value1", groupedTable.GetValue <string>(TestTableColumns.StringColumn, 0));
            Assert.AreEqual("Value3", groupedTable.GetValue <string>(TestTableColumns.StringColumn, 1));
            Assert.AreEqual(2, groupedTable.GetValue <int>(countCol, 0));
            Assert.AreEqual(1, groupedTable.GetValue <int>(countCol, 1));

            // Remove rows
            baseTable.DeleteRow(row1);
            Assert.AreEqual(2, groupedTable.RowCount);
            Assert.AreEqual(2, rowUpdates.CurrentRowCount);

            baseTable.DeleteRow(row2);
            Assert.AreEqual(1, groupedTable.RowCount);
            Assert.AreEqual(1, rowUpdates.CurrentRowCount);

            baseTable.DeleteRow(row3);
            Assert.AreEqual(0, groupedTable.RowCount);
            Assert.AreEqual(0, rowUpdates.CurrentRowCount);
        }
        public GroupTestViewModel(IAccountBalanceDataService service)
        {
            var accountsTable = service.Accounts;

            _groupedAccounts = new AggregatedTable(accountsTable);
            _groupedAccounts.GroupBy <int>(AccountColumns.PersonId);
            var balanceColumn = (IReactiveColumn <decimal>)accountsTable.GetColumnByName(AccountColumns.AccountBalance);

            _groupedAccounts.AddAggregate(balanceColumn, SumColumnId, () => new Sum <decimal>());
            _groupedAccounts.AddAggregate(balanceColumn, CountColumnId, () => new Count <decimal>());
            _groupedAccounts.FinishInitialisation();

            var groups = new IndexedObservableCollection <BalanceGroup, int>(g => g.RowIndex);

            _groupedAccounts.ReplayAndSubscribe(
                update =>
            {
                if (update.Action == TableUpdateAction.Add)
                {
                    groups.Add(new BalanceGroup(_groupedAccounts, update.RowIndex));
                }
                else if (update.Action == TableUpdateAction.Delete)
                {
                    groups.RemoveAt(groups.GetIndexForKey(update.RowIndex));
                }
            });

            var accounts = new IndexedObservableCollection <AccountViewModel, int>(a => a.RowIndex);

            accountsTable.ReplayAndSubscribe(
                update =>
            {
                if (update.Action == TableUpdateAction.Add)
                {
                    var accountViewModel = new AccountViewModel(accountsTable, update.RowIndex);
                    accounts.Add(accountViewModel);
                    Debug.WriteLine("{1},Adding,,{0},", update.RowIndex, DateTime.Now.ToLongTimeString());
                }
                else if (update.Action == TableUpdateAction.Delete)
                {
                    var indexForKey      = accounts.GetIndexForKey(update.RowIndex);
                    var accountViewModel = accounts[indexForKey];
                    accounts.RemoveAt(indexForKey);
                    Debug.WriteLine("{1},Removing,{0}", accountViewModel.PersonId, DateTime.Now.ToLongTimeString());
                }
                else
                {
                    var indexForKey      = accounts.GetIndexForKey(update.RowIndex);
                    var accountViewModel = accounts[indexForKey];
                    Debug.WriteLine("{1},Modifying,{0},{2},{3}",
                                    accountViewModel.PersonId, DateTime.Now.ToLongTimeString(), update.RowIndex, update.Column.ColumnId);
                }
            });
            Groups   = groups;
            Accounts = accounts;
        }
        public GroupTestViewModelSyncfusion(IAccountBalanceDataService service)
        {
            var accountsTable   = service.Accounts;
            var groupedAccounts = new AggregatedTable(accountsTable);

            groupedAccounts.GroupBy <int>(AccountColumns.PersonId);
            var balanceColumn = (IReactiveColumn <decimal>)accountsTable.GetColumnByName(AccountColumns.AccountBalance);

            groupedAccounts.AddAggregate(balanceColumn, GroupTestViewModel.SumColumnId, () => new Sum <decimal>());
            groupedAccounts.AddAggregate(balanceColumn, GroupTestViewModel.CountColumnId, () => new Count <decimal>());
            groupedAccounts.FinishInitialisation();
            SetTable(groupedAccounts);
        }