From ac154ff752eec3689e3c9a1ff415af7a1c0ac682 Mon Sep 17 00:00:00 2001
From: bicijinlian <bicijinlian@163.com>
Date: Mon, 9 Sep 2019 14:51:07 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 LinqStudy.Test/LinqToObject/CreateTest.cs     | 43 +++++++++------
 LinqStudy.Test/LinqToObject/GroupTest.cs      |  5 +-
 LinqStudy.Test/LinqToObject/ProjectiveTest.cs | 52 +++++++------------
 .../LinqToObject/SequenceEqualTest.cs         |  3 +-
 LinqStudy.Test/LinqToObject/SetsTest.cs       |  4 +-
 LinqStudy.Test/LinqToObject/WhereTest.cs      |  5 +-
 LinqStudy.Test/Other/IndexersTest.cs          |  1 -
 7 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/LinqStudy.Test/LinqToObject/CreateTest.cs b/LinqStudy.Test/LinqToObject/CreateTest.cs
index cdcc4d1..f8ea03b 100644
--- a/LinqStudy.Test/LinqToObject/CreateTest.cs
+++ b/LinqStudy.Test/LinqToObject/CreateTest.cs
@@ -9,10 +9,11 @@ using FluentAssertions;
 namespace LinqStudy.Test.LinqToObject
 {
     /// <summary>
-    /// 生成操作符
+    ///  生成操作符
     /// </summary>
     public class CreateTest
     {
+        #region Empty
         /// <summary>
         ///  Empty 返回指定类型的空集,没有任何元素的集合。
         ///  Enumerable的静态方法,常用来做初始种子集合。
@@ -20,10 +21,10 @@ namespace LinqStudy.Test.LinqToObject
         [Fact]
         public void Empty_string_Test()
         {
-           var ini= Enumerable.Empty<string>();
+            var ini = Enumerable.Empty<string>();
 
-           Assert.IsType<string[]>(ini);
-           Assert.Empty(ini);
+            Assert.IsType<string[]>(ini);
+            Assert.Empty(ini);
         }
 
         /// <summary>
@@ -37,6 +38,9 @@ namespace LinqStudy.Test.LinqToObject
             Assert.IsType<Person[]>(ini);
             Assert.Empty(ini);
         }
+        #endregion
+
+        #region DefaultIfEmpty
 
         /// <summary>
         ///  DefaultIfEmpty
@@ -45,11 +49,12 @@ namespace LinqStudy.Test.LinqToObject
         [Fact]
         public void DefaultIfEmpty_Test()
         {
-            var defaultValue= Enumerable.DefaultIfEmpty(Enumerable.Empty<int>());
+            var defaultValue = Enumerable.DefaultIfEmpty(Enumerable.Empty<int>());
 
             Assert.Single(defaultValue);
             Assert.Equal(default(int), defaultValue.First());
         }
+
         /// <summary>
         /// 数据源为Null时,抛出异常。
         /// </summary>
@@ -61,6 +66,9 @@ namespace LinqStudy.Test.LinqToObject
             Assert.Single(defaultValue);
             Assert.Equal(default(Person), defaultValue.First());
         }
+        #endregion
+
+        #region Range
 
         /// <summary>
         /// Range:生成指定范围的整数序列
@@ -86,7 +94,8 @@ namespace LinqStudy.Test.LinqToObject
             //生成100项值均为"test@163.com"的字符串序列
             var values = Enumerable.Repeat("test@163.com", 100);
 
