30 changed files with 1164 additions and 49 deletions
@ -0,0 +1,19 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
<RootNamespace /> |
|||
<IsPackable>false</IsPackable> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\modules\dynamic-queryable\LINGYUN.Linq.Dynamic.Queryable\LINGYUN.Linq.Dynamic.Queryable.csproj" /> |
|||
<ProjectReference Include="..\LINGYUN.Abp.EntityFrameworkCore.Tests\LINGYUN.Abp.EntityFrameworkCore.Tests.csproj" /> |
|||
<ProjectReference Include="..\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,4 @@ |
|||
namespace LINGYUN.Abp.DynamicQueryable.EntityFrameworkCore; |
|||
public abstract class AbpDynamicQueryableEntityFrameworkCoreTestBase : AbpTestsBase<AbpDynamicQueryableEntityFrameworkCoreTestModule> |
|||
{ |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace LINGYUN.Abp.DynamicQueryable.EntityFrameworkCore; |
|||
|
|||
[DependsOn(typeof(AbpEntityFrameworkCoreTestModule))] |
|||
public class AbpDynamicQueryableEntityFrameworkCoreTestModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,302 @@ |
|||
using LINGYUN.Abp.EntityFrameworkCore; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using ExecDynamicQueryable = LINGYUN.Linq.Dynamic.Queryable.DynamicQueryable; |
|||
|
|||
namespace LINGYUN.Abp.DynamicQueryable.EntityFrameworkCore; |
|||
|
|||
public class DynamicQueryableEntityFrameworkCoreTests : AbpDynamicQueryableEntityFrameworkCoreTestBase |
|||
{ |
|||
[Fact] |
|||
public void Should_Null() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.Null, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Null() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotNull, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Equal() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.Equal, |
|||
Field = nameof(EfCoreTestEntity.PropInt32), |
|||
Logic = DynamicLogic.And, |
|||
Value = 2048 |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Equal() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotEqual, |
|||
Field = nameof(EfCoreTestEntity.PropInt32), |
|||
Logic = DynamicLogic.And, |
|||
Value = null |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Less_Than() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.LessThan, |
|||
Field = nameof(EfCoreTestEntity.PropInt32), |
|||
Logic = DynamicLogic.And, |
|||
Value = 2048 |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Less_Than_Or_Equal() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.LessThanOrEqual, |
|||
Field = nameof(EfCoreTestEntity.PropInt32), |
|||
Logic = DynamicLogic.And, |
|||
Value = 2048 |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Greater_Than() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.GreaterThan, |
|||
Field = nameof(EfCoreTestEntity.PropInt64), |
|||
Logic = DynamicLogic.And, |
|||
Value = 1024L |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Greater_Than_Or_Equal() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.GreaterThanOrEqual, |
|||
Field = nameof(EfCoreTestEntity.PropInt64), |
|||
Logic = DynamicLogic.And, |
|||
Value = 1024L |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(3); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Starts_With() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.StartsWith, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And, |
|||
Value = "1" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Starts_With() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotStartsWith, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And, |
|||
Value = "1" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(3); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Ends_With() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.EndsWith, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And, |
|||
Value = "1" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Ends_With() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotEndsWith, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And, |
|||
Value = "1" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(3); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Contains() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.Contains, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And, |
|||
Value = "22" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Contains() |
|||
{ |
|||
using var dbContext = GetRequiredService<EfCoreTestDbContext>(); |
|||
Expression<Func<EfCoreTestEntity, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new ExecDynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotContains, |
|||
Field = nameof(EfCoreTestEntity.PropString), |
|||
Logic = DynamicLogic.And, |
|||
Value = "23" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = dbContext.TestEntities.Local.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(3); |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
global using Xunit; |
|||
global using Shouldly; |
|||
global using LINGYUN.Abp.EntityFrameworkCore.Tests; |
|||
global using LINGYUN.Abp.Tests; |
|||
global using LINGYUN.Linq.Dynamic.Queryable; |
|||
@ -0,0 +1,24 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore.Modeling; |
|||
|
|||
namespace LINGYUN.Abp.EntityFrameworkCore; |
|||
public class EfCoreTestDbContext : AbpDbContext<EfCoreTestDbContext> |
|||
{ |
|||
public virtual DbSet<EfCoreTestEntity> TestEntities { get; set; } |
|||
|
|||
public EfCoreTestDbContext( |
|||
DbContextOptions<EfCoreTestDbContext> options) : base(options) |
|||
{ |
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder modelBuilder) |
|||
{ |
|||
base.OnModelCreating(modelBuilder); |
|||
|
|||
modelBuilder.Entity<EfCoreTestEntity>(b => |
|||
{ |
|||
b.ConfigureByConvention(); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.Abp.EntityFrameworkCore; |
|||
|
|||
public class EfCoreTestEntity : Entity<Guid> |
|||
{ |
|||
public virtual string PropString { get; set; } |
|||
public virtual int? PropInt32 { get; set; } |
|||
public virtual long? PropInt64 { get; set; } |
|||
public virtual DateTime? DateTime { get; set; } |
|||
public EfCoreTestEntity( |
|||
Guid id, |
|||
string propString = null, |
|||
int? propInt32 = null, |
|||
long? propInt64 = null, |
|||
DateTime? dateTime = null) |
|||
: base(id) |
|||
{ |
|||
PropString = propString; |
|||
PropInt32 = propInt32; |
|||
PropInt64 = propInt64; |
|||
DateTime = dateTime; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Storage; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.EntityFrameworkCore; |
|||
public class EfCoreTestEntityDataSeeder |
|||
{ |
|||
private readonly EfCoreTestDbContext _dbContext; |
|||
|
|||
public EfCoreTestEntityDataSeeder( |
|||
EfCoreTestDbContext dbContext) |
|||
{ |
|||
_dbContext = dbContext; |
|||
} |
|||
|
|||
public async virtual Task SeedAsync() |
|||
{ |
|||
//_dbContext.GetService<IRelationalDatabaseCreator>().CreateTables();
|
|||
|
|||
await _dbContext.TestEntities.AddAsync( |
|||
new EfCoreTestEntity(Guid.NewGuid(), "1223", 1024, 1024L, new DateTime(2021, 10, 1, 0, 0, 0))); |
|||
|
|||
await _dbContext.TestEntities.AddAsync( |
|||
new EfCoreTestEntity(Guid.NewGuid(), null, 2048, 2048L, new DateTime(2022, 10, 1, 12, 0, 0))); |
|||
|
|||
await _dbContext.TestEntities.AddAsync( |
|||
new EfCoreTestEntity(Guid.NewGuid(), "3221", null, 4096L, null)); |
|||
|
|||
await _dbContext.TestEntities.AddAsync( |
|||
new EfCoreTestEntity(Guid.NewGuid(), null, null, null, new DateTime(2022, 1, 1, 12, 0, 0))); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
<RootNamespace /> |
|||
<IsPackable>false</IsPackable> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\modules\dynamic-queryable\LINGYUN.Linq.Dynamic.Queryable\LINGYUN.Linq.Dynamic.Queryable.csproj" /> |
|||
<ProjectReference Include="..\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,5 @@ |
|||
namespace LINGYUN.Linq.Dynamic.Queryable; |
|||
|
|||
public abstract class DynamicQueryableTestBase : AbpTestsBase<DynamicQueryableTestModule> |
|||
{ |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace LINGYUN.Linq.Dynamic.Queryable; |
|||
|
|||
[DependsOn(typeof(AbpTestsBaseModule))] |
|||
public class DynamicQueryableTestModule : AbpModule |
|||
{ |
|||
} |
|||
@ -0,0 +1,337 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Linq.Dynamic.Queryable; |
|||
|
|||
public class LinqTestClass |
|||
{ |
|||
public string StringNull { get; set; } |
|||
public string StringRequired { get; set; } |
|||
public long? Int64Null { get; set; } |
|||
public long Int64Required { get; set; } |
|||
public DateTime? DateTimeNull { get; set; } |
|||
public DateTime DateTimeRequired { get; set; } |
|||
public DateOnly? DateOnlyNull { get; set; } |
|||
public DateOnly DateOnlyRequired { get; set; } |
|||
public TimeOnly? TimeOnlyNull { get; set; } |
|||
public TimeOnly TimeOnlyRequired { get; set; } |
|||
} |
|||
|
|||
public class DynamicQueryableTests : DynamicQueryableTestBase |
|||
{ |
|||
private readonly static List<LinqTestClass> _testClasses; |
|||
static DynamicQueryableTests() |
|||
{ |
|||
_testClasses = new List<LinqTestClass> |
|||
{ |
|||
new LinqTestClass |
|||
{ |
|||
StringNull = null, |
|||
StringRequired = "3211", |
|||
DateOnlyNull = new DateOnly(2022, 1, 1), |
|||
DateOnlyRequired = new DateOnly(2022, 10, 1), |
|||
TimeOnlyNull = null, |
|||
TimeOnlyRequired = new TimeOnly(12, 0, 0), |
|||
DateTimeNull = new DateTime(2021, 1, 1, 0, 0, 0), |
|||
DateTimeRequired = new DateTime(2022, 10, 1, 12, 0, 0), |
|||
Int64Null = null, |
|||
Int64Required = 1024L |
|||
}, |
|||
new LinqTestClass |
|||
{ |
|||
StringNull = "not null", |
|||
StringRequired = "1123", |
|||
DateOnlyNull = null, |
|||
DateOnlyRequired = new DateOnly(2021, 10, 1), |
|||
TimeOnlyNull = new TimeOnly(0, 0, 0), |
|||
TimeOnlyRequired = new TimeOnly(1, 0, 0), |
|||
DateTimeNull = null, |
|||
DateTimeRequired = new DateTime(2021, 1, 1, 0, 0, 0), |
|||
Int64Null = null, |
|||
Int64Required = 2048L |
|||
}, |
|||
}; |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Null() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.Null, |
|||
Field = nameof(LinqTestClass.Int64Null), |
|||
Logic = DynamicLogic.And |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Null() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotNull, |
|||
Field = nameof(LinqTestClass.StringNull), |
|||
Logic = DynamicLogic.And |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Equal() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.Equal, |
|||
Field = nameof(LinqTestClass.StringRequired), |
|||
Logic = DynamicLogic.And, |
|||
Value = "1123" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Equal() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotEqual, |
|||
Field = nameof(LinqTestClass.StringRequired), |
|||
Logic = DynamicLogic.And, |
|||
Value = "1123" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Less_Than() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.LessThan, |
|||
Field = nameof(LinqTestClass.Int64Required), |
|||
Logic = DynamicLogic.And, |
|||
Value = 2048L |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Less_Than_Or_Equal() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.LessThanOrEqual, |
|||
Field = nameof(LinqTestClass.Int64Required), |
|||
Logic = DynamicLogic.And, |
|||
Value = 2048L |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Greater_Than() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.GreaterThan, |
|||
Field = nameof(LinqTestClass.Int64Null), |
|||
Logic = DynamicLogic.And, |
|||
Value = 1024L |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(0); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Greater_Than_Or_Equal() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.GreaterThanOrEqual, |
|||
Field = nameof(LinqTestClass.Int64Required), |
|||
Logic = DynamicLogic.And, |
|||
Value = 1024L |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Starts_With() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.StartsWith, |
|||
Field = nameof(LinqTestClass.StringNull), |
|||
Logic = DynamicLogic.And, |
|||
Value = "not" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Starts_With() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotStartsWith, |
|||
Field = nameof(LinqTestClass.StringNull), |
|||
Logic = DynamicLogic.And, |
|||
Value = "not" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Ends_With() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.EndsWith, |
|||
Field = nameof(LinqTestClass.StringNull), |
|||
Logic = DynamicLogic.And, |
|||
Value = "null" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Ends_With() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotEndsWith, |
|||
Field = nameof(LinqTestClass.StringNull), |
|||
Logic = DynamicLogic.And, |
|||
Value = "null" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Contains() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.Contains, |
|||
Field = nameof(LinqTestClass.StringNull), |
|||
Logic = DynamicLogic.And, |
|||
Value = "null" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Not_Contains() |
|||
{ |
|||
Expression<Func<LinqTestClass, bool>> exp = (_) => true; |
|||
|
|||
var dynamicQueryable = new DynamicQueryable(); |
|||
dynamicQueryable.Paramters.Add(new DynamicParamter |
|||
{ |
|||
Comparison = DynamicComparison.NotContains, |
|||
Field = nameof(LinqTestClass.StringNull), |
|||
Logic = DynamicLogic.And, |
|||
Value = "test" |
|||
}); |
|||
|
|||
exp = exp.DynamicQuery(dynamicQueryable); |
|||
|
|||
var result = _testClasses.Where(exp.Compile()).ToList(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
global using Xunit; |
|||
global using Shouldly; |
|||
global using LINGYUN.Abp.Tests; |
|||
global using LINGYUN.Linq.Dynamic.Queryable; |
|||
Loading…
Reference in new issue