- 完善 IUpdate.SetSource 组合主键的数据更新单元测试;

This commit is contained in:
28810
2020-02-24 18:03:37 +08:00
parent 05d1828884
commit 02cd7ad557
28 changed files with 375 additions and 209 deletions

View File

@ -48,6 +48,29 @@ namespace FreeSql.Tests.Odbc.Dameng
sql = update.SetSource(items).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CREATETIME\" = to_timestamp('2020-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
if (g.dameng.Select<ts_source_mpk>().Where(a => a.id1 == 1 && a.id2 == 7).Any() == false)
g.dameng.Insert(new ts_source_mpk { id1 = 1, id2 = 7 }).ExecuteAffrows();
if (g.dameng.Select<ts_source_mpk>().Where(a => a.id1 == 1 && a.id2 == 8).Any() == false)
g.dameng.Insert(new ts_source_mpk { id1 = 1, id2 = 8 }).ExecuteAffrows();
sql = g.dameng.Update<ts_source_mpk>().SetSource(new[] {
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
}).NoneParameter().ToSql().Replace("\r\n", "");
g.dameng.Update<ts_source_mpk>().SetSource(new[] {
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
}).NoneParameter().ExecuteAffrows();
var testlist = g.dameng.Select<ts_source_mpk>().ToList();
}
public class ts_source_mpk
{
[Column(IsPrimary = true)]
public int id1 { get; set; }
[Column(IsPrimary = true)]
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void IgnoreColumns()

View File

@ -50,6 +50,19 @@ namespace FreeSql.Tests.Odbc.Default
sql = update.SetSource(items).IgnoreColumns(a => a.TypeGuid).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [CreateTime] = '2020-01-01 00:00:00' WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
sql = g.odbc.Update<ts_source_mpk>().SetSource(new[] {
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
}).NoneParameter().ToSql().Replace("\r\n", "");
}
public class ts_source_mpk
{
[Column(IsPrimary = true)]
public int id1 { get; set; }
[Column(IsPrimary = true)]
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void IgnoreColumns()

View File

@ -78,6 +78,19 @@ namespace FreeSql.Tests.Odbc.MySql
Assert.Equal("UPDATE `TestEnumUpdateTb` SET `type` = 'sum211', `time` = '0001-01-01 00:00:00.000' WHERE (`id` = 0)", sql);
g.mysql.Update<TestEnumUpdateTb>().NoneParameter().SetSource(new TestEnumUpdateTb { id = (int)id, type = TestEnumUpdateTbType.biggit }).ExecuteAffrows();
Assert.Equal(TestEnumUpdateTbType.biggit, g.mysql.Select<TestEnumUpdateTb>().Where(a => a.id == id).First()?.type);
sql = g.mysql.Update<ts_source_mpk>().SetSource(new[] {
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
}).NoneParameter().ToSql().Replace("\r\n", "");
}
public class ts_source_mpk
{
[Column(IsPrimary = true)]
public int id1 { get; set; }
[Column(IsPrimary = true)]
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void IgnoreColumns()

View File

@ -48,6 +48,19 @@ namespace FreeSql.Tests.Odbc.Oracle
sql = update.SetSource(items).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CREATETIME\" = to_timestamp('2020-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
sql = g.oracle.Update<ts_source_mpk>().SetSource(new[] {
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
}).NoneParameter().ToSql().Replace("\r\n", "");
}
public class ts_source_mpk
{
[Column(IsPrimary = true)]
public int id1 { get; set; }
[Column(IsPrimary = true)]
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void IgnoreColumns()

View File

@ -49,6 +49,19 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
sql = update.SetSource(items).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"tb_topic\" SET \"createtime\" = '2020-01-01 00:00:00.000000' WHERE (\"id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
sql = g.pgsql.Update<ts_source_mpk>().SetSource(new[] {
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
}).NoneParameter().ToSql().Replace("\r\n", "");
}
public class ts_source_mpk
{
[Column(IsPrimary = true)]
public int id1 { get; set; }
[Column(IsPrimary = true)]
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void IgnoreColumns()

View File

@ -51,6 +51,19 @@ namespace FreeSql.Tests.Odbc.SqlServer
sql = update.SetSource(items).IgnoreColumns(a => a.TypeGuid).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE [tb_topic] SET [CreateTime] = '2020-01-01 00:00:00.000' WHERE ([Id] IN (1,2,3,4,5,6,7,8,9,10))", sql);
sql = g.sqlserver.Update<ts_source_mpk>().SetSource(new[] {
new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" },
new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" }
}).NoneParameter().ToSql().Replace("\r\n", "");
}
public class ts_source_mpk
{
[Column(IsPrimary = true)]
public int id1 { get; set; }
[Column(IsPrimary = true)]
public int id2 { get; set; }
public string xx { get; set; }
}
[Fact]
public void IgnoreColumns()