-            Array.ForEach(values.ToArray(), (emai) => {
+            Array.ForEach(values.ToArray(), (emai) =>
+            {
                 Assert.Equal("test@163.com", emai);
             });
         }
@@ -98,8 +107,8 @@ namespace LinqStudy.Test.LinqToObject
         public void Repeat_TestData_Test()
         {
             //生成测试数据:生成了有100项的一个序列,这100项均是对同一个对象的引用,而不是100个对象。
-
             Random rdm = new Random(DateTime.Now.Ticks.GetHashCode());
+    
             //虽然生成时,用了随机数,但是因对象只生成了一次,其它均是这个对象的浅拷贝,所以100个对象,完全相同:100个对同一对象的引用。
             var persons = Enumerable.Repeat(new Person()
             {
@@ -111,23 +120,26 @@ namespace LinqStudy.Test.LinqToObject
             Assert.Equal(100, persons.Count);
 
             //所有对象引用相同
-            Assert.All(persons, (p) => 
+            Assert.All(persons, (p) =>
             {
                 Assert.Same(persons[0], p);
             });
         }
 
+        #endregion
+
+        #region SequenceEqual
+
         /// <summary>
         ///  SequenceEqual: 比较源和目标序列,返回一个bool值,指示所含元素是否相同。
         /// </summary>
         [Fact]
         public void SequenceEqual_Test()
         {
-            Person p=new Person(){Id=1,Name="王小明",Age=20};
-
-            var s1=Enumerable.Repeat(p,100);
+            Person p = new Person() { Id = 1, Name = "王小明", Age = 20 };
 
-            var s2=Enumerable.Repeat(p,100);
+            var s1 = Enumerable.Repeat(p, 100);
+            var s2 = Enumerable.Repeat(p, 100);
 
             Assert.True(s1.SequenceEqual(s2));
         }
@@ -135,13 +147,14 @@ namespace LinqStudy.Test.LinqToObject
         [Fact]
         public void SequenceEqual_No_Test()
         {
-            Person p=new Person(){Id=1,Name="王小明",Age=20};
+            Person p = new Person() { Id = 1, Name = "王小明", Age = 20 };
 
-            var s1=Enumerable.Repeat(p,100);
+            var s1 = Enumerable.Repeat(p, 100);
 
-            var s2=Enumerable.Repeat(p,200);
+            var s2 = Enumerable.Repeat(p, 200);
 
             Assert.False(s1.SequenceEqual(s2));
         }
+        #endregion
     }
 }
diff --git a/LinqStudy.Test/LinqToObject/GroupTest.cs b/LinqStudy.Test/LinqToObject/GroupTest.cs
index 2da2993..9fd3943 100644
--- a/LinqStudy.Test/LinqToObject/GroupTest.cs
+++ b/LinqStudy.Test/LinqToObject/GroupTest.cs
@@ -39,7 +39,7 @@ namespace LinqStudy.Test.LinqToObject
         }
 
         /// <summary>
-        /// 延迟执行
+        ///  延迟执行
         /// </summary>
         [Fact]
         public void GroupBy_Delay_Test()
@@ -128,8 +128,9 @@ namespace LinqStudy.Test.LinqToObject
 
             Assert.Equal(expected,actual);
         }
+        
         /// <summary>
-        /// 重载4:keySelector elementSelector comparer
+        ///  重载4:keySelector elementSelector comparer
         /// </summary>
         [Fact]
         public void GroupBy_keySelector_elementSelector_comparer_Test()
diff --git a/LinqStudy.Test/LinqToObject/ProjectiveTest.cs b/LinqStudy.Test/LinqToObject/ProjectiveTest.cs
index 8dca176..696c4e6 100644
--- a/LinqStudy.Test/LinqToObject/ProjectiveTest.cs
+++ b/LinqStudy.Test/LinqToObject/ProjectiveTest.cs
@@ -16,6 +16,8 @@ namespace LinqStudy.Test.LinqToObject
     /// </summary>
     public class ProjectiveTest
     {
+        #region Select
+
         /// <summary>
         /// Select投影:简单投影,一对一
         /// </summary>
@@ -26,11 +28,12 @@ namespace LinqStudy.Test.LinqToObject
             var persons = PersonManager.GetPersons();
 
             // Act
-            var maps = persons.Select(p=>p.Age).ToList();
-            
+            var maps = persons.Select(p => p.Age).ToList();
+
             // Assert
             Assert.IsType<List<int>>(maps);
         }
