This commit is contained in:
xuejiaming 2022-08-09 14:13:52 +08:00
parent b0f110829d
commit 34c38445e6
10 changed files with 731 additions and 267 deletions

View File

@ -1,9 +1,9 @@
:start
::定义版本
set EFCORE2=2.6.0.26
set EFCORE3=3.6.0.26
set EFCORE5=5.6.0.26
set EFCORE6=6.6.0.26
set EFCORE2=2.6.0.27
set EFCORE3=3.6.0.27
set EFCORE5=5.6.0.27
set EFCORE6=6.6.0.27
::删除所有bin与obj下的文件
@echo off

View File

@ -11,8 +11,10 @@ using ShardingCore.Core.RuntimeContexts;
using ShardingCore.Core.VirtualDatabase.VirtualDataSources;
using ShardingCore.Core.VirtualDatabase.VirtualDataSources.PhysicDataSources;
using ShardingCore.Core.VirtualRoutes.Abstractions;
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes.RouteRuleEngine;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine;
using ShardingCore.Exceptions;
using ShardingCore.Extensions;
using ShardingCore.Extensions.ShardingPageExtensions;
@ -47,6 +49,7 @@ namespace ShardingCore.Test
private readonly IRouteTailFactory _routeTailFactory;
private readonly IReadWriteConnectorFactory _readWriteConnectorFactory;
private readonly IShardingConnectionStringResolver _shardingConnectionStringResolver;
private readonly ITableRouteRuleEngineFactory _tableRouteRuleEngineFactory;
private readonly IShardingComparer _shardingComparer;
public ShardingTest(ShardingDefaultDbContext virtualDbContext, IShardingRuntimeContext shardingRuntimeContext, IConfiguration configuration)
@ -55,7 +58,7 @@ namespace ShardingCore.Test
_shardingRouteManager = shardingRuntimeContext.GetShardingRouteManager();
_shardingReadWriteManager = shardingRuntimeContext.GetShardingReadWriteManager();
_virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
_connectionStringManager = new ActualConnectionStringManager(_shardingReadWriteManager,_virtualDataSource);
_connectionStringManager = new ActualConnectionStringManager(_shardingReadWriteManager, _virtualDataSource);
_configuration = configuration;
_entityMetadataManager = shardingRuntimeContext.GetEntityMetadataManager();
_tableRouteManager = shardingRuntimeContext.GetTableRouteManager();
@ -63,8 +66,9 @@ namespace ShardingCore.Test
_routeTailFactory = shardingRuntimeContext.GetRouteTailFactory();
_shardingComparer = shardingRuntimeContext.GetShardingComparer();
_readWriteConnectorFactory = shardingRuntimeContext.GetReadWriteConnectorFactory();
_tableRouteRuleEngineFactory = shardingRuntimeContext.GetService<ITableRouteRuleEngineFactory>();
var readWriteConnectors = _virtualDataSource.ConfigurationParams.ReadWriteNodeSeparationConfigs.Select(o => _readWriteConnectorFactory.CreateConnector(_virtualDataSource.ConfigurationParams.ReadStrategy.GetValueOrDefault(), o.Key, o.Value));
_shardingConnectionStringResolver = new ReadWriteShardingConnectionStringResolver(readWriteConnectors, _virtualDataSource.ConfigurationParams.ReadStrategy.GetValueOrDefault(),_readWriteConnectorFactory);
_shardingConnectionStringResolver = new ReadWriteShardingConnectionStringResolver(readWriteConnectors, _virtualDataSource.ConfigurationParams.ReadStrategy.GetValueOrDefault(), _readWriteConnectorFactory);
}
// [Fact]
// public void RouteParseCompileCacheTest()
@ -211,7 +215,7 @@ namespace ShardingCore.Test
{ new ParallelTableComparerType(typeof(SysUserSalary)),new ParallelTableComparerType(typeof(SysUserMod)), });
Assert.Equal(x1x1, x2x2);
Assert.Equal(x1x1.GetHashCode(), x2x2.GetHashCode());
var succeedAddConnectionString = _shardingConnectionStringResolver.AddConnectionString("X", "Data Source=localhost;Initial Catalog=ShardingCoreDBC;Integrated Security=True;",null);
var succeedAddConnectionString = _shardingConnectionStringResolver.AddConnectionString("X", "Data Source=localhost;Initial Catalog=ShardingCoreDBC;Integrated Security=True;", null);
Assert.True(succeedAddConnectionString);
var connectionString = _shardingConnectionStringResolver.GetConnectionString("X", null);
Assert.Equal("Data Source=localhost;Initial Catalog=ShardingCoreDBC;Integrated Security=True;", connectionString);
@ -361,7 +365,7 @@ namespace ShardingCore.Test
Assert.Equal(pageDescAge, sysUserMod.Age);
pageDescAge--;
}
var skip10First= await _virtualDbContext.Set<SysUserMod>().Skip(10).OrderByDescending(o => o.Age).FirstOrDefaultAsync();
var skip10First = await _virtualDbContext.Set<SysUserMod>().Skip(10).OrderByDescending(o => o.Age).FirstOrDefaultAsync();
Assert.Equal(skip10First, pageResult[0]);
}
@ -524,9 +528,9 @@ namespace ShardingCore.Test
[Fact]
public async Task ToList_Id_Eq_Not_In_Db_Test()
{
var mod1s = await _virtualDbContext.Set<SysUserMod>().Where(o =>string.Compare(((IId)o).Id,"1001") ==0).ToListAsync();
var mod1s = await _virtualDbContext.Set<SysUserMod>().Where(o => string.Compare(((IId)o).Id, "1001") == 0).ToListAsync();
var mod2s = await _virtualDbContext.Set<SysUserMod>().Where(o => string.Compare("1001", o.Id) == 0).ToListAsync();
var mod3s = await _virtualDbContext.Set<SysUserMod>().Where(o => "1001".CompareTo(o.Id)==0).ToListAsync();
var mod3s = await _virtualDbContext.Set<SysUserMod>().Where(o => "1001".CompareTo(o.Id) == 0).ToListAsync();
var mod4s = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id.CompareTo("1001") == 0).ToListAsync();
var mods = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1001").ToListAsync();
Assert.Empty(mods);
@ -603,9 +607,9 @@ namespace ShardingCore.Test
Assert.Equal("2", sysUserMod.Id);
var sysUserMod2 = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Name == "name_2").Select(o => new
{
Name=o.Name
Name = o.Name
}).FirstOrDefaultAsync();
var sysUserMod1 = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Name == "name_2").Select(o => new TestClass(o.Name,""){Id = o.Id}).FirstOrDefaultAsync();
var sysUserMod1 = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Name == "name_2").Select(o => new TestClass(o.Name, "") { Id = o.Id }).FirstOrDefaultAsync();
Assert.NotNull(sysUserMod1);
}
@ -615,7 +619,7 @@ namespace ShardingCore.Test
public string Aa { get; }
public string Id { get; set; }
public TestClass(string name,string aa)
public TestClass(string name, string aa)
{
Name = name;
Aa = aa;
@ -761,7 +765,7 @@ namespace ShardingCore.Test
select new
{
UI = g.Key,
x=g.Sum(o=>o.SalaryDecimal),
x = g.Sum(o => o.SalaryDecimal),
Now = dateTime
};
var listAsync = await sql.ToListAsync();
@ -790,47 +794,6 @@ namespace ShardingCore.Test
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
//[Fact]
//public async Task Group_Recently_Test()
//{
// //var list =(from us in _virtualDbContext.Set<SysUserSalary>().Where(o => ids.Contains(o.UserId))
// // group us by new
// // {
// // UserId=us.UserId
// // }
// // into g
// // select new
// // {
// // UserId=g.Key.UserId,
// // DateOfMonth = g.Max(o=>o.DateOfMonth)
// // }).ToList();
// //var y = list;
// var ids = new List<string>(){ "200", "300" };
// List<SysUserSalary> result = new List<SysUserSalary>(ids.Count);
// var routeFilter = new List<SysUserSalary>().AsQueryable().Where(o => ids.Contains(o.UserId));
// //<2F><>ȡ<EFBFBD><C8A1>·<EFBFBD><C2B7>ʱ<EFBFBD><EFBFBD><E4B5B9>
// var tableRouteResults = _tableRouteRuleEngineFactory.Route(routeFilter)
// .Select(o => o.ReplaceTables.First().Tail).OrderByDescending(o => o).ToList();
// foreach (var tableRouteResult in tableRouteResults)
// {
// if(ids.IsEmpty())
// break;
// using (_shardingRouteManager.CreateScope())
// {
// _shardingRouteManager.Current.TryCreateOrAddMustTail<SysUserSalary>(tableRouteResult);
// var queryable = _virtualDbContext.Set<SysUserSalary>().Where(o => ids.Contains(o.UserId))
// .GroupBy(o => new { o.UserId }, i => i,
// (i, u) => new {
// Data = u.OrderByDescending(o => o.DateOfMonth).FirstOrDefault()
// });
// var r =await queryable.ToListAsync();
// result.AddRange(r.Select(o=>o.Data));
// var removeUserIds = result.Select(u => u.UserId).ToHashSet();
// ids.RemoveAll(o => removeUserIds.Contains(o));
// }
// }
//}
[Fact]
public async Task OrderCountTest()
@ -924,7 +887,7 @@ namespace ShardingCore.Test
public void LogDayTableSeparatorTest()
{
var tableRoute = _tableRouteManager.GetRoute(typeof(LogDay));
var virtualTableName =tableRoute.EntityMetadata.LogicTableName;
var virtualTableName = tableRoute.EntityMetadata.LogicTableName;
Assert.Equal(nameof(LogDay), virtualTableName);
Assert.True(string.IsNullOrWhiteSpace(tableRoute.EntityMetadata.TableSeparator));
@ -961,7 +924,7 @@ namespace ShardingCore.Test
var fourBegin = new DateTime(2021, 4, 1).Date;
var fiveBegin = new DateTime(2021, 5, 1).Date;
var moneyAverage = await _virtualDbContext.Set<Order>()
.Where(o => o.CreateTime >= fourBegin&& o.CreateTime <= fiveBegin).Select(o => o.Money).AverageAsync();
.Where(o => o.CreateTime >= fourBegin && o.CreateTime <= fiveBegin).Select(o => o.Money).AverageAsync();
Assert.Equal(105, moneyAverage);
using (_shardingRouteManager.CreateScope())
@ -1693,35 +1656,136 @@ namespace ShardingCore.Test
[Fact]
public async Task QueryInner_Test()
{
var sysUserMods = _virtualDbContext.Set<SysUserMod>().Select(o=>o);
var sysUserModInts = await _virtualDbContext.Set<SysUserModInt>().Where(o=>sysUserMods.Select(i=>i.Age).Any(i=>i==o.Age)).ToListAsync();
var sysUserMods = _virtualDbContext.Set<SysUserMod>().Select(o => o);
var sysUserModInts = await _virtualDbContext.Set<SysUserModInt>().Where(o => sysUserMods.Select(i => i.Age).Any(i => i == o.Age)).ToListAsync();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public async Task Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = await _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupByAsync(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public async Task Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o=>o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o=>o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
[Fact]
public async Task Group_Recently_Test()
{
//var list =(from us in _virtualDbContext.Set<SysUserSalary>().Where(o => ids.Contains(o.UserId))
// group us by new
// {
// UserId=us.UserId
// }
// into g
// select new
// {
// UserId=g.Key.UserId,
// DateOfMonth = g.Max(o=>o.DateOfMonth)
// }).ToList();
//var y = list;
var ids = new List<string>() { "200", "300" };
List<SysUserSalary> result = new List<SysUserSalary>(ids.Count);
var routeFilter = new List<SysUserSalary>().AsQueryable().Where(o => ids.Contains(o.UserId));
var dataSourceRouteResult = new DataSourceRouteResult(new HashSet<string>() { _virtualDataSource.DefaultDataSourceName });
var tableRouteResults = _tableRouteRuleEngineFactory.Route(dataSourceRouteResult, routeFilter,new Dictionary<Type, IQueryable>(){{typeof(SysUserSalary),null}})
.RouteUnits
.Select(o => o.TableRouteResult.ReplaceTables.First().Tail).OrderByDescending(o => o).ToList();
foreach (var tableRouteResult in tableRouteResults)
{
if (ids.IsEmpty())
break;
using (_shardingRouteManager.CreateScope())
{
_shardingRouteManager.Current.TryCreateOrAddMustTail<SysUserSalary>(tableRouteResult);
var queryable = _virtualDbContext.Set<SysUserSalary>().Where(o => ids.Contains(o.UserId))
.GroupBy(o => new { o.UserId }, i => i,
(i, u) => new
{
Data = u.OrderByDescending(o => o.DateOfMonth).FirstOrDefault()
});
var r = await queryable.ToListAsync();
result.AddRange(r.Select(o => o.Data));
var removeUserIds = result.Select(u => u.UserId).ToHashSet();
ids.RemoveAll(o => removeUserIds.Contains(o));
}
}
}
}
}

View File

@ -1454,31 +1454,88 @@ namespace ShardingCore.Test
var sysUserModInts = _virtualDbContext.Set<SysUserModInt>().Where(o => sysUserMods.Select(i => i.Age).Any(i => i == o.Age)).ToList();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public void Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupBy(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public void Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
}
}

View File

@ -17,6 +17,7 @@ namespace ShardingCore.Test.Shardings
public class SysUserSalaryVirtualTableRoute:AbstractShardingOperatorVirtualTableRoute<SysUserSalary,int>
{
//public override bool? EnableRouteParseCompileCache => true;
protected override bool EnableHintRoute => true;
public override string ShardingKeyToTail(object shardingKey)
{

View File

@ -1681,31 +1681,88 @@ namespace ShardingCore.Test2x
var sysUserModInts = await _virtualDbContext.Set<SysUserModInt>().Where(o=>sysUserMods.Select(i=>i.Age).Any(i=>i==o.Age)).ToListAsync();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public async Task Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = await _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupByAsync(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public async Task Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o => o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o => o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
}
}

View File

@ -1454,31 +1454,88 @@ namespace ShardingCore.Test2x
var sysUserModInts = _virtualDbContext.Set<SysUserModInt>().Where(o => sysUserMods.Select(i => i.Age).Any(i => i == o.Age)).ToList();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public void Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupBy(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public void Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
}
}

View File

@ -1681,31 +1681,88 @@ namespace ShardingCore.Test3x
var sysUserModInts = await _virtualDbContext.Set<SysUserModInt>().Where(o=>sysUserMods.Select(i=>i.Age).Any(i=>i==o.Age)).ToListAsync();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public async Task Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = await _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupByAsync(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public async Task Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o => o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o => o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
}
}

