Skip to content

Commit 1c05852

Browse files
2881028810
28810
authored and
28810
committed
补充 IncludeMany 变异向下两级单元测试
1 parent 7ac0d62 commit 1c05852

File tree

5 files changed

+146
-26
lines changed

5 files changed

+146
-26
lines changed

FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs

+29-5
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,15 @@ public class TestInclude_OneToManyModel3 {
923923

924924
public int model2111Idaaa { get; set; }
925925
public string title { get; set; }
926+
927+
public List<TestInclude_OneToManyModel4> childs2 { get; set; }
928+
}
929+
public class TestInclude_OneToManyModel4 {
930+
[Column(IsIdentity = true)]
931+
public int id { get; set; }
932+
933+
public int model3333Id333 { get; set; }
934+
public string title444 { get; set; }
926935
}
927936

928937
[Fact]
@@ -932,17 +941,32 @@ public void Include_OneToMany() {
932941
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
933942
g.mysql.Insert(model2).ExecuteAffrows();
934943

935-
var model3s = new[] {
936-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
937-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
938-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
944+
var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" };
945+
model3_1.id = (int)g.mysql.Insert(model3_1).ExecuteIdentity();
946+
var model3_2 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" };
947+
model3_2.id = (int)g.mysql.Insert(model3_2).ExecuteIdentity();
948+
var model3_3 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" };
949+
model3_3.id = (int)g.mysql.Insert(model3_2).ExecuteIdentity();
950+
951+
var model4s = new[] {
952+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" },
953+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" },
954+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" },
955+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" },
956+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" }
939957
};
940-
Assert.Equal(3, g.mysql.Insert(model3s).ExecuteAffrows());
958+
Assert.Equal(5, g.mysql.Insert(model4s).ExecuteAffrows());
941959

942960
var t1 = g.mysql.Select<TestInclude_OneToManyModel1>()
943961
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
944962
.Where(a => a.id <= model1.id)
945963
.ToList();
964+
965+
var t2 = g.mysql.Select<TestInclude_OneToManyModel1>()
966+
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id),
967+
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id)))
968+
.Where(a => a.id <= model1.id)
969+
.ToList();
946970
}
947971
[Fact]
948972
public void Include_OneToChilds() {

FreeSql.Tests/Oracle/Curd/OracleSelectTest.cs

+29-5
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,15 @@ public class TiOtmModel3 {
816816

817817
public int model2111Idaaa { get; set; }
818818
public string title { get; set; }
819+
820+
public List<TiOtmModel4> childs2 { get; set; }
821+
}
822+
public class TiOtmModel4 {
823+
[Column(IsIdentity = true)]
824+
public int id { get; set; }
825+
826+
public int model3333Id333 { get; set; }
827+
public string title444 { get; set; }
819828
}
820829

821830
[Fact]
@@ -825,17 +834,32 @@ public void Include_OneToMany() {
825834
var model2 = new TiOtmModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
826835
g.oracle.Insert(model2).ExecuteAffrows();
827836

828-
var model3s = new[] {
829-
new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
830-
new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
831-
new TiOtmModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
837+
var model3_1 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" };
838+
model3_1.id = (int)g.oracle.Insert(model3_1).ExecuteIdentity();
839+
var model3_2 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" };
840+
model3_2.id = (int)g.oracle.Insert(model3_2).ExecuteIdentity();
841+
var model3_3 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" };
842+
model3_3.id = (int)g.oracle.Insert(model3_2).ExecuteIdentity();
843+
844+
var model4s = new[] {
845+
new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" },
846+
new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" },
847+
new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" },
848+
new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" },
849+
new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" }
832850
};
833-
Assert.Equal(3, g.oracle.Insert(model3s).ExecuteAffrows());
851+
Assert.Equal(5, g.oracle.Insert(model4s).ExecuteAffrows());
834852

835853
var t1 = g.oracle.Select<TiOtmModel1>()
836854
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
837855
.Where(a => a.id <= model1.id)
838856
.ToList();
857+
858+
var t2 = g.oracle.Select<TiOtmModel1>()
859+
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id),
860+
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id)))
861+
.Where(a => a.id <= model1.id)
862+
.ToList();
839863
}
840864
[Fact]
841865
public void Include_OneToChilds() {

FreeSql.Tests/PostgreSQL/Curd/PostgreSQLSelectTest.cs

+29-5
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,15 @@ public class TestInclude_OneToManyModel3 {
882882

883883
public int model2111Idaaa { get; set; }
884884
public string title { get; set; }
885+
886+
public List<TestInclude_OneToManyModel4> childs2 { get; set; }
887+
}
888+
public class TestInclude_OneToManyModel4 {
889+
[Column(IsIdentity = true)]
890+
public int id { get; set; }
891+
892+
public int model3333Id333 { get; set; }
893+
public string title444 { get; set; }
885894
}
886895

887896
[Fact]
@@ -891,17 +900,32 @@ public void Include_OneToMany() {
891900
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
892901
g.pgsql.Insert(model2).ExecuteAffrows();
893902

894-
var model3s = new[] {
895-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
896-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
897-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
903+
var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" };
904+
model3_1.id = (int)g.pgsql.Insert(model3_1).ExecuteIdentity();
905+
var model3_2 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" };
906+
model3_2.id = (int)g.pgsql.Insert(model3_2).ExecuteIdentity();
907+
var model3_3 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" };
908+
model3_3.id = (int)g.pgsql.Insert(model3_2).ExecuteIdentity();
909+
910+
var model4s = new[] {
911+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" },
912+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" },
913+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" },
914+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" },
915+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" }
898916
};
899-
Assert.Equal(3, g.pgsql.Insert(model3s).ExecuteAffrows());
917+
Assert.Equal(5, g.pgsql.Insert(model4s).ExecuteAffrows());
900918

901919
var t1 = g.pgsql.Select<TestInclude_OneToManyModel1>()
902920
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
903921
.Where(a => a.id <= model1.id)
904922
.ToList();
923+
924+
var t2 = g.pgsql.Select<TestInclude_OneToManyModel1>()
925+
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id),
926+
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id)))
927+
.Where(a => a.id <= model1.id)
928+
.ToList();
905929
}
906930
[Fact]
907931
public void Include_OneToChilds() {

FreeSql.Tests/SqlServer/Curd/SqlServerSelectTest.cs

+29-5
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,15 @@ public class TestInclude_OneToManyModel3 {
813813

814814
public int model2111Idaaa { get; set; }
815815
public string title { get; set; }
816+
817+
public List<TestInclude_OneToManyModel4> childs2 { get; set; }
818+
}
819+
public class TestInclude_OneToManyModel4 {
820+
[Column(IsIdentity = true)]
821+
public int id { get; set; }
822+
823+
public int model3333Id333 { get; set; }
824+
public string title444 { get; set; }
816825
}
817826

818827
[Fact]
@@ -822,17 +831,32 @@ public void Include_OneToMany() {
822831
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
823832
_sqlserverFixture.SqlServer.Insert(model2).ExecuteAffrows();
824833

825-
var model3s = new[] {
826-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
827-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
828-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
834+
var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" };
835+
model3_1.id = (int)_sqlserverFixture.SqlServer.Insert(model3_1).ExecuteIdentity();
836+
var model3_2 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" };
837+
model3_2.id = (int)_sqlserverFixture.SqlServer.Insert(model3_2).ExecuteIdentity();
838+
var model3_3 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" };
839+
model3_3.id = (int)_sqlserverFixture.SqlServer.Insert(model3_2).ExecuteIdentity();
840+
841+
var model4s = new[] {
842+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" },
843+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" },
844+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" },
845+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" },
846+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" }
829847
};
830-
Assert.Equal(3, _sqlserverFixture.SqlServer.Insert(model3s).ExecuteAffrows());
848+
Assert.Equal(5, _sqlserverFixture.SqlServer.Insert(model4s).ExecuteAffrows());
831849

832850
var t1 = _sqlserverFixture.SqlServer.Select<TestInclude_OneToManyModel1>()
833851
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
834852
.Where(a => a.id <= model1.id)
835853
.ToList();
854+
855+
var t2 = _sqlserverFixture.SqlServer.Select<TestInclude_OneToManyModel1>()
856+
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id),
857+
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id)))
858+
.Where(a => a.id <= model1.id)
859+
.ToList();
836860
}
837861
[Fact]
838862
public void Include_OneToChilds() {

FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs

+30-6
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,15 @@ public class TestInclude_OneToManyModel3 {
779779

780780
public int model2111Idaaa { get; set; }
781781
public string title { get; set; }
782+
783+
public List<TestInclude_OneToManyModel4> childs2 { get; set; }
784+
}
785+
public class TestInclude_OneToManyModel4 {
786+
[Column(IsIdentity = true)]
787+
public int id { get; set; }
788+
789+
public int model3333Id333 { get; set; }
790+
public string title444 { get; set; }
782791
}
783792

784793
[Fact]
@@ -788,15 +797,30 @@ public void Include_OneToMany() {
788797
var model2 = new TestInclude_OneToManyModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() };
789798
g.sqlite.Insert(model2).ExecuteAffrows();
790799

791-
var model3s = new [] {
792-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__111" },
793-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" },
794-
new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" }
800+
var model3_1 = new TestInclude_OneToManyModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" };
801+
model3_1.id = (int)g.sqlite.Insert(model3_1).ExecuteIdentity();
802+
var model3_2 =new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__222" };
803+
model3_2.id = (int)g.sqlite.Insert(model3_2).ExecuteIdentity();
804+
var model3_3 = new TestInclude_OneToManyModel3{ model2111Idaaa = model1.id, title = "testmodel3__333" };
805+
model3_3.id = (int)g.sqlite.Insert(model3_2).ExecuteIdentity();
806+
807+
var model4s = new[] {
808+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" },
809+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" },
810+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" },
811+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" },
812+
new TestInclude_OneToManyModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" }
795813
};
796-
Assert.Equal(3, g.sqlite.Insert(model3s).ExecuteAffrows());
814+
Assert.Equal(5, g.sqlite.Insert(model4s).ExecuteAffrows());
797815

798816
var t1 = g.sqlite.Select<TestInclude_OneToManyModel1>()
799-
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id && m3.title == a.model2.m2setting))
817+
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id))
818+
.Where(a => a.id <= model1.id)
819+
.ToList();
820+
821+
var t2 = g.sqlite.Select<TestInclude_OneToManyModel1>()
822+
.IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id),
823+
then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id)))
800824
.Where(a => a.id <= model1.id)
801825
.ToList();
802826
}

0 commit comments

Comments
 (0)