+
         /// <summary>
         /// 投影为匿名类
         /// </summary>
@@ -41,8 +44,8 @@ namespace LinqStudy.Test.LinqToObject
             var persons = PersonManager.GetPersons();
 
             // Act
-            var maps = persons.Select(p=>new {Id=p.Id, Node=$"姓名{p.Name},年龄{p.Age}."}).ToList();
-            
+            var maps = persons.Select(p => new { Id = p.Id, Node = $"姓名{p.Name},年龄{p.Age}." }).ToList();
+
             // Assert
             Assert.IsNotType<List<Person>>(maps);
         }
@@ -55,12 +58,15 @@ namespace LinqStudy.Test.LinqToObject
         {
             var persons = PersonManager.GetPersons();
 
-            var maps = persons.Select((query,index)=> new KeyValuePair<int, Person>(index,query)).ToList();
+            var maps = persons.Select((query, index) => new KeyValuePair<int, Person>(index, query)).ToList();
             var indexs = persons.Select((query, index) => index).ToList();
 
             Assert.IsType<List<KeyValuePair<int, Person>>>(maps);
-            Assert.Equal(0,indexs[0]);
+            Assert.Equal(0, indexs[0]);
         }
+        #endregion
+
+        #region SelectMany
 
         /// <summary>
         ///  将序列的每个元素投影到 IEnumerable<TResult> 并将结果序列合并为一个序列。
@@ -82,7 +88,7 @@ namespace LinqStudy.Test.LinqToObject
                 new Employee(){Id=5,Name="东升",Emails=new List<string>(){ "ebc@163.com", "ecd@163.com", "ede@163.com" }},
             };
 
-            var maps = employees.SelectMany(q=>q.Emails).ToList();
+            var maps = employees.SelectMany(q => q.Emails).ToList();
 
             Assert.IsType<List<string>>(maps);
             Assert.Equal(15, maps.Count);
@@ -106,7 +112,7 @@ namespace LinqStudy.Test.LinqToObject
                 new Employee(){Id=5,Name="东升",Emails=new List<string>(){ "ebc@163.com", "ecd@163.com", "ede@163.com" }},
             };
 
-            var maps = employees.SelectMany((q, idx) => 
+            var maps = employees.SelectMany((q, idx) =>
             {
                 q.Emails.Add(idx.ToString());
                 return q.Emails;
@@ -134,7 +140,7 @@ namespace LinqStudy.Test.LinqToObject
                 new Employee(){ Id=5,Name="东升",Emails=new List<string>(){ "e1@163.com", "e2@163.com", "e3@163.com" } },
             };
 
-            var maps = employees.SelectMany((employee)=> employee.Emails,(person,email)=> new { Name=person.Name,Email=email}).ToList();
+            var maps = employees.SelectMany((employee) => employee.Emails, (person, email) => new { Name = person.Name, Email = email }).ToList();
 
             Assert.Equal(15, maps.Count);
         }
@@ -160,12 +166,12 @@ namespace LinqStudy.Test.LinqToObject
 
             var maps = employees.SelectMany
             (
-                (employee, idx) => 
+                (employee, idx) =>
                 {
                     return new List<Employee>() { new Employee() { Id = employee.Id, Name = employee.Name + "_" + idx, Emails = employee.Emails } };
-                }, 
+                },
 
-                (person,email) => new
+                (person, email) => new
                 {
                     Name = email.Name,
                     Email = email.Emails
@@ -175,26 +181,6 @@ namespace LinqStudy.Test.LinqToObject
 
             Assert.Equal(5, maps.Count);
         }
-
-        [Fact]
-        public void Test()
-        {
-            var cc= DocDemo("");
-        }
-
-        /// <summary>
-        ///  Doc示例
-        /// </summary>
-        /// <param name="aa">参数</param>
-        /// <exception cref="ArgumentNullException">
-        ///   ArgumentNullException
-        /// </exception>
-        /// <example>DecDemo("dsfsadf")</example>
-        /// <seealso cref="SortedDictionary{TKey, TValue}"/>
-        /// <returns>参数+“-”</returns>
-        private string DocDemo(string aa)
-        {
-            return aa + "-";
-        }
+        #endregion
     }
 }
