mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 完善 ExpressionTree DateTime/DateTimeOffset 数据转换测试;
This commit is contained in:
@ -418,6 +418,34 @@ namespace FreeSql.ExpressionTree
|
||||
Assert.Null(Utils.GetDataReaderValue(typeof(DateTime?), "aaa"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DateTime2_By_DateTimeOffset()
|
||||
{
|
||||
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime), Expression.Constant(DateTimeOffset.MinValue));
|
||||
Assert.Equal(DateTime.MinValue, Utils.GetDataReaderValue(typeof(DateTime), DateTimeOffset.MinValue));
|
||||
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime), Expression.Constant(DateTimeOffset.MaxValue));
|
||||
Assert.Equal(DateTime.MaxValue, Utils.GetDataReaderValue(typeof(DateTime), DateTimeOffset.MaxValue));
|
||||
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime), Expression.Constant("2000-1-1"));
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), Utils.GetDataReaderValue(typeof(DateTime), "2000-1-1"));
|
||||
|
||||
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime?), Expression.Constant(DateTimeOffset.MinValue));
|
||||
Assert.Equal(DateTime.MinValue, Utils.GetDataReaderValue(typeof(DateTime?), DateTimeOffset.MinValue));
|
||||
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime?), Expression.Constant(DateTimeOffset.MaxValue));
|
||||
Assert.Equal(DateTime.MaxValue, Utils.GetDataReaderValue(typeof(DateTime?), DateTimeOffset.MaxValue));
|
||||
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime?), Expression.Constant("2000-1-1"));
|
||||
Assert.Equal(DateTime.Parse("2000-1-1"), Utils.GetDataReaderValue(typeof(DateTime?), "2000-1-1"));
|
||||
|
||||
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime), Expression.Constant(null));
|
||||
Assert.Equal(default(DateTime), Utils.GetDataReaderValue(typeof(DateTime), null));
|
||||
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime), Expression.Constant("aaa"));
|
||||
Assert.Equal(default(DateTime), Utils.GetDataReaderValue(typeof(DateTime), "aaa"));
|
||||
|
||||
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime?), Expression.Constant(null));
|
||||
Assert.Null(Utils.GetDataReaderValue(typeof(DateTime?), null));
|
||||
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(DateTime?), Expression.Constant("aaa"));
|
||||
Assert.Null(Utils.GetDataReaderValue(typeof(DateTime?), "aaa"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DateTimeOffset2()
|
||||
{
|
||||
@ -445,5 +473,33 @@ namespace FreeSql.ExpressionTree
|
||||
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset?), Expression.Constant("aaa"));
|
||||
Assert.Null(Utils.GetDataReaderValue(typeof(DateTimeOffset?), "aaa"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DateTimeOffset2_By_DateTime()
|
||||
{
|
||||
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset), Expression.Constant(DateTime.MinValue));
|
||||
Assert.Equal(DateTimeOffset.MinValue, Utils.GetDataReaderValue(typeof(DateTimeOffset), DateTime.MinValue));
|
||||
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset), Expression.Constant(DateTime.MaxValue));
|
||||
Assert.Equal(DateTimeOffset.MaxValue, Utils.GetDataReaderValue(typeof(DateTimeOffset), DateTime.MaxValue));
|
||||
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset), Expression.Constant("2000-1-1"));
|
||||
Assert.Equal(DateTimeOffset.Parse("2000-1-1"), Utils.GetDataReaderValue(typeof(DateTimeOffset), "2000-1-1"));
|
||||
|
||||
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset?), Expression.Constant(DateTime.MinValue));
|
||||
Assert.Equal(DateTimeOffset.MinValue, Utils.GetDataReaderValue(typeof(DateTimeOffset?), DateTime.MinValue));
|
||||
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset?), Expression.Constant(DateTime.MaxValue));
|
||||
Assert.Equal(DateTimeOffset.MaxValue, Utils.GetDataReaderValue(typeof(DateTimeOffset?), DateTime.MaxValue));
|
||||
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset?), Expression.Constant("2000-1-1"));
|
||||
Assert.Equal(DateTimeOffset.Parse("2000-1-1"), Utils.GetDataReaderValue(typeof(DateTimeOffset?), "2000-1-1"));
|
||||
|
||||
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset), Expression.Constant(null));
|
||||
Assert.Equal(default(DateTimeOffset), Utils.GetDataReaderValue(typeof(DateTimeOffset), null));
|
||||
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset), Expression.Constant("aaa"));
|
||||
Assert.Equal(default(DateTimeOffset), Utils.GetDataReaderValue(typeof(DateTimeOffset), "aaa"));
|
||||
|
||||
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset?), Expression.Constant(null));
|
||||
Assert.Null(Utils.GetDataReaderValue(typeof(DateTimeOffset?), null));
|
||||
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(DateTimeOffset?), Expression.Constant("aaa"));
|
||||
Assert.Null(Utils.GetDataReaderValue(typeof(DateTimeOffset?), "aaa"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace FreeSql.Tests.MySqlMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.mysql;
|
||||
var item = new DateTimeOffSetTestMap { dtos_to_dt = DateTimeOffset.Now, dtosnullable_to_dt = DateTimeOffset.Now };
|
||||
var item = new DateTimeOffSetTestMap { dtos_to_dt = DateTimeOffset.Now };
|
||||
Assert.Equal(1, orm.Insert<DateTimeOffSetTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
@ -38,6 +38,14 @@ namespace FreeSql.Tests.MySqlMapType
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
|
||||
|
||||
item.dtosnullable_to_dt = DateTimeOffset.Now;
|
||||
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g"));
|
||||
Assert.Equal(item.dtosnullable_to_dt.Value.ToString("g"), find.dtosnullable_to_dt.Value.ToString("g"));
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<DateTimeOffSetTestMap>().Where(a => a.id == item.id).Set(a => a.dtos_to_dt, item.dtos_to_dt = DateTimeOffset.Now).ExecuteAffrows());
|
||||
find = orm.Select<DateTimeOffSetTestMap>().Where(a => a.id == item.id).First();
|
||||
|
Reference in New Issue
Block a user