mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
add \0 string test
This commit is contained in:
parent
79ebc184ef
commit
e9949b58ff
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,12 +10,32 @@ namespace FreeSql.Tests.GBase
|
|||||||
{
|
{
|
||||||
public class GBaseCodeFirstTest
|
public class GBaseCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.gbase;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
var fsql = g.gbase;
|
var fsql = g.gbase;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -38,8 +58,8 @@ namespace FreeSql.Tests.GBase
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_StringLength_1()
|
public void Text_StringLength_1()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var str2 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人啊"));
|
var str2 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人啊"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT02 { Data = str1, Data2 = str2 };
|
var item1 = new TS_TEXT02 { Data = str1, Data2 = str2 };
|
||||||
Assert.Equal(1, g.gbase.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.gbase.Insert(item1).ExecuteAffrows());
|
||||||
@ -71,7 +91,7 @@ namespace FreeSql.Tests.GBase
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -116,57 +136,57 @@ namespace FreeSql.Tests.GBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.gbase.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.gbase.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.gbase.CodeFirst.SyncStructure<测试中文表>();
|
g.gbase.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.gbase.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.gbase.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.gbase.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.gbase.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.gbase.GetRepository<测试中文表>();
|
var repo = g.gbase.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.gbase.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -182,7 +202,7 @@ namespace FreeSql.Tests.GBase
|
|||||||
class AddUniquesInfo
|
class AddUniquesInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编号
|
/// 编号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid id { get; set; }
|
public Guid id { get; set; }
|
||||||
public string phone { get; set; }
|
public string phone { get; set; }
|
||||||
@ -239,7 +259,7 @@ namespace FreeSql.Tests.GBase
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -260,7 +280,7 @@ namespace FreeSql.Tests.GBase
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue + 1,
|
ShortNullable = short.MinValue + 1,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
UInt = uint.MaxValue,
|
UInt = uint.MaxValue,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -11,12 +11,32 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
{
|
{
|
||||||
public class MySqlCodeFirstTest
|
public class MySqlCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
var fsql = g.mysql;
|
var fsql = g.mysql;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -126,7 +146,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_StringLength_1()
|
public void Text_StringLength_1()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT02 { Data = str1 };
|
var item1 = new TS_TEXT02 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -148,7 +168,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text()
|
public void Text()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT01 { Data = str1 };
|
var item1 = new TS_TEXT01 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -170,7 +190,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_StringLength_2()
|
public void Text_StringLength_2()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT04 { Data = str1 };
|
var item1 = new TS_TEXT04 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -192,7 +212,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void LongText()
|
public void LongText()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT03 { Data = str1 };
|
var item1 = new TS_TEXT03 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -214,7 +234,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -260,7 +280,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 表名中有点()
|
public void 表名中有点()
|
||||||
{
|
{
|
||||||
var item = new tbdot01 { name = "insert" };
|
var item = new tbdot01 { name = "insert" };
|
||||||
g.mysql.Insert(item).ExecuteAffrows();
|
g.mysql.Insert(item).ExecuteAffrows();
|
||||||
@ -288,61 +308,61 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<测试中文表2>();
|
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<测试中文表2>();
|
||||||
g.mysql.CodeFirst.SyncStructure<测试中文表2>();
|
g.mysql.CodeFirst.SyncStructure<测试中文表2>();
|
||||||
|
|
||||||
var item = new 测试中文表2
|
var item = new 测试中文表2
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.mysql.Insert<测试中文表2>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert<测试中文表2>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
g.mysql.Update<测试中文表2>().SetSource(item2).ExecuteAffrows();
|
g.mysql.Update<测试中文表2>().SetSource(item2).ExecuteAffrows();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.mysql.Update<测试中文表2>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Update<测试中文表2>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.mysql.GetRepository<测试中文表2>();
|
var repo = g.mysql.GetRepository<测试中文表2>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表2
|
class 测试中文表2
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -394,7 +414,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
{
|
{
|
||||||
|
|
||||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
sql = g.mysql.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
sql = g.mysql.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +435,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
testFieldBoolNullable = true,
|
testFieldBoolNullable = true,
|
||||||
testFieldByte = 255,
|
testFieldByte = 255,
|
||||||
testFieldByteNullable = 127,
|
testFieldByteNullable = 127,
|
||||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
testFieldDateTime = DateTime.Now,
|
testFieldDateTime = DateTime.Now,
|
||||||
testFieldDateTimeNullable = DateTime.Now.AddHours(-1),
|
testFieldDateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
testFieldDecimal = 99.99M,
|
testFieldDecimal = 99.99M,
|
||||||
@ -459,7 +479,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
testFieldSByteNullable = 99,
|
testFieldSByteNullable = 99,
|
||||||
testFieldShort = short.MaxValue,
|
testFieldShort = short.MaxValue,
|
||||||
testFieldShortNullable = short.MinValue,
|
testFieldShortNullable = short.MinValue,
|
||||||
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
testFieldChar = 'X',
|
testFieldChar = 'X',
|
||||||
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
||||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
|
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
@ -675,7 +695,7 @@ namespace FreeSql.Tests.MySqlConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
/// 保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,6 +10,26 @@ namespace FreeSql.Tests.Odbc.Dameng
|
|||||||
{
|
{
|
||||||
public class DamengCodeFirstTest
|
public class DamengCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.dameng;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void StringLength()
|
public void StringLength()
|
||||||
{
|
{
|
||||||
@ -27,106 +47,106 @@ namespace FreeSql.Tests.Odbc.Dameng
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 数字表_字段()
|
public void 数字表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
||||||
g.dameng.CodeFirst.SyncStructure<测试数字表>();
|
g.dameng.CodeFirst.SyncStructure<测试数字表>();
|
||||||
|
|
||||||
var item = new 测试数字表
|
var item = new 测试数字表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.dameng.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.dameng.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.dameng.GetRepository<测试数字表>();
|
var repo = g.dameng.GetRepository<测试数字表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
[Table(Name = "123测试数字表")]
|
[Table(Name = "123测试数字表")]
|
||||||
class 测试数字表
|
class 测试数字表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true, Name = "123编号")]
|
[Column(IsPrimary = true, Name = "123编号")]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123标题")]
|
[Column(Name = "123标题")]
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123创建时间")]
|
[Column(Name = "123创建时间")]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.dameng.CodeFirst.SyncStructure<测试中文表>();
|
g.dameng.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.dameng.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.dameng.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.dameng.GetRepository<测试中文表>();
|
var repo = g.dameng.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -179,7 +199,7 @@ namespace FreeSql.Tests.Odbc.Dameng
|
|||||||
{
|
{
|
||||||
|
|
||||||
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
//sql = g.dameng.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
//sql = g.dameng.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +220,7 @@ namespace FreeSql.Tests.Odbc.Dameng
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -221,7 +241,7 @@ namespace FreeSql.Tests.Odbc.Dameng
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue,
|
ShortNullable = short.MinValue,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
Char = 'X',
|
Char = 'X',
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -12,6 +12,26 @@ namespace FreeSql.Tests.Odbc.Default
|
|||||||
public class OdbcCodeFirstTest
|
public class OdbcCodeFirstTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.odbc;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,6 +10,26 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
{
|
{
|
||||||
public class MySqlCodeFirstTest
|
public class MySqlCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void EnumStartValue1()
|
public void EnumStartValue1()
|
||||||
{
|
{
|
||||||
@ -106,7 +126,7 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 表名中有点()
|
public void 表名中有点()
|
||||||
{
|
{
|
||||||
var item = new tbdot01 { name = "insert" };
|
var item = new tbdot01 { name = "insert" };
|
||||||
g.mysql.Insert(item).ExecuteAffrows();
|
g.mysql.Insert(item).ExecuteAffrows();
|
||||||
@ -134,53 +154,53 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<测试中文表2>();
|
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<测试中文表2>();
|
||||||
g.mysql.CodeFirst.SyncStructure<测试中文表2>();
|
g.mysql.CodeFirst.SyncStructure<测试中文表2>();
|
||||||
|
|
||||||
var item = new 测试中文表2
|
var item = new 测试中文表2
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.mysql.Insert<测试中文表2>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert<测试中文表2>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.mysql.Update<测试中文表2>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Update<测试中文表2>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.mysql.GetRepository<测试中文表2>();
|
var repo = g.mysql.GetRepository<测试中文表2>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表2
|
class 测试中文表2
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -232,7 +252,7 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
{
|
{
|
||||||
|
|
||||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
sql = g.mysql.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
sql = g.mysql.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +273,7 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
testFieldBoolNullable = true,
|
testFieldBoolNullable = true,
|
||||||
testFieldByte = 255,
|
testFieldByte = 255,
|
||||||
testFieldByteNullable = 127,
|
testFieldByteNullable = 127,
|
||||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
testFieldDateTime = DateTime.Now,
|
testFieldDateTime = DateTime.Now,
|
||||||
testFieldDateTimeNullable = DateTime.Now.AddHours(-1),
|
testFieldDateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
testFieldDecimal = 99.99M,
|
testFieldDecimal = 99.99M,
|
||||||
@ -274,7 +294,7 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
testFieldSByteNullable = 99,
|
testFieldSByteNullable = 99,
|
||||||
testFieldShort = short.MaxValue,
|
testFieldShort = short.MaxValue,
|
||||||
testFieldShortNullable = short.MinValue,
|
testFieldShortNullable = short.MinValue,
|
||||||
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
testFieldChar = 'X',
|
testFieldChar = 'X',
|
||||||
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
||||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
|
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
@ -472,7 +492,7 @@ namespace FreeSql.Tests.Odbc.MySql
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
/// 保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,6 +10,26 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
{
|
{
|
||||||
public class OracleCodeFirstTest
|
public class OracleCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.oracle;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void StringLength()
|
public void StringLength()
|
||||||
{
|
{
|
||||||
@ -27,106 +47,106 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 数字表_字段()
|
public void 数字表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
||||||
g.oracle.CodeFirst.SyncStructure<测试数字表>();
|
g.oracle.CodeFirst.SyncStructure<测试数字表>();
|
||||||
|
|
||||||
var item = new 测试数字表
|
var item = new 测试数字表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.oracle.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.oracle.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.oracle.GetRepository<测试数字表>();
|
var repo = g.oracle.GetRepository<测试数字表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
[Table(Name = "123tb")]
|
[Table(Name = "123tb")]
|
||||||
class 测试数字表
|
class 测试数字表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true, Name = "123id")]
|
[Column(IsPrimary = true, Name = "123id")]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123title")]
|
[Column(Name = "123title")]
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123time")]
|
[Column(Name = "123time")]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.oracle.CodeFirst.SyncStructure<测试中文表>();
|
g.oracle.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.oracle.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.oracle.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.oracle.GetRepository<测试中文表>();
|
var repo = g.oracle.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -177,7 +197,7 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
public void GetComparisonDDLStatements()
|
public void GetComparisonDDLStatements()
|
||||||
{
|
{
|
||||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
//sql = g.oracle.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
//sql = g.oracle.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +210,7 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
var item = new TableAllType { };
|
var item = new TableAllType { };
|
||||||
for (var a = 0; a < 100; a++)
|
for (var a = 0; a < 100; a++)
|
||||||
{
|
{
|
||||||
try //ERROR [23000] [Oracle][ODBC][Ora]ORA-00001: 违反唯一约束条件 (1ODBC.1ODBC_TB_ALLTYPE_pk2)
|
try //ERROR [23000] [Oracle][ODBC][Ora]ORA-00001: 违反唯一约束条件 (1ODBC.1ODBC_TB_ALLTYPE_pk2)
|
||||||
{
|
{
|
||||||
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||||
break;
|
break;
|
||||||
@ -208,7 +228,7 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -229,7 +249,7 @@ namespace FreeSql.Tests.Odbc.Oracle
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue,
|
ShortNullable = short.MinValue,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
Char = 'X',
|
Char = 'X',
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
@ -14,6 +14,26 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
|||||||
{
|
{
|
||||||
public class PostgreSQLCodeFirstTest
|
public class PostgreSQLCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.pgsql;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void StringLength()
|
public void StringLength()
|
||||||
{
|
{
|
||||||
@ -31,53 +51,53 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.pgsql.CodeFirst.SyncStructure<测试中文表>();
|
g.pgsql.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.pgsql.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.pgsql.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.pgsql.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.pgsql.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.pgsql.GetRepository<测试中文表>();
|
var repo = g.pgsql.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.pgsql.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -105,7 +125,7 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
|||||||
public void AddField()
|
public void AddField()
|
||||||
{
|
{
|
||||||
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
var sql = g.pgsql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
g.pgsql.Select<TopicAddField>();
|
g.pgsql.Select<TopicAddField>();
|
||||||
var id = g.pgsql.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
var id = g.pgsql.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||||
}
|
}
|
||||||
@ -160,7 +180,7 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
|||||||
testFieldBoolNullable = true,
|
testFieldBoolNullable = true,
|
||||||
testFieldByte = byte.MaxValue,
|
testFieldByte = byte.MaxValue,
|
||||||
testFieldByteNullable = byte.MinValue,
|
testFieldByteNullable = byte.MinValue,
|
||||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
testFieldDateTime = DateTime.Now,
|
testFieldDateTime = DateTime.Now,
|
||||||
testFieldDateTimeNullable = DateTime.Now.AddDays(-1),
|
testFieldDateTimeNullable = DateTime.Now.AddDays(-1),
|
||||||
testFieldDecimal = 999.99M,
|
testFieldDecimal = 999.99M,
|
||||||
@ -183,7 +203,7 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
|
|||||||
testFieldSByteNullable = sbyte.MinValue,
|
testFieldSByteNullable = sbyte.MinValue,
|
||||||
testFieldShort = short.MaxValue,
|
testFieldShort = short.MaxValue,
|
||||||
testFieldShortNullable = short.MinValue,
|
testFieldShortNullable = short.MinValue,
|
||||||
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
testFieldChar = 'X',
|
testFieldChar = 'X',
|
||||||
testFieldTimeSpan = TimeSpan.FromDays(1),
|
testFieldTimeSpan = TimeSpan.FromDays(1),
|
||||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(90),
|
testFieldTimeSpanNullable = TimeSpan.FromSeconds(90),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -12,6 +12,26 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
[Collection("SqlServerCollection")]
|
[Collection("SqlServerCollection")]
|
||||||
public class SqlServerCodeFirstTest
|
public class SqlServerCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlserver;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void StringLength()
|
public void StringLength()
|
||||||
{
|
{
|
||||||
@ -29,7 +49,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 表名中有点()
|
public void 表名中有点()
|
||||||
{
|
{
|
||||||
var item = new tbdot01 { name = "insert" };
|
var item = new tbdot01 { name = "insert" };
|
||||||
g.sqlserver.Insert(item).ExecuteAffrows();
|
g.sqlserver.Insert(item).ExecuteAffrows();
|
||||||
@ -50,66 +70,66 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
Assert.Null(find);
|
Assert.Null(find);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表中带点
|
/// 表中带点
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Table(Name = "[freesql.T].[dbo].[sys.tbdot01]")]
|
[Table(Name = "[freesql.T].[dbo].[sys.tbdot01]")]
|
||||||
class tbdot01
|
class tbdot01
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主键
|
/// 主键
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid id { get; set; }
|
public Guid id { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.sqlserver.CodeFirst.SyncStructure<测试中文表>();
|
g.sqlserver.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.sqlserver.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.sqlserver.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.sqlserver.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.sqlserver.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.sqlserver.GetRepository<测试中文表>();
|
var repo = g.sqlserver.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -167,7 +187,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
public void GetComparisonDDLStatements()
|
public void GetComparisonDDLStatements()
|
||||||
{
|
{
|
||||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +208,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
testFieldBoolNullable = true,
|
testFieldBoolNullable = true,
|
||||||
testFieldByte = byte.MaxValue,
|
testFieldByte = byte.MaxValue,
|
||||||
testFieldByteNullable = byte.MinValue,
|
testFieldByteNullable = byte.MinValue,
|
||||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
testFieldDateTime = DateTime.Now,
|
testFieldDateTime = DateTime.Now,
|
||||||
testFieldDateTimeNullable = DateTime.Now.AddHours(1),
|
testFieldDateTimeNullable = DateTime.Now.AddHours(1),
|
||||||
testFieldDateTimeNullableOffset = new DateTimeOffset(DateTime.Now.AddHours(1), TimeSpan.FromHours(8)),
|
testFieldDateTimeNullableOffset = new DateTimeOffset(DateTime.Now.AddHours(1), TimeSpan.FromHours(8)),
|
||||||
@ -212,7 +232,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
|||||||
testFieldSByteNullable = sbyte.MinValue,
|
testFieldSByteNullable = sbyte.MinValue,
|
||||||
testFieldShort = short.MaxValue,
|
testFieldShort = short.MaxValue,
|
||||||
testFieldShortNullable = short.MinValue,
|
testFieldShortNullable = short.MinValue,
|
||||||
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
testFieldChar = 'X',
|
testFieldChar = 'X',
|
||||||
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
||||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(30),
|
testFieldTimeSpanNullable = TimeSpan.FromSeconds(30),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -12,12 +12,32 @@ namespace FreeSql.Tests.Dameng
|
|||||||
{
|
{
|
||||||
public class DamengCodeFirstTest
|
public class DamengCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.dameng;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
var fsql = g.dameng;
|
var fsql = g.dameng;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -54,7 +74,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
var creatorId1 = dr.GetString(1);
|
var creatorId1 = dr.GetString(1);
|
||||||
|
|
||||||
var id = dr.GetValue(0);
|
var id = dr.GetValue(0);
|
||||||
//var creatorId = dr.GetValue(1); //报错
|
//var creatorId = dr.GetValue(1); //报错
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,7 +99,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_StringLength_1()
|
public void Text_StringLength_1()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT02 { Data = str1 };
|
var item1 = new TS_TEXT02 { Data = str1 };
|
||||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||||
@ -101,7 +121,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text()
|
public void Text()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT01 { Data = str1 };
|
var item1 = new TS_TEXT01 { Data = str1 };
|
||||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||||
@ -122,7 +142,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -137,7 +157,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
//NoneParameter
|
//NoneParameter
|
||||||
item1 = new TS_BLB01 { Data = data1 };
|
item1 = new TS_BLB01 { Data = data1 };
|
||||||
Assert.Throws<Exception>(() => g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
Assert.Throws<Exception>(() => g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
//DmException: 字符串截断
|
//DmException: 字符串截断
|
||||||
}
|
}
|
||||||
class TS_BLB01
|
class TS_BLB01
|
||||||
{
|
{
|
||||||
@ -162,106 +182,106 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 数字表_字段()
|
public void 数字表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
||||||
g.dameng.CodeFirst.SyncStructure<测试数字表>();
|
g.dameng.CodeFirst.SyncStructure<测试数字表>();
|
||||||
|
|
||||||
var item = new 测试数字表
|
var item = new 测试数字表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.dameng.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.dameng.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.dameng.GetRepository<测试数字表>();
|
var repo = g.dameng.GetRepository<测试数字表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
[Table(Name = "123测试数字表")]
|
[Table(Name = "123测试数字表")]
|
||||||
class 测试数字表
|
class 测试数字表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true, Name = "123编号")]
|
[Column(IsPrimary = true, Name = "123编号")]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123标题")]
|
[Column(Name = "123标题")]
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123创建时间")]
|
[Column(Name = "123创建时间")]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.dameng.CodeFirst.SyncStructure<测试中文表>();
|
g.dameng.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.dameng.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.dameng.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.dameng.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.dameng.GetRepository<测试中文表>();
|
var repo = g.dameng.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -313,7 +333,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
public void GetComparisonDDLStatements()
|
public void GetComparisonDDLStatements()
|
||||||
{
|
{
|
||||||
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
//sql = g.dameng.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
//sql = g.dameng.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +350,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -351,7 +371,7 @@ WHERE (a.""ID"" = 1) AND ROWNUM < 2";
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue,
|
ShortNullable = short.MinValue,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
Char = 'X',
|
Char = 'X',
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,12 +10,32 @@ namespace FreeSql.Tests.Firebird
|
|||||||
{
|
{
|
||||||
public class FirebirdCodeFirstTest
|
public class FirebirdCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.firebird;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
var fsql = g.firebird;
|
var fsql = g.firebird;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -38,7 +58,7 @@ namespace FreeSql.Tests.Firebird
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_StringLength_1()
|
public void Text_StringLength_1()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT02 { Data = str1 };
|
var item1 = new TS_TEXT02 { Data = str1 };
|
||||||
Assert.Equal(1, g.firebird.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.firebird.Insert(item1).ExecuteAffrows());
|
||||||
@ -66,7 +86,7 @@ namespace FreeSql.Tests.Firebird
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -111,111 +131,111 @@ namespace FreeSql.Tests.Firebird
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 数字表_字段()
|
public void 数字表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.firebird.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
var sql = g.firebird.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
||||||
g.firebird.CodeFirst.SyncStructure<测试数字表>();
|
g.firebird.CodeFirst.SyncStructure<测试数字表>();
|
||||||
|
|
||||||
var item = new 测试数字表
|
var item = new 测试数字表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.firebird.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.firebird.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.firebird.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.firebird.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.firebird.GetRepository<测试数字表>();
|
var repo = g.firebird.GetRepository<测试数字表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.firebird.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
[Table(Name = "123tb")]
|
[Table(Name = "123tb")]
|
||||||
[OraclePrimaryKeyName("pk1_123tb")]
|
[OraclePrimaryKeyName("pk1_123tb")]
|
||||||
class 测试数字表
|
class 测试数字表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true, Name = "123id")]
|
[Column(IsPrimary = true, Name = "123id")]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123title")]
|
[Column(Name = "123title")]
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123time")]
|
[Column(Name = "123time")]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.firebird.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.firebird.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.firebird.CodeFirst.SyncStructure<测试中文表>();
|
g.firebird.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.firebird.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.firebird.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.firebird.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.firebird.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.firebird.GetRepository<测试中文表>();
|
var repo = g.firebird.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.firebird.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -231,7 +251,7 @@ namespace FreeSql.Tests.Firebird
|
|||||||
class AddUniquesInfo
|
class AddUniquesInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编号
|
/// 编号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid id { get; set; }
|
public Guid id { get; set; }
|
||||||
public string phone { get; set; }
|
public string phone { get; set; }
|
||||||
@ -288,7 +308,7 @@ namespace FreeSql.Tests.Firebird
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -309,7 +329,7 @@ namespace FreeSql.Tests.Firebird
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue,
|
ShortNullable = short.MinValue,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
UInt = uint.MaxValue,
|
UInt = uint.MaxValue,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,12 +10,32 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
{
|
{
|
||||||
public class MsAccessCodeFirstTest
|
public class MsAccessCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.msaccess;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
var fsql = g.msaccess;
|
var fsql = g.msaccess;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -52,57 +72,57 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.msaccess.CodeFirst.SyncStructure<测试中文表>();
|
g.msaccess.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.msaccess.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.msaccess.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.msaccess.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.msaccess.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.msaccess.GetRepository<测试中文表>();
|
var repo = g.msaccess.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.msaccess.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -148,29 +168,29 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
public void AddField()
|
public void AddField()
|
||||||
{
|
{
|
||||||
|
|
||||||
//秀一波 FreeSql.Repository 扩展包,dotnet add package FreeSql.Repository
|
//秀一波 FreeSql.Repository 扩展包,dotnet add package FreeSql.Repository
|
||||||
var topicRepository = g.msaccess.GetGuidRepository<Topic>();
|
var topicRepository = g.msaccess.GetGuidRepository<Topic>();
|
||||||
var commentRepository = g.msaccess.GetGuidRepository<Comment>();
|
var commentRepository = g.msaccess.GetGuidRepository<Comment>();
|
||||||
|
|
||||||
//添加测试文章
|
//添加测试文章
|
||||||
var topic = topicRepository.Insert(new Topic
|
var topic = topicRepository.Insert(new Topic
|
||||||
{
|
{
|
||||||
Title = "文章标题1",
|
Title = "文章标题1",
|
||||||
Content = "文章内容1",
|
Content = "文章内容1",
|
||||||
CreateTime = DateTime.Now
|
CreateTime = DateTime.Now
|
||||||
});
|
});
|
||||||
|
|
||||||
//添加10条测试评论
|
//添加10条测试评论
|
||||||
var comments = Enumerable.Range(0, 10).Select(a => new Comment
|
var comments = Enumerable.Range(0, 10).Select(a => new Comment
|
||||||
{
|
{
|
||||||
TopicId = topic.Id,
|
TopicId = topic.Id,
|
||||||
Nickname = $"昵称{a}",
|
Nickname = $"昵称{a}",
|
||||||
Content = $"评论内容{a}",
|
Content = $"评论内容{a}",
|
||||||
CreateTime = DateTime.Now
|
CreateTime = DateTime.Now
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
var affrows = commentRepository.Insert(comments);
|
var affrows = commentRepository.Insert(comments);
|
||||||
|
|
||||||
var find = commentRepository.Select.Where(a => a.Topic.Title == "文章标题1").ToList();
|
var find = commentRepository.Select.Where(a => a.Topic.Title == "文章标题1").ToList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -202,7 +222,7 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
{
|
{
|
||||||
|
|
||||||
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
//sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
//sql = g.msaccess.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +243,7 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -244,7 +264,7 @@ namespace FreeSql.Tests.MsAccess
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue,
|
ShortNullable = short.MinValue,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
Char = 'X',
|
Char = 'X',
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -11,6 +11,26 @@ namespace FreeSql.Tests.MySql
|
|||||||
{
|
{
|
||||||
public class MySqlCodeFirstTest
|
public class MySqlCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.mysql;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public enum EnumTest009
|
public enum EnumTest009
|
||||||
{
|
{
|
||||||
A, B, C
|
A, B, C
|
||||||
@ -36,7 +56,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
public void TestEnumToSet009()
|
public void TestEnumToSet009()
|
||||||
{
|
{
|
||||||
var fsql = g.mysql;
|
var fsql = g.mysql;
|
||||||
//插入
|
//插入
|
||||||
//insert into TestTable(ColEnumTest,ColSetTest) values('B','A,B');
|
//insert into TestTable(ColEnumTest,ColSetTest) values('B','A,B');
|
||||||
//insert into TestTable(ColEnumTest,ColSetTest) values(1,3);
|
//insert into TestTable(ColEnumTest,ColSetTest) values(1,3);
|
||||||
var sql1 = fsql.Insert<TestTable009>().NoneParameter().AppendData(new TestTable009
|
var sql1 = fsql.Insert<TestTable009>().NoneParameter().AppendData(new TestTable009
|
||||||
@ -46,7 +66,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
}).ToSql();
|
}).ToSql();
|
||||||
Assert.Equal("INSERT INTO `TestTable009`(`ColEnumTest`, `ColSetTest`) VALUES('B', 'A,B')", sql1);
|
Assert.Equal("INSERT INTO `TestTable009`(`ColEnumTest`, `ColSetTest`) VALUES('B', 'A,B')", sql1);
|
||||||
|
|
||||||
//查询 扩展方法 contains
|
//查询 扩展方法 contains
|
||||||
//select * from TestTable t where FIND_IN_SET('A',t.ColSetTest)>0
|
//select * from TestTable t where FIND_IN_SET('A',t.ColSetTest)>0
|
||||||
//select * from TestTable t where t.ColSetTest&1
|
//select * from TestTable t where t.ColSetTest&1
|
||||||
var sql2 = fsql.Select<TestTable009>().Where(i => (i.ColSetTest & SetTest009.A) == SetTest009.A).ToSql();
|
var sql2 = fsql.Select<TestTable009>().Where(i => (i.ColSetTest & SetTest009.A) == SetTest009.A).ToSql();
|
||||||
@ -59,7 +79,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
{
|
{
|
||||||
var fsql = g.mysql;
|
var fsql = g.mysql;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -248,7 +268,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_StringLength_1()
|
public void Text_StringLength_1()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT02 { Data = str1 };
|
var item1 = new TS_TEXT02 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -270,7 +290,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text()
|
public void Text()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT01 { Data = str1 };
|
var item1 = new TS_TEXT01 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -292,7 +312,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_StringLength_2()
|
public void Text_StringLength_2()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT04 { Data = str1 };
|
var item1 = new TS_TEXT04 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -314,7 +334,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Text_MaxLength_2()
|
public void Text_MaxLength_2()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT041 { Data = str1 };
|
var item1 = new TS_TEXT041 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -336,7 +356,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void LongText()
|
public void LongText()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_TEXT03 { Data = str1 };
|
var item1 = new TS_TEXT03 { Data = str1 };
|
||||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||||
@ -358,7 +378,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -404,7 +424,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 表名中有点()
|
public void 表名中有点()
|
||||||
{
|
{
|
||||||
var item = new tbdot01 { name = "insert" };
|
var item = new tbdot01 { name = "insert" };
|
||||||
g.mysql.Insert(item).ExecuteAffrows();
|
g.mysql.Insert(item).ExecuteAffrows();
|
||||||
@ -432,59 +452,59 @@ namespace FreeSql.Tests.MySql
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<测试中文表2>();
|
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<测试中文表2>();
|
||||||
g.mysql.CodeFirst.SyncStructure<测试中文表2>();
|
g.mysql.CodeFirst.SyncStructure<测试中文表2>();
|
||||||
|
|
||||||
var item = 测试中文表2.Create("测试标题", DateTime.Now);
|
var item = 测试中文表2.Create("测试标题", DateTime.Now);
|
||||||
Assert.Equal(1, g.mysql.Insert<测试中文表2>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Insert<测试中文表2>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题22 = "测试标题更新";
|
item.标题22 = "测试标题更新";
|
||||||
Assert.Equal(1, g.mysql.Update<测试中文表2>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.mysql.Update<测试中文表2>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题22, item2.标题22);
|
Assert.Equal(item.标题22, item2.标题22);
|
||||||
|
|
||||||
item.标题22 = "测试标题更新_repo";
|
item.标题22 = "测试标题更新_repo";
|
||||||
var repo = g.mysql.GetRepository<测试中文表2>();
|
var repo = g.mysql.GetRepository<测试中文表2>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题22, item2.标题22);
|
Assert.Equal(item.标题22, item2.标题22);
|
||||||
|
|
||||||
item.标题22 = "测试标题更新_repo22";
|
item.标题22 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
item2 = g.mysql.Select<测试中文表2>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题22, item2.标题22);
|
Assert.Equal(item.标题22, item2.标题22);
|
||||||
}
|
}
|
||||||
class 测试中文表2
|
class 测试中文表2
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; protected set; }
|
public Guid 编号 { get; protected set; }
|
||||||
|
|
||||||
public string 标题 { get; protected set; }
|
public string 标题 { get; protected set; }
|
||||||
|
|
||||||
public string 标题22 { get; set; }
|
public string 标题22 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; protected set; }
|
public DateTime 创建时间 { get; protected set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
|
|
||||||
public static 测试中文表2 Create(string title, DateTime ctm)
|
public static 测试中文表2 Create(string title, DateTime ctm)
|
||||||
{
|
{
|
||||||
return new 测试中文表2 { 标题 = title, 标题22 = title, 创建时间 = ctm };
|
return new 测试中文表2 { 标题 = title, 标题22 = title, 创建时间 = ctm };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,7 +557,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
{
|
{
|
||||||
|
|
||||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
sql = g.mysql.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
sql = g.mysql.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,7 +578,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
testFieldBoolNullable = true,
|
testFieldBoolNullable = true,
|
||||||
testFieldByte = 255,
|
testFieldByte = 255,
|
||||||
testFieldByteNullable = 127,
|
testFieldByteNullable = 127,
|
||||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
testFieldDateTime = DateTime.Now,
|
testFieldDateTime = DateTime.Now,
|
||||||
testFieldDateTimeNullable = DateTime.Now.AddHours(-1),
|
testFieldDateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
testFieldDecimal = 99.99M,
|
testFieldDecimal = 99.99M,
|
||||||
@ -602,7 +622,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
testFieldSByteNullable = 99,
|
testFieldSByteNullable = 99,
|
||||||
testFieldShort = short.MaxValue,
|
testFieldShort = short.MaxValue,
|
||||||
testFieldShortNullable = short.MinValue,
|
testFieldShortNullable = short.MinValue,
|
||||||
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
testFieldChar = 'X',
|
testFieldChar = 'X',
|
||||||
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
||||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
|
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
@ -831,7 +851,7 @@ namespace FreeSql.Tests.MySql
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
/// 保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Oracle.ManagedDataAccess.Client;
|
using Oracle.ManagedDataAccess.Client;
|
||||||
using System;
|
using System;
|
||||||
@ -15,12 +15,32 @@ namespace FreeSql.Tests.Oracle
|
|||||||
{
|
{
|
||||||
public class OracleCodeFirstTest
|
public class OracleCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.oracle;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
var fsql = g.oracle;
|
var fsql = g.oracle;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -52,7 +72,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
//.UseNoneCommandParameter(true)
|
//.UseNoneCommandParameter(true)
|
||||||
|
|
||||||
.UseMonitorCommand(
|
.UseMonitorCommand(
|
||||||
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
||||||
//, (cmd, traceLog) => Console.WriteLine(traceLog)
|
//, (cmd, traceLog) => Console.WriteLine(traceLog)
|
||||||
)
|
)
|
||||||
.Build())
|
.Build())
|
||||||
@ -115,7 +135,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void NClob_StringLength_1()
|
public void NClob_StringLength_1()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_NCLB02 { Data = str1 };
|
var item1 = new TS_NCLB02 { Data = str1 };
|
||||||
Assert.Equal(1, g.oracle.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert(item1).ExecuteAffrows());
|
||||||
@ -126,7 +146,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
//NoneParameter
|
//NoneParameter
|
||||||
item1 = new TS_NCLB02 { Data = str1 };
|
item1 = new TS_NCLB02 { Data = str1 };
|
||||||
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
||||||
|
|
||||||
item2 = g.oracle.Select<TS_NCLB02>().Where(a => a.Id == item1.Id).First();
|
item2 = g.oracle.Select<TS_NCLB02>().Where(a => a.Id == item1.Id).First();
|
||||||
Assert.Equal(str1, item2.Data);
|
Assert.Equal(str1, item2.Data);
|
||||||
@ -141,7 +161,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void NClob()
|
public void NClob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_NCLB01 { Data = str1 };
|
var item1 = new TS_NCLB01 { Data = str1 };
|
||||||
Assert.Equal(1, g.oracle.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert(item1).ExecuteAffrows());
|
||||||
@ -152,7 +172,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
//NoneParameter
|
//NoneParameter
|
||||||
item1 = new TS_NCLB01 { Data = str1 };
|
item1 = new TS_NCLB01 { Data = str1 };
|
||||||
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
||||||
|
|
||||||
item2 = g.oracle.Select<TS_NCLB01>().Where(a => a.Id == item1.Id).First();
|
item2 = g.oracle.Select<TS_NCLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
Assert.Equal(str1, item2.Data);
|
Assert.Equal(str1, item2.Data);
|
||||||
@ -166,7 +186,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Clob()
|
public void Clob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
|
|
||||||
var item1 = new TS_CLB01 { Data = str1 };
|
var item1 = new TS_CLB01 { Data = str1 };
|
||||||
Assert.Equal(1, g.oracle.Insert(item1).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert(item1).ExecuteAffrows());
|
||||||
@ -177,7 +197,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
//NoneParameter
|
//NoneParameter
|
||||||
item1 = new TS_CLB01 { Data = str1 };
|
item1 = new TS_CLB01 { Data = str1 };
|
||||||
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
||||||
|
|
||||||
item2 = g.oracle.Select<TS_CLB01>().Where(a => a.Id == item1.Id).First();
|
item2 = g.oracle.Select<TS_CLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
Assert.Equal(str1, item2.Data);
|
Assert.Equal(str1, item2.Data);
|
||||||
@ -191,7 +211,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -206,7 +226,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
//NoneParameter
|
//NoneParameter
|
||||||
item1 = new TS_BLB01 { Data = data1 };
|
item1 = new TS_BLB01 { Data = data1 };
|
||||||
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||||
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
//Oracle.ManagedDataAccess.Client.OracleException:“ORA-01704: 字符串文字太长”
|
||||||
|
|
||||||
item2 = g.oracle.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
item2 = g.oracle.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||||
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||||
@ -244,111 +264,111 @@ namespace FreeSql.Tests.Oracle
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 数字表_字段()
|
public void 数字表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试数字表>();
|
||||||
g.oracle.CodeFirst.SyncStructure<测试数字表>();
|
g.oracle.CodeFirst.SyncStructure<测试数字表>();
|
||||||
|
|
||||||
var item = new 测试数字表
|
var item = new 测试数字表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.oracle.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert<测试数字表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.oracle.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Update<测试数字表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.oracle.GetRepository<测试数字表>();
|
var repo = g.oracle.GetRepository<测试数字表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试数字表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
[Table(Name = "123tb")]
|
[Table(Name = "123tb")]
|
||||||
[OraclePrimaryKeyName("pk1_123tb")]
|
[OraclePrimaryKeyName("pk1_123tb")]
|
||||||
class 测试数字表
|
class 测试数字表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true, Name = "123id")]
|
[Column(IsPrimary = true, Name = "123id")]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123title")]
|
[Column(Name = "123title")]
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(Name = "123time")]
|
[Column(Name = "123time")]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.oracle.CodeFirst.SyncStructure<测试中文表>();
|
g.oracle.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.oracle.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.oracle.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.oracle.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.oracle.GetRepository<测试中文表>();
|
var repo = g.oracle.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.oracle.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -401,7 +421,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
{
|
{
|
||||||
|
|
||||||
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.oracle.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
//sql = g.oracle.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
//sql = g.oracle.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,7 +442,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -443,7 +463,7 @@ namespace FreeSql.Tests.Oracle
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue,
|
ShortNullable = short.MinValue,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
Char = 'X',
|
Char = 'X',
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
@ -19,6 +19,26 @@ namespace FreeSql.Tests.PostgreSQL
|
|||||||
public class PostgreSQLCodeFirstTest
|
public class PostgreSQLCodeFirstTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.pgsql;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using FreeSql.Tests.DataContext.SqlServer;
|
using FreeSql.Tests.DataContext.SqlServer;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
@ -12,6 +12,26 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
{
|
{
|
||||||
public class SqlServerCodeFirstTest
|
public class SqlServerCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlserver;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GeographyCrud()
|
public void GeographyCrud()
|
||||||
{
|
{
|
||||||
@ -168,7 +188,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
item6 = fsql.Select<ts_geocrud01>().Where(a => a.id == id1).First(a => new ts_geocurd01_dto1 { geo = a.geo });
|
item6 = fsql.Select<ts_geocrud01>().Where(a => a.id == id1).First(a => new ts_geocurd01_dto1 { geo = a.geo });
|
||||||
Assert.Equal(geo1, item6.geo);
|
Assert.Equal(geo1, item6.geo);
|
||||||
|
|
||||||
//批量
|
//批量
|
||||||
fsql.Delete<ts_geocrud01>().Where("1=1").ExecuteAffrows();
|
fsql.Delete<ts_geocrud01>().Where("1=1").ExecuteAffrows();
|
||||||
id1 = Guid.NewGuid();
|
id1 = Guid.NewGuid();
|
||||||
geo1 = "LINESTRING (-122.36 47.656, -122.343 47.656)";
|
geo1 = "LINESTRING (-122.36 47.656, -122.343 47.656)";
|
||||||
@ -190,7 +210,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
Assert.Equal(items[1].id, item1.id);
|
Assert.Equal(items[1].id, item1.id);
|
||||||
Assert.Equal(items[1].geo, item1.geo);
|
Assert.Equal(items[1].geo, item1.geo);
|
||||||
|
|
||||||
//批量 NoneParameter
|
//批量 NoneParameter
|
||||||
fsql.Delete<ts_geocrud01>().Where("1=1").ExecuteAffrows();
|
fsql.Delete<ts_geocrud01>().Where("1=1").ExecuteAffrows();
|
||||||
id1 = Guid.NewGuid();
|
id1 = Guid.NewGuid();
|
||||||
geo1 = "LINESTRING (-122.36 47.656, -122.343 47.656)";
|
geo1 = "LINESTRING (-122.36 47.656, -122.343 47.656)";
|
||||||
@ -228,7 +248,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
{
|
{
|
||||||
var fsql = g.sqlserver;
|
var fsql = g.sqlserver;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -330,7 +350,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -376,7 +396,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 表名中有点()
|
public void 表名中有点()
|
||||||
{
|
{
|
||||||
var item = new tbdot01 { name = "insert" };
|
var item = new tbdot01 { name = "insert" };
|
||||||
g.sqlserver.Insert(item).ExecuteAffrows();
|
g.sqlserver.Insert(item).ExecuteAffrows();
|
||||||
@ -397,70 +417,70 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
Assert.Null(find);
|
Assert.Null(find);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表中带点
|
/// 表中带点
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Table(Name = "[freesql.T].[dbo].[sys.tbdot01]")]
|
[Table(Name = "[freesql.T].[dbo].[sys.tbdot01]")]
|
||||||
class tbdot01
|
class tbdot01
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主键
|
/// 主键
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid id { get; set; }
|
public Guid id { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.sqlserver.CodeFirst.SyncStructure<测试中文表>();
|
g.sqlserver.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.sqlserver.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.sqlserver.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.sqlserver.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.sqlserver.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.sqlserver.GetRepository<测试中文表>();
|
var repo = g.sqlserver.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlserver.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -518,7 +538,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
public void GetComparisonDDLStatements()
|
public void GetComparisonDDLStatements()
|
||||||
{
|
{
|
||||||
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
sql = g.sqlserver.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,7 +559,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
testFieldBoolNullable = true,
|
testFieldBoolNullable = true,
|
||||||
testFieldByte = byte.MaxValue,
|
testFieldByte = byte.MaxValue,
|
||||||
testFieldByteNullable = byte.MinValue,
|
testFieldByteNullable = byte.MinValue,
|
||||||
testFieldBytes = Encoding.GetEncoding("gb2312").GetBytes("我是中国人"),
|
testFieldBytes = Encoding.GetEncoding("gb2312").GetBytes("我是中国人"),
|
||||||
testFieldDateTime = DateTime.Now,
|
testFieldDateTime = DateTime.Now,
|
||||||
testFieldDateTimeNullable = DateTime.Now.AddHours(1),
|
testFieldDateTimeNullable = DateTime.Now.AddHours(1),
|
||||||
testFieldDateTimeNullableOffset = new DateTimeOffset(DateTime.Now.AddHours(1), TimeSpan.FromHours(8)),
|
testFieldDateTimeNullableOffset = new DateTimeOffset(DateTime.Now.AddHours(1), TimeSpan.FromHours(8)),
|
||||||
@ -563,7 +583,7 @@ namespace FreeSql.Tests.SqlServer
|
|||||||
testFieldSByteNullable = sbyte.MinValue,
|
testFieldSByteNullable = sbyte.MinValue,
|
||||||
testFieldShort = short.MaxValue,
|
testFieldShort = short.MaxValue,
|
||||||
testFieldShortNullable = short.MinValue,
|
testFieldShortNullable = short.MinValue,
|
||||||
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
testFieldChar = 'X',
|
testFieldChar = 'X',
|
||||||
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
testFieldTimeSpan = TimeSpan.FromSeconds(999),
|
||||||
testFieldTimeSpanNullable = TimeSpan.FromSeconds(30),
|
testFieldTimeSpanNullable = TimeSpan.FromSeconds(30),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -11,12 +11,32 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
{
|
{
|
||||||
public class SqliteCodeFirstTest
|
public class SqliteCodeFirstTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test_0String()
|
||||||
|
{
|
||||||
|
var fsql = g.sqlite;
|
||||||
|
fsql.Delete<test_0string01>().Where("1=1").ExecuteAffrows();
|
||||||
|
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows());
|
||||||
|
Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows());
|
||||||
|
|
||||||
|
var list = fsql.Select<test_0string01>().ToList();
|
||||||
|
Assert.Equal(2, list.Count);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name);
|
||||||
|
Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name);
|
||||||
|
}
|
||||||
|
class test_0string01
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertUpdateParameter()
|
public void InsertUpdateParameter()
|
||||||
{
|
{
|
||||||
var fsql = g.sqlite;
|
var fsql = g.sqlite;
|
||||||
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
|
||||||
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
|
||||||
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
|
||||||
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
|
||||||
Assert.NotNull(find);
|
Assert.NotNull(find);
|
||||||
@ -39,7 +59,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Blob()
|
public void Blob()
|
||||||
{
|
{
|
||||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||||
|
|
||||||
var item1 = new TS_BLB01 { Data = data1 };
|
var item1 = new TS_BLB01 { Data = data1 };
|
||||||
@ -92,7 +112,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 表名中有点()
|
public void 表名中有点()
|
||||||
{
|
{
|
||||||
var item = new tbdot01 { name = "insert" };
|
var item = new tbdot01 { name = "insert" };
|
||||||
g.sqlite.Insert(item).ExecuteAffrows();
|
g.sqlite.Insert(item).ExecuteAffrows();
|
||||||
@ -120,57 +140,57 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void 中文表_字段()
|
public void 中文表_字段()
|
||||||
{
|
{
|
||||||
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<测试中文表>();
|
||||||
g.sqlite.CodeFirst.SyncStructure<测试中文表>();
|
g.sqlite.CodeFirst.SyncStructure<测试中文表>();
|
||||||
|
|
||||||
var item = new 测试中文表
|
var item = new 测试中文表
|
||||||
{
|
{
|
||||||
标题 = "测试标题",
|
标题 = "测试标题",
|
||||||
创建时间 = DateTime.Now
|
创建时间 = DateTime.Now
|
||||||
};
|
};
|
||||||
Assert.Equal(1, g.sqlite.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
Assert.Equal(1, g.sqlite.Insert<测试中文表>().AppendData(item).ExecuteAffrows());
|
||||||
Assert.NotEqual(Guid.Empty, item.编号);
|
Assert.NotEqual(Guid.Empty, item.编号);
|
||||||
var item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
var item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新";
|
item.标题 = "测试标题更新";
|
||||||
Assert.Equal(1, g.sqlite.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
Assert.Equal(1, g.sqlite.Update<测试中文表>().SetSource(item).ExecuteAffrows());
|
||||||
item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo";
|
item.标题 = "测试标题更新_repo";
|
||||||
var repo = g.sqlite.GetRepository<测试中文表>();
|
var repo = g.sqlite.GetRepository<测试中文表>();
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
|
|
||||||
item.标题 = "测试标题更新_repo22";
|
item.标题 = "测试标题更新_repo22";
|
||||||
Assert.Equal(1, repo.Update(item));
|
Assert.Equal(1, repo.Update(item));
|
||||||
item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
item2 = g.sqlite.Select<测试中文表>().Where(a => a.编号 == item.编号).First();
|
||||||
Assert.NotNull(item2);
|
Assert.NotNull(item2);
|
||||||
Assert.Equal(item.编号, item2.编号);
|
Assert.Equal(item.编号, item2.编号);
|
||||||
Assert.Equal(item.标题, item2.标题);
|
Assert.Equal(item.标题, item2.标题);
|
||||||
}
|
}
|
||||||
class 测试中文表
|
class 测试中文表
|
||||||
{
|
{
|
||||||
[Column(IsPrimary = true)]
|
[Column(IsPrimary = true)]
|
||||||
public Guid 编号 { get; set; }
|
public Guid 编号 { get; set; }
|
||||||
|
|
||||||
public string 标题 { get; set; }
|
public string 标题 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
|
||||||
public DateTime 创建时间 { get; set; }
|
public DateTime 创建时间 { get; set; }
|
||||||
|
|
||||||
[Column(ServerTime = DateTimeKind.Local)]
|
[Column(ServerTime = DateTimeKind.Local)]
|
||||||
public DateTime 更新时间 { get; set; }
|
public DateTime 更新时间 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -217,29 +237,29 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
public void AddField()
|
public void AddField()
|
||||||
{
|
{
|
||||||
|
|
||||||
//秀一波 FreeSql.Repository 扩展包,dotnet add package FreeSql.Repository
|
//秀一波 FreeSql.Repository 扩展包,dotnet add package FreeSql.Repository
|
||||||
var topicRepository = g.sqlite.GetGuidRepository<Topic>();
|
var topicRepository = g.sqlite.GetGuidRepository<Topic>();
|
||||||
var commentRepository = g.sqlite.GetGuidRepository<Comment>();
|
var commentRepository = g.sqlite.GetGuidRepository<Comment>();
|
||||||
|
|
||||||
//添加测试文章
|
//添加测试文章
|
||||||
var topic = topicRepository.Insert(new Topic
|
var topic = topicRepository.Insert(new Topic
|
||||||
{
|
{
|
||||||
Title = "文章标题1",
|
Title = "文章标题1",
|
||||||
Content = "文章内容1",
|
Content = "文章内容1",
|
||||||
CreateTime = DateTime.Now
|
CreateTime = DateTime.Now
|
||||||
});
|
});
|
||||||
|
|
||||||
//添加10条测试评论
|
//添加10条测试评论
|
||||||
var comments = Enumerable.Range(0, 10).Select(a => new Comment
|
var comments = Enumerable.Range(0, 10).Select(a => new Comment
|
||||||
{
|
{
|
||||||
TopicId = topic.Id,
|
TopicId = topic.Id,
|
||||||
Nickname = $"昵称{a}",
|
Nickname = $"昵称{a}",
|
||||||
Content = $"评论内容{a}",
|
Content = $"评论内容{a}",
|
||||||
CreateTime = DateTime.Now
|
CreateTime = DateTime.Now
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
var affrows = commentRepository.Insert(comments);
|
var affrows = commentRepository.Insert(comments);
|
||||||
|
|
||||||
var find = commentRepository.Select.Where(a => a.Topic.Title == "文章标题1").ToList();
|
var find = commentRepository.Select.Where(a => a.Topic.Title == "文章标题1").ToList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -271,7 +291,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
{
|
{
|
||||||
|
|
||||||
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后
|
||||||
//sql = g.Sqlite.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
//sql = g.Sqlite.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +312,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
BoolNullable = true,
|
BoolNullable = true,
|
||||||
Byte = 255,
|
Byte = 255,
|
||||||
ByteNullable = 127,
|
ByteNullable = 127,
|
||||||
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
Bytes = Encoding.UTF8.GetBytes("我是中国人"),
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
DateTimeNullable = DateTime.Now.AddHours(-1),
|
DateTimeNullable = DateTime.Now.AddHours(-1),
|
||||||
Decimal = 99.99M,
|
Decimal = 99.99M,
|
||||||
@ -313,7 +333,7 @@ namespace FreeSql.Tests.Sqlite
|
|||||||
SByteNullable = 99,
|
SByteNullable = 99,
|
||||||
Short = short.MaxValue,
|
Short = short.MaxValue,
|
||||||
ShortNullable = short.MinValue,
|
ShortNullable = short.MinValue,
|
||||||
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
|
||||||
Char = 'X',
|
Char = 'X',
|
||||||
TimeSpan = TimeSpan.FromSeconds(999),
|
TimeSpan = TimeSpan.FromSeconds(999),
|
||||||
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
TimeSpanNullable = TimeSpan.FromSeconds(60),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user