diff --git a/LinqStudy.Test/LinqToObject/SequenceEqualTest.cs b/LinqStudy.Test/LinqToObject/SequenceEqualTest.cs
index 79dd73d..9a3b75f 100644
--- a/LinqStudy.Test/LinqToObject/SequenceEqualTest.cs
+++ b/LinqStudy.Test/LinqToObject/SequenceEqualTest.cs
@@ -14,6 +14,7 @@ namespace LinqStudy.Test.LinqToObject
     /// </summary>
     public class SequenceEqualTest
     {
+        #region SequenceEqual
         /// <summary>
         ///  SequenceEqual
         ///  序列相等比较:所含项数量相同、内容相同、位置相同、引用类型则引用相同的对象,则两个序列相等。
@@ -60,7 +61,6 @@ namespace LinqStudy.Test.LinqToObject
         [Fact]
         public void SequenceEqual_ValueType_Test()
         {
-
             List<int> sequence1 = new List<int>() { 1, 2, 3 };
 
             List<int> sequence2 = new List<int>() { 1, 2, 3 };
@@ -194,5 +194,6 @@ namespace LinqStudy.Test.LinqToObject
 
             Assert.True(sequence1.SequenceEqual(sequence2, new PersonEqualityComparer()));
         }
+        #endregion
     }
 }
diff --git a/LinqStudy.Test/LinqToObject/SetsTest.cs b/LinqStudy.Test/LinqToObject/SetsTest.cs
index 12d8ff8..ced4bd1 100644
--- a/LinqStudy.Test/LinqToObject/SetsTest.cs
+++ b/LinqStudy.Test/LinqToObject/SetsTest.cs
@@ -7,8 +7,8 @@ using Xunit;
 namespace LinqStudy.Test.LinqToObject
 {
     /// <summary>
-    /// Sets 集合操作符
-    /// 注意:集合操作为 “延迟执行”,数据源为null时均引发异常。
+    ///  Sets 集合操作符
+    ///  注意:集合操作为 “延迟执行”,数据源为null时均引发异常。
     /// </summary>
     public class SetsTest
     {
diff --git a/LinqStudy.Test/LinqToObject/WhereTest.cs b/LinqStudy.Test/LinqToObject/WhereTest.cs
index fc54e67..9d5661b 100644
--- a/LinqStudy.Test/LinqToObject/WhereTest.cs
+++ b/LinqStudy.Test/LinqToObject/WhereTest.cs
@@ -13,6 +13,8 @@ namespace LinqStudy.Test.LinqToObject
     /// </summary>
     public class WhereTest
     {
+        #region Where
+
         /// <summary>
         /// where:过滤查询条件
         /// </summary>
@@ -39,9 +41,10 @@ namespace LinqStudy.Test.LinqToObject
         {
             List<Person> Persons = null;
 
-            Action act = ()=> { Persons.Where(p => p.Name.StartsWith("zhang")); };
+            Action act = () => { Persons.Where(p => p.Name.StartsWith("zhang")); };
 
             Assert.Throws<ArgumentNullException>(act);
         }
+        #endregion
     }
 }
diff --git a/LinqStudy.Test/Other/IndexersTest.cs b/LinqStudy.Test/Other/IndexersTest.cs
index 42e6e0b..6fdf5b4 100644
--- a/LinqStudy.Test/Other/IndexersTest.cs
+++ b/LinqStudy.Test/Other/IndexersTest.cs
@@ -76,6 +76,5 @@ namespace LinqStudy.Test.Other
                 Employees[idx] = value;
             }
         }
-        
     }
 }