You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
5.9 KiB
138 lines
5.9 KiB
using OrmTest.Models;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OrmTest.UnitTest
|
|
{
|
|
public class Method : ExpTestBase
|
|
{
|
|
private Method() { }
|
|
public Method(int eachCount)
|
|
{
|
|
this.Count = eachCount;
|
|
}
|
|
internal void Init()
|
|
{
|
|
base.Begin();
|
|
for (int i = 0; i < base.Count; i++)
|
|
{
|
|
#region StringIsNullOrEmpty
|
|
StringIsNullOrEmpty();
|
|
StringIsNullOrEmpty2();
|
|
StringIsNullOrEmpty3();
|
|
StringIsNullOrEmpty4();
|
|
ToUpper();
|
|
ToLower();
|
|
Trim();
|
|
Contains();
|
|
#endregion
|
|
}
|
|
base.End("Method Test");
|
|
}
|
|
|
|
private void Contains()
|
|
{
|
|
Expression<Func<Student, bool>> exp = it => NBORM.Contains(it.Name,"a");
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, " ([Name] like '%'+@MethodConst0+'%') ", new List<SugarParameter>() {
|
|
new SugarParameter("@MethodConst0","a")
|
|
}, "Contains");
|
|
}
|
|
|
|
private void Trim()
|
|
{
|
|
Expression<Func<Student, bool>> exp = it =>NBORM.Trim(" a")==it.Name;
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, "((rtrim(ltrim(@MethodConst0))) = [Name] )", new List<SugarParameter>() {
|
|
new SugarParameter("@MethodConst0"," a")
|
|
}, "Trim");
|
|
}
|
|
|
|
private void ToUpper()
|
|
{
|
|
Expression<Func<Student, bool>> exp = it =>"a"== NBORM.ToUpper(it.Id) ;
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, "( @Const0 = (UPPER([Id])) )", new List<SugarParameter>() {
|
|
new SugarParameter("@Const0","a")
|
|
}, "ToUpper");
|
|
}
|
|
private void ToLower()
|
|
{
|
|
Expression<Func<Student, bool>> exp = it => "a" == NBORM.ToLower(it.Id);
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, "( @Const0 = (LOWER([Id])) )", new List<SugarParameter>() {
|
|
new SugarParameter("@Const0","a")
|
|
}, "ToLower");
|
|
}
|
|
|
|
#region StringIsNullOrEmpty
|
|
private void StringIsNullOrEmpty()
|
|
{
|
|
Expression<Func<Student, bool>> exp = it => it.Id > 2 || NBORM.IsNullOrEmpty(it.Id); ;
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, "(( [Id] > @Id0 ) OR ( [Id]='' OR [Id] IS NULL ))", new List<SugarParameter>() {
|
|
new SugarParameter("@Id0",2)
|
|
}, "StringIsNullOrEmpty");
|
|
}
|
|
private void StringIsNullOrEmpty2()
|
|
{
|
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(true); ;
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
|
new SugarParameter("@MethodConst1",true),
|
|
new SugarParameter("@Id0",2)
|
|
}, "StringIsNullOrEmpty2");
|
|
}
|
|
private void StringIsNullOrEmpty3()
|
|
{
|
|
int a = 1;
|
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(a); ;
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
|
new SugarParameter("@MethodConst1",1),
|
|
new SugarParameter("@Id0",2)
|
|
}, "StringIsNullOrEmpty3");
|
|
}
|
|
private void StringIsNullOrEmpty4()
|
|
{
|
|
WhereConst.name = "xx";
|
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(WhereConst.name); ;
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
|
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
|
var value = expContext.Result.GetString();
|
|
var pars = expContext.Parameters;
|
|
base.Check(value, pars, "(( @Id0 = [Id] ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
|
new SugarParameter("@MethodConst1","xx"),
|
|
new SugarParameter("@Id0",2)
|
|
}, "StringIsNullOrEmpty4");
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|