- 增加 .First()/.FirstAsync() 指定字段查询的重载方法;

- 调整 FreeSql.Repository 直接引用 FreeSql.DbContext 内的仓储实现;
- 补充 单独针对 MySql 枚举类型的单元测试;
This commit is contained in:
28810
2019-04-11 17:34:21 +08:00
parent b5c79204d8
commit 4686d7e0af
19 changed files with 106 additions and 922 deletions

View File

@ -18,6 +18,13 @@ namespace FreeSql.Tests.MySql {
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
class TestEnumInsertTb {
[Column(IsIdentity = true)]
public int id { get; set; }
public TestEnumInserTbType type { get; set; }
public DateTime time { get; set; } = new DateTime();
}
enum TestEnumInserTbType { str1, biggit, sum211 }
[Fact]
public void AppendData() {
@ -35,6 +42,12 @@ namespace FreeSql.Tests.MySql {
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
Assert.Equal("INSERT INTO `tb_topic`(`Clicks`, `Title`) VALUES(?Clicks_0, ?Title_0), (?Clicks_1, ?Title_1), (?Clicks_2, ?Title_2), (?Clicks_3, ?Title_3), (?Clicks_4, ?Title_4), (?Clicks_5, ?Title_5), (?Clicks_6, ?Title_6), (?Clicks_7, ?Title_7), (?Clicks_8, ?Title_8), (?Clicks_9, ?Title_9)", sql);
sql = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).ToSql();
Assert.Equal("INSERT INTO `TestEnumInsertTb`(`type`, `time`) VALUES(?type_0, ?time_0)", sql);
sql = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).NoneParameter().ToSql();
Assert.Equal("INSERT INTO `TestEnumInsertTb`(`type`, `time`) VALUES('sum211', '0001-01-01 00:00:00')", sql);
}
[Fact]
@ -66,6 +79,9 @@ namespace FreeSql.Tests.MySql {
Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows());
Assert.Equal(10, insert.AppendData(items).ExecuteAffrows());
Assert.Equal(1, g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).ExecuteAffrows());
Assert.Equal(1, g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).NoneParameter().ExecuteAffrows());
}
[Fact]
public void ExecuteIdentity() {
@ -73,6 +89,11 @@ namespace FreeSql.Tests.MySql {
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity());
var id = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).ExecuteIdentity();
Assert.Equal(TestEnumInserTbType.sum211, g.mysql.Select< TestEnumInsertTb>().Where(a => a.id == id).First()?.type);
id = g.mysql.Insert<TestEnumInsertTb>().AppendData(new TestEnumInsertTb { type = TestEnumInserTbType.sum211 }).NoneParameter().ExecuteIdentity();
Assert.Equal(TestEnumInserTbType.sum211, g.mysql.Select<TestEnumInsertTb>().Where(a => a.id == id).First()?.type);
}
[Fact]
public void ExecuteInserted() {