View File

@ -1454,31 +1454,88 @@ namespace ShardingCore.Test3x
var sysUserModInts = _virtualDbContext.Set<SysUserModInt>().Where(o => sysUserMods.Select(i => i.Age).Any(i => i == o.Age)).ToList();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public void Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupBy(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public void Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
}
}

View File

@ -1681,31 +1681,88 @@ namespace ShardingCore.Test5x
var sysUserModInts = await _virtualDbContext.Set<SysUserModInt>().Where(o=>sysUserMods.Select(i=>i.Age).Any(i=>i==o.Age)).ToListAsync();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public async Task Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = await _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupByAsync(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public async Task Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o => o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public async Task Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = await _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o => o.TotalSalary).ToListAsync();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
}
}

View File

@ -1454,31 +1454,88 @@ namespace ShardingCore.Test5x
var sysUserModInts = _virtualDbContext.Set<SysUserModInt>().Where(o => sysUserMods.Select(i => i.Age).Any(i => i == o.Age)).ToList();
Assert.Equal(1000, sysUserModInts.Count);
}
// [Fact]
// public void Group_API_Test()
// {
// var ids = new[] {"200", "300"};
// var dateOfMonths = new[] {202111, 202110};
// var group = _virtualDbContext.Set<SysUserSalary>()
// .Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
// .ShardingGroupBy(g => new {UId = g.UserId}, g => new
// {
//
// GroupUserId = g.Key.UId,
// Count = g.Count(),
// TotalSalary = g.Sum(o => o.Salary),
// AvgSalary = g.Average(o => o.Salary),
// AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
// MinSalary = g.Min(o => o.Salary),
// MaxSalary = g.Max(o => o.Salary)
// });
// Assert.Equal(2, group.Count);
// Assert.Equal(2, group[0].Count);
// Assert.Equal(2260000, group[0].TotalSalary);
// Assert.Equal(1130000, group[0].AvgSalary);
// Assert.Equal(11300, group[0].AvgSalaryDecimal);
// Assert.Equal(1120000, group[0].MinSalary);
// Assert.Equal(1140000, group[0].MaxSalary);
// }
[Fact]
public void Group_API_Test()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test1()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderBy(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("200", group[0].GroupUserId);
Assert.Equal(2260000, group[0].TotalSalary);
Assert.Equal(1130000, group[0].AvgSalary);
Assert.Equal(11300, group[0].AvgSalaryDecimal);
Assert.Equal(1120000, group[0].MinSalary);
Assert.Equal(1140000, group[0].MaxSalary);
}
[Fact]
public void Group_API_Test2()
{
var ids = new[] { "200", "300" };
var dateOfMonths = new[] { 202111, 202110 };
var group = _virtualDbContext.Set<SysUserSalary>()
.Where(o => ids.Contains(o.UserId) && dateOfMonths.Contains(o.DateOfMonth))
.GroupBy(g => new { UId = g.UserId })
.Select(g => new
{
GroupUserId = g.Key.UId,
Count = g.Count(),
TotalSalary = g.Sum(o => o.Salary),
AvgSalary = g.Average(o => o.Salary),
AvgSalaryDecimal = g.Average(o => o.SalaryDecimal),
MinSalary = g.Min(o => o.Salary),
MaxSalary = g.Max(o => o.Salary)
}).OrderByDescending(o => o.TotalSalary).ToList();
Assert.Equal(2, group.Count);
Assert.Equal(2, group[0].Count);
Assert.Equal("300", group[0].GroupUserId);
Assert.Equal(2690000, group[0].TotalSalary);
Assert.Equal(1345000, group[0].AvgSalary);
Assert.Equal(13450, group[0].AvgSalaryDecimal);
Assert.Equal(1330000, group[0].MinSalary);
Assert.Equal(1360000, group[0].MaxSalary);
}
}
}