2017-01-28 21:56:15 +08:00
|
|
|
|
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.ExpressionTest
|
|
|
|
|
{
|
|
|
|
|
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++)
|
|
|
|
|
{
|
2017-01-30 18:53:06 +08:00
|
|
|
|
#region StringIsNullOrEmpty
|
2017-01-30 15:10:54 +08:00
|
|
|
|
StringIsNullOrEmpty();
|
2017-01-30 15:41:16 +08:00
|
|
|
|
StringIsNullOrEmpty2();
|
2017-01-30 16:42:33 +08:00
|
|
|
|
StringIsNullOrEmpty3();
|
2017-01-30 18:17:55 +08:00
|
|
|
|
StringIsNullOrEmpty4();
|
2017-01-30 18:53:06 +08:00
|
|
|
|
ToUpper();
|
2017-01-30 21:54:23 +08:00
|
|
|
|
ToLower();
|
2017-01-30 18:53:06 +08:00
|
|
|
|
#endregion
|
2017-01-28 21:56:15 +08:00
|
|
|
|
}
|
|
|
|
|
base.End("Method Test");
|
|
|
|
|
}
|
2017-01-30 18:53:06 +08:00
|
|
|
|
|
|
|
|
|
private void ToUpper()
|
2017-01-30 15:10:54 +08:00
|
|
|
|
{
|
2017-01-30 21:54:23 +08:00
|
|
|
|
Expression<Func<Student, bool>> exp = it =>"a"== NBORM.ToUpper(it.Id) ;
|
2017-01-30 15:10:54 +08:00
|
|
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
|
|
|
|
|
expContext.Resolve();
|
|
|
|
|
var value = expContext.Result.GetString();
|
|
|
|
|
var pars = expContext.Parameters;
|
2017-01-30 21:54:23 +08:00
|
|
|
|
base.Check(value, pars, "( @Const0 = (UPPER(Id)) )", new List<SugarParameter>() {
|
|
|
|
|
new SugarParameter("@Const0","a")
|
2017-01-30 18:55:50 +08:00
|
|
|
|
}, "ToUpper");
|
2017-01-30 15:41:16 +08:00
|
|
|
|
}
|
2017-01-30 21:54:23 +08:00
|
|
|
|
private void ToLower()
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<Student, bool>> exp = it => "a" == NBORM.ToLower(it.Id);
|
|
|
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
|
|
|
|
|
expContext.Resolve();
|
|
|
|
|
var value = expContext.Result.GetString();
|
|
|
|
|
var pars = expContext.Parameters;
|
|
|
|
|
base.Check(value, pars, "( @Const0 = (LOWER(Id)) )", new List<SugarParameter>() {
|
|
|
|
|
new SugarParameter("@Const0","a")
|
|
|
|
|
}, "ToLower");
|
|
|
|
|
}
|
2017-01-30 15:41:16 +08:00
|
|
|
|
|
2017-01-30 18:53:06 +08:00
|
|
|
|
#region StringIsNullOrEmpty
|
|
|
|
|
private void StringIsNullOrEmpty()
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<Student, bool>> exp = it => it.Id > 2 || NBORM.IsNullOrEmpty(it.Id); ;
|
|
|
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
|
|
|
|
|
expContext.Resolve();
|
|
|
|
|
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");
|
|
|
|
|
}
|
2017-01-30 15:41:16 +08:00
|
|
|
|
private void StringIsNullOrEmpty2()
|
|
|
|
|
{
|
2017-01-30 18:53:06 +08:00
|
|
|
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(true); ;
|
2017-01-30 15:41:16 +08:00
|
|
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
|
|
|
|
|
expContext.Resolve();
|
|
|
|
|
var value = expContext.Result.GetString();
|
|
|
|
|
var pars = expContext.Parameters;
|
2017-01-30 21:54:23 +08:00
|
|
|
|
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
|
|
|
|
new SugarParameter("@MethodConst1",true),
|
2017-01-30 15:41:16 +08:00
|
|
|
|
new SugarParameter("@Id0",2)
|
|
|
|
|
}, "StringIsNullOrEmpty2");
|
2017-01-30 15:10:54 +08:00
|
|
|
|
}
|
2017-01-30 16:42:33 +08:00
|
|
|
|
private void StringIsNullOrEmpty3()
|
|
|
|
|
{
|
|
|
|
|
int a = 1;
|
|
|
|
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(a); ;
|
|
|
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
|
|
|
|
|
expContext.Resolve();
|
|
|
|
|
var value = expContext.Result.GetString();
|
|
|
|
|
var pars = expContext.Parameters;
|
2017-01-30 21:54:23 +08:00
|
|
|
|
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
|
|
|
|
new SugarParameter("@MethodConst1",1),
|
2017-01-30 16:42:33 +08:00
|
|
|
|
new SugarParameter("@Id0",2)
|
|
|
|
|
}, "StringIsNullOrEmpty3");
|
|
|
|
|
}
|
2017-01-30 18:17:55 +08:00
|
|
|
|
private void StringIsNullOrEmpty4()
|
|
|
|
|
{
|
|
|
|
|
WhereConst.name = "xx";
|
|
|
|
|
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(WhereConst.name); ;
|
|
|
|
|
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
|
|
|
|
|
expContext.Resolve();
|
|
|
|
|
var value = expContext.Result.GetString();
|
|
|
|
|
var pars = expContext.Parameters;
|
2017-01-30 21:54:23 +08:00
|
|
|
|
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
|
|
|
|
|
new SugarParameter("@MethodConst1","xx"),
|
2017-01-30 18:17:55 +08:00
|
|
|
|
new SugarParameter("@Id0",2)
|
|
|
|
|
}, "StringIsNullOrEmpty4");
|
2017-01-30 18:53:06 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2017-01-28 21:56:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-30 15:41:16 +08:00
|
|
|
|
|