|
| 1 | +using DevExtreme.AspNet.Data.ResponseModel; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace DevExtreme.AspNet.Data.Tests { |
| 9 | + |
| 10 | + public class RemoteGroupCountTestHelper { |
| 11 | + |
| 12 | + public interface IEntity { |
| 13 | + int G1 { get; set; } |
| 14 | + int G2 { get; set; } |
| 15 | + } |
| 16 | + |
| 17 | + public static IEnumerable<T> GenerateTestData<T>(Func<T> itemFactory) where T : IEntity { |
| 18 | + T CreateItem(int g1, int g2) { |
| 19 | + var item = itemFactory(); |
| 20 | + item.G1 = g1; |
| 21 | + item.G2 = g2; |
| 22 | + return item; |
| 23 | + } |
| 24 | + yield return CreateItem(1, 0); |
| 25 | + yield return CreateItem(2, 1); |
| 26 | + yield return CreateItem(2, 1); |
| 27 | + yield return CreateItem(2, 2); |
| 28 | + yield return CreateItem(3, 0); |
| 29 | + } |
| 30 | + |
| 31 | + public static void Run<T>(IQueryable<T> data) { |
| 32 | + Run(data, new[] { |
| 33 | + new GroupingInfo { Selector = "G1", IsExpanded = false } |
| 34 | + }); |
| 35 | + Run(data, new[] { |
| 36 | + new GroupingInfo { Selector = "G1", IsExpanded = false }, |
| 37 | + new GroupingInfo { Selector = "G2", IsExpanded = false } |
| 38 | + }); |
| 39 | + } |
| 40 | + |
| 41 | + static void Run<T>(IQueryable<T> data, GroupingInfo[] group) { |
| 42 | + var loadOptions = new SampleLoadOptions { |
| 43 | + RemoteGrouping = true, |
| 44 | + RequireTotalCount = false, |
| 45 | + RequireGroupCount = true, |
| 46 | + Group = group, |
| 47 | + Skip = 1, |
| 48 | + Take = 1 |
| 49 | + }; |
| 50 | + |
| 51 | + var loadResult = DataSourceLoader.Load(data, loadOptions); |
| 52 | + Assert.Equal(3, loadResult.groupCount); |
| 53 | + |
| 54 | + var log = loadOptions.ExpressionLog; |
| 55 | + |
| 56 | + if(group.Length == 1) { |
| 57 | + Assert.Equal(-1, loadResult.totalCount); // not requested |
| 58 | + Assert.Equal(2, log.Count); |
| 59 | + Assert.Contains(log, line => line.Contains(".Distinct().Count()")); |
| 60 | + } else { |
| 61 | + Assert.Equal(data.Count(), loadResult.totalCount); // bonus because all groups are loaded |
| 62 | + Assert.Single(log); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments