|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace DevExtreme.AspNet.Data.Tests { |
| 8 | + |
| 9 | + public static class AsyncTestHelper { |
| 10 | + |
| 11 | + public interface IDataItem { |
| 12 | + int Value { get; set; } |
| 13 | + } |
| 14 | + |
| 15 | + public static IEnumerable<T> CreateTestData<T>(Func<T> itemFactory) where T : IDataItem { |
| 16 | + for(var i = 1; i <= 3; i++) { |
| 17 | + var item = itemFactory(); |
| 18 | + item.Value = i; |
| 19 | + yield return item; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + public static async Task RunAsync<T>(IQueryable<T> data) { |
| 24 | + var loadOptions = new SampleLoadOptions { |
| 25 | + RequireTotalCount = true, |
| 26 | + Take = 1, |
| 27 | + RemoteGrouping = true |
| 28 | + }; |
| 29 | + |
| 30 | + { |
| 31 | + var loadResult = await DataSourceLoader.LoadAsync(data, loadOptions); |
| 32 | + Assert.Equal(3, loadResult.totalCount); |
| 33 | + Assert.Single(loadResult.data); |
| 34 | + } |
| 35 | + |
| 36 | + { |
| 37 | + loadOptions.TotalSummary = new[] { |
| 38 | + new SummaryInfo { SummaryType = "sum", Selector = nameof(IDataItem.Value) } |
| 39 | + }; |
| 40 | + |
| 41 | + var loadResult = await DataSourceLoader.LoadAsync(data, loadOptions); |
| 42 | + Assert.Equal(6m, loadResult.summary[0]); |
| 43 | + } |
| 44 | + |
| 45 | + Assert.Contains(loadOptions.ExpressionLog, i => i.EndsWith(".Count()")); |
| 46 | + Assert.Contains(loadOptions.ExpressionLog, i => i.EndsWith(".Take(1)")); |
| 47 | + Assert.Contains(loadOptions.ExpressionLog, i => i.Contains(".GroupBy")); |
| 48 | + } |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments