コード例 #1
0
ファイル: SortTests.cs プロジェクト: bisaga/Grid.Blazor
        private bool ValidateSorting <T, TNext>(TestGrid grid, Func <TestModel, T> orderExpression,
                                                string columnName,
                                                GridSortDirection direction,
                                                Func <TestModel, TNext> thenByExpression,
                                                GridSortDirection?thenByDirection)
        {
            grid.AddQueryParameter(((QueryStringSortSettings)grid.Settings.SortSettings)
                                   .ColumnQueryParameterName, columnName);
            grid.AddQueryParameter(((QueryStringSortSettings)grid.Settings.SortSettings)
                                   .DirectionQueryParameterName, direction.ToString("d"));
            grid.UpdateGrid().Wait();

            IEnumerable <TestModel>        resultCollection = grid.GetItemsToDisplay();
            IOrderedEnumerable <TestModel> etalonCollection;

            switch (direction)
            {
            case GridSortDirection.Ascending:
                etalonCollection = _repo.GetAll().OrderBy(orderExpression);
                break;

            case GridSortDirection.Descending:
                etalonCollection = _repo.GetAll().OrderByDescending(orderExpression);
                break;

            default:
                throw new ArgumentOutOfRangeException("direction");
            }
            if (thenByExpression != null)
            {
                switch (thenByDirection)
                {
                case GridSortDirection.Ascending:
                    etalonCollection = etalonCollection.ThenBy(thenByExpression);
                    break;

                case GridSortDirection.Descending:
                    etalonCollection = etalonCollection.ThenByDescending(thenByExpression);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("thenByDirection");
                }
            }

            if (!ValidateCollectionsTheSame(resultCollection, etalonCollection))
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
 public override string ToString()
 {
     return(ColumnName + SortingDataDelimeter + Direction.ToString("D") + SortingDataDelimeter + Id.ToString());
 }