增加 IncludeMany 变异多级单元测试

This commit is contained in:
28810
2019-05-15 19:08:22 +08:00
parent fe016c017d
commit 7ac0d62ed7
7 changed files with 218 additions and 24 deletions

View File

@ -901,9 +901,48 @@ namespace FreeSql.Tests.MySql {
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = ?bname", sql);
}
public class TestInclude_OneToManyModel1 {
[Column(IsIdentity = true)]
public int id { get; set; }
public virtual TestInclude_OneToManyModel2 model2 { get; set; }
public string m1name { get; set; }
}
public class TestInclude_OneToManyModel2 {
[Column(IsPrimary = true)]
public int model2id { get; set; }
public virtual TestInclude_OneToManyModel1 model1 { get; set; }
public string m2setting { get; set; }
public List<TestInclude_OneToManyModel3> childs { get; set; }
}
public class TestInclude_OneToManyModel3 {
[Column(IsIdentity = true)]
public int id { get; set; }
public int model2111Idaaa { get; set; }
public string title { get; set; }
}
[Fact]
public void Include_OneToMany() {
var model1 = new TestInclude_OneToManyModel1 { m1name = DateTime.Now.Second.ToString() };
model1.id = (int)g.mysql.Insert(model1).ExecuteIdentity();
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
g.mysql.Insert(model2).ExecuteAffrows();
var model3s = new[] {
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
};
Assert.Equal(3, g.mysql.Insert(model3s).ExecuteAffrows());
var t1 = g.mysql.Select<TestInclude_OneToManyModel1>()
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
.Where(a => a.id <= model1.id)
.ToList();
}
[Fact]
public void Include_OneToChilds() {

View File

@ -794,9 +794,48 @@ namespace FreeSql.Tests.Oracle {
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql);
}
public class TiOtmModel1 {
[Column(IsIdentity = true)]
public int id { get; set; }
public virtual TiOtmModel2 model2 { get; set; }
public string m1name { get; set; }
}
public class TiOtmModel2 {
[Column(IsPrimary = true)]
public int model2id { get; set; }
public virtual TiOtmModel1 model1 { get; set; }
public string m2setting { get; set; }
public List<TiOtmModel3> childs { get; set; }
}
public class TiOtmModel3 {
[Column(IsIdentity = true)]
public int id { get; set; }
public int model2111Idaaa { get; set; }
public string title { get; set; }
}
[Fact]
public void Include_OneToMany() {
var model1 = new TiOtmModel1 { m1name = DateTime.Now.Second.ToString() };
model1.id = (int)g.oracle.Insert(model1).ExecuteIdentity();
var model2 = new TiOtmModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
g.oracle.Insert(model2).ExecuteAffrows();
var model3s = new[] {
new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
};
Assert.Equal(3, g.oracle.Insert(model3s).ExecuteAffrows());
var t1 = g.oracle.Select<TiOtmModel1>()
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
.Where(a => a.id <= model1.id)
.ToList();
}
[Fact]
public void Include_OneToChilds() {

View File

@ -860,9 +860,48 @@ namespace FreeSql.Tests.PostgreSQL {
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"typeguid\" and b.\"name\" = @bname", sql);
}
public class TestInclude_OneToManyModel1 {
[Column(IsIdentity = true)]
public int id { get; set; }
public virtual TestInclude_OneToManyModel2 model2 { get; set; }
public string m1name { get; set; }
}
public class TestInclude_OneToManyModel2 {
[Column(IsPrimary = true)]
public int model2id { get; set; }
public virtual TestInclude_OneToManyModel1 model1 { get; set; }
public string m2setting { get; set; }
public List<TestInclude_OneToManyModel3> childs { get; set; }
}
public class TestInclude_OneToManyModel3 {
[Column(IsIdentity = true)]
public int id { get; set; }
public int model2111Idaaa { get; set; }
public string title { get; set; }
}
[Fact]
public void Include_OneToMany() {
var model1 = new TestInclude_OneToManyModel1 { m1name = DateTime.Now.Second.ToString() };
model1.id = (int)g.pgsql.Insert(model1).ExecuteIdentity();
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
g.pgsql.Insert(model2).ExecuteAffrows();
var model3s = new[] {
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
};
Assert.Equal(3, g.pgsql.Insert(model3s).ExecuteAffrows());
var t1 = g.pgsql.Select<TestInclude_OneToManyModel1>()
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
.Where(a => a.id <= model1.id)
.ToList();
}
[Fact]
public void Include_OneToChilds() {

View File

@ -791,9 +791,48 @@ namespace FreeSql.Tests.SqlServer {
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN TestTypeInfo b on b.Guid = a.TypeGuid and b.Name = @bname", sql);
}
public class TestInclude_OneToManyModel1 {
[Column(IsIdentity = true)]
public int id { get; set; }
public virtual TestInclude_OneToManyModel2 model2 { get; set; }
public string m1name { get; set; }
}
public class TestInclude_OneToManyModel2 {
[Column(IsPrimary = true)]
public int model2id { get; set; }
public virtual TestInclude_OneToManyModel1 model1 { get; set; }
public string m2setting { get; set; }
public List<TestInclude_OneToManyModel3> childs { get; set; }
}
public class TestInclude_OneToManyModel3 {
[Column(IsIdentity = true)]
public int id { get; set; }
public int model2111Idaaa { get; set; }
public string title { get; set; }
}
[Fact]
public void Include_OneToMany() {
var model1 = new TestInclude_OneToManyModel1 { m1name = DateTime.Now.Second.ToString() };
model1.id = (int)_sqlserverFixture.SqlServer.Insert(model1).ExecuteIdentity();
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
_sqlserverFixture.SqlServer.Insert(model2).ExecuteAffrows();
var model3s = new[] {
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
};
Assert.Equal(3, _sqlserverFixture.SqlServer.Insert(model3s).ExecuteAffrows());
var t1 = _sqlserverFixture.SqlServer.Select<TestInclude_OneToManyModel1>()
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
.Where(a => a.id <= model1.id)
.ToList();
}
[Fact]
public void Include_OneToChilds() {

View File

@ -757,29 +757,48 @@ namespace FreeSql.Tests.Sqlite {
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TypeGuid\" and b.\"Name\" = @bname", sql);
}
class TestInclude_OneToManyModel1 {
public class TestInclude_OneToManyModel1 {
[Column(IsIdentity = true)]
public int id { get; set; }
public virtual TestInclude_OneToManyModel2 model2 { get; set; }
public string m1name { get; set; }
}
class TestInclude_OneToManyModel2 {
public class TestInclude_OneToManyModel2 {
[Column(IsPrimary = true)]
public int model2id { get; set; }
public virtual TestInclude_OneToManyModel2 model1 { get; set; }
public virtual TestInclude_OneToManyModel1 model1 { get; set; }
public virtual List<TestInclude_OneToManyModel3> childs { get; set; }
public string m2setting { get; set; }
public List<TestInclude_OneToManyModel3> childs { get; set; }
}
class TestInclude_OneToManyModel3 {
public class TestInclude_OneToManyModel3 {
[Column(IsIdentity = true)]
public int id { get; set; }
public int model2111Idaaa { get; set; }
public string title { get; set; }
}
[Fact]
public void Include_OneToMany() {
var model1 = new TestInclude_OneToManyModel1 { };
var model1 = new TestInclude_OneToManyModel1 { m1name = DateTime.Now.Second.ToString() };
model1.id = (int)g.sqlite.Insert(model1).ExecuteIdentity();
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
g.sqlite.Insert(model2).ExecuteAffrows();
var model3s = new [] {
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
};
Assert.Equal(3, g.sqlite.Insert(model3s).ExecuteAffrows());
var t1 = g.sqlite.Select<TestInclude_OneToManyModel1>()
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id && m3.title == a.model2.m2setting))
.Where(a => a.id <= model1.id)
.ToList();
}
[Fact]
public void Include_OneToChilds() {