New Expression BUG

This commit is contained in:
sunkaixuan
2017-07-07 23:18:25 +08:00
parent 6386133359
commit e3ee431c91
8 changed files with 130 additions and 125 deletions

View File

@@ -18,6 +18,7 @@ namespace OrmTest
static void Main(string[] args)
{
// /***Unit Test***/
new Select(1).Init();
new Field(1).Init();
new Where(1).Init();
new Method(1).Init();

View File

@@ -33,15 +33,18 @@ namespace OrmTest.UnitTest
{
Expression<Func<Student, School, object>> exp = (it, school) => new Student() { Name = "a", Id = it.Id, SchoolId = school.Id, TestId = it.Id + 1 };
ExpressionContext expContext = new ExpressionContext();
expContext.IsSingle = false;
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(
selectorValue,
pars,
@" @constant1 AS Name , it.Id AS Id , school.Id AS SchoolId , ( it.Id + 1 ) AS TestId ",
@" @constant0 AS [Name] , [it].[Id] AS [Id] , [school].[Id] AS [SchoolId] , ( [it].[Id] + @Id1 ) AS [TestId] ",
new List<SugarParameter>(){
new SugarParameter("@constant1","a")},
new SugarParameter("@constant0","a"),
new SugarParameter("@Id1",1)
},
"Select.Multiple Error");
}
@@ -49,21 +52,23 @@ namespace OrmTest.UnitTest
{
Expression<Func<Student, School, object>> exp = (it, school) => new { Name = "a", Id = it.Id / 2, SchoolId = school.Id };
ExpressionContext expContext = new ExpressionContext();
expContext.IsSingle = false;
expContext.Resolve(exp, ResolveExpressType.SelectMultiple);
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(
selectorValue,
pars,
@" @constant1 AS Name , ( it.Id / 2 ) AS Id , school.Id AS SchoolId ",
@" @constant0 AS [Name] , ( [it].[Id] / @Id1 ) AS [Id] , [school].[Id] AS [SchoolId] ",
new List<SugarParameter>(){
new SugarParameter("@constant1","a")},
new SugarParameter("@constant0","a"),
new SugarParameter("@Id1", 2)},
"Select.MultipleDynamic Error");
}
private void single()
{
int p = 1;
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id = it.Id, SchoolId = p,TestId=it.Id+1 };
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id = it.Id, SchoolId = p,TestId=it.Id+11 };
ExpressionContext expContext = new ExpressionContext();
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
var selectorValue = expContext.Result.GetString();
@@ -71,17 +76,18 @@ namespace OrmTest.UnitTest
base.Check(
selectorValue,
pars,
@" @constant1 AS Name , Id AS Id , @constant3 AS SchoolId , ( Id + 1 ) AS TestId ",
@" @constant0 AS [Name] , [Id] AS [Id] , @constant1 AS [SchoolId] , ( [Id] + @Id2 ) AS [TestId] ",
new List<SugarParameter>(){
new SugarParameter("@constant1","a"),
new SugarParameter("@constant3",1)},
new SugarParameter("@constant0","a"),
new SugarParameter("@constant1",1),
new SugarParameter("@Id2",11 ) },
"Select.single Error");
}
private void singleDynamic()
{
string a = "a";
Expression<Func<Student, object>> exp = it => new { x = it.Id, shoolid = 1, name = a,p=it.Id*1 };
Expression<Func<Student, object>> exp = it => new { x = it.Id, shoolid = 1, name = a,p=it.Id*2 };
ExpressionContext expContext = new ExpressionContext();
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
var selectorValue = expContext.Result.GetString();
@@ -89,11 +95,12 @@ namespace OrmTest.UnitTest
base.Check(
selectorValue,
pars,
@" Id AS x , @constant2 AS shoolid , @constant3 AS name , ( Id * 1 ) AS p ",
@" [Id] AS [x] , @constant0 AS [shoolid] , @constant1 AS [name] , ( [Id] * @Id2 ) AS [p] ",
new List<SugarParameter>(){
new SugarParameter("@constant2",1),
new SugarParameter("@constant3","a")},
"Select.single Error");
new SugarParameter("@constant0",1),
new SugarParameter("@constant1","a"),
new SugarParameter("@Id2",2)},
"Select.singleDynamic Error");
}
}
}