diff --git a/LinqStudy.Test/LinqToObject/ConcatTest.cs b/LinqStudy.Test/LinqToObject/ConcatTest.cs deleted file mode 100644 index ed3cb75..0000000 --- a/LinqStudy.Test/LinqToObject/ConcatTest.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -using Xunit; -using LinqStudy; - -namespace LinqStudy.Test.LinqToObject -{ - /// - /// 串联操作 - /// - public class ConcatTest - { - /// - /// Concat:将两个序列合并成一个序列,不去重。与Union不同。 - /// - public void Concat_Test() - { - List peoples1 = new List() - { - new Person(){ Id=2, Name="小龙女", Age=28}, - new Person(){ Id=4, Name="杨过", Age=32}, - }; - - List peoples2 = new List() - { - new Person(){ Id=2, Name="小龙女", Age=28}, - new Person(){ Id=3, Name="云花公主", Age=16}, - }; - - var concatAct = peoples1.Concat(peoples2); - - var totalCount = concatAct.Count(); - - Assert.Equal(4, totalCount); - } - } -} \ No newline at end of file diff --git a/LinqStudy.Test/LinqToObject/JoinTest.cs b/LinqStudy.Test/LinqToObject/JoinTest.cs new file mode 100644 index 0000000..f4fa033 --- /dev/null +++ b/LinqStudy.Test/LinqToObject/JoinTest.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +using Xunit; +using LinqStudy; + +namespace LinqStudy.Test.LinqToObject +{ + /// + /// 联接操作:将一个数据源对象与另一个数据源对象进行关联或联合的操作。 + /// 延迟执行 + /// 数据源为null,均引发异常 + /// + public class JoinTest + { + #region Jion + /// + /// Jion:将一个数据源与另一个数据源相联接,根据两个数据源中相等的值进行匹配; + /// 类似T-SQL中的Inner Join + /// 延迟执行 + /// + [Fact] + public void Jion_Test() + { + List peoples = new List() + { + new Person(){ Id=1, Name="小龙女",Age=18 }, + new Person(){ Id=2, Name="郭靖",Age=28 }, + }; + + List teachers = new List() + { + new Teacher(){ Id=1, Name="杨过老师",Hometown=new Hometown(){ Province="终南山",City="古墓"} }, + new Teacher(){ Id=2, Name="郭老师",Hometown=new Hometown(){ Province="湖北省",City="襄阳"} }, + new Teacher(){ Id=3, Name="金轮法师",Hometown=new Hometown(){ Province="西藏",City="游民"} }, + }; + + var jionItem = peoples.Join + ( + teachers, p => p.Id, + t => t.Id, + (p, t) => new + { + Id = 1, + Name = p.Name + "-" + t.Name, + Age = 18, + Hometown = t.Hometown + } + ) + .ToList(); + + Assert.Equal(2, jionItem.Count); + } + #endregion + + #region GroupJion + #endregion + } +} \ No newline at end of file diff --git a/LinqStudy.Test/LinqToObject/OrderTest.cs b/LinqStudy.Test/LinqToObject/OrderTest.cs index f74bec9..c4b6f75 100644 --- a/LinqStudy.Test/LinqToObject/OrderTest.cs +++ b/LinqStudy.Test/LinqToObject/OrderTest.cs @@ -58,7 +58,7 @@ namespace LinqStudy.Test.LinqToObject var lastName = oprationItem.Last().Name; Assert.Equal("张三", firtName); - Assert.Equal("王五", lastName); + Assert.Equal("赵六", lastName); } /// diff --git a/LinqStudy.Test/LinqToObject/SetsTest.cs b/LinqStudy.Test/LinqToObject/SetsTest.cs index 86e5380..12d8ff8 100644 --- a/LinqStudy.Test/LinqToObject/SetsTest.cs +++ b/LinqStudy.Test/LinqToObject/SetsTest.cs @@ -381,5 +381,37 @@ namespace LinqStudy.Test.LinqToObject Assert.Equal("杨过", iexcepItemName); } #endregion + + #region Concat + /// + /// 串联操作 + /// + public class ConcatTest + { + /// + /// Concat:将两个序列合并成一个序列,不去重。与Union不同。 + /// + public void Concat_Test() + { + List peoples1 = new List() + { + new Person(){ Id=2, Name="小龙女", Age=28}, + new Person(){ Id=4, Name="杨过", Age=32}, + }; + + List peoples2 = new List() + { + new Person(){ Id=2, Name="小龙女", Age=28}, + new Person(){ Id=3, Name="云花公主", Age=16}, + }; + + var concatAct = peoples1.Concat(peoples2); + + var totalCount = concatAct.Count(); + + Assert.Equal(4, totalCount); + } + } + #endregion } } \ No newline at end of file