PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/SimplifyLinqExpressionIssueTests.cs

https://github.com/pombredanne/SharpDevelop
C# | 193 lines | 159 code | 9 blank | 25 comment | 0 complexity | d310a15328d0471518cd7f25a4f1bc26 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, Apache-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-3.0
  1. //
  2. // SimplifyLinqExpressionIssueTests.cs
  3. //
  4. // Author:
  5. // Mike Kr端ger <mkrueger@xamarin.com>
  6. //
  7. // Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using ICSharpCode.NRefactory.CSharp.Refactoring;
  28. using NUnit.Framework;
  29. namespace ICSharpCode.NRefactory.CSharp.CodeIssues
  30. {
  31. [TestFixture]
  32. public class SimplifyLinqExpressionIssueTests : InspectionActionTestBase
  33. {
  34. [Test]
  35. public void TestNotAny ()
  36. {
  37. Test<SimplifyLinqExpressionIssue>(@"
  38. using System;
  39. using System.Linq;
  40. class FooBar
  41. {
  42. void Test (string[] args)
  43. {
  44. Console.WriteLine (!args.Any (d => d.Length == 0));
  45. }
  46. }
  47. ", @"
  48. using System;
  49. using System.Linq;
  50. class FooBar
  51. {
  52. void Test (string[] args)
  53. {
  54. Console.WriteLine (args.All (d => d.Length != 0));
  55. }
  56. }
  57. ");
  58. }
  59. [Test]
  60. public void TestNotAll ()
  61. {
  62. Test<SimplifyLinqExpressionIssue>(@"
  63. using System;
  64. using System.Linq;
  65. class FooBar
  66. {
  67. void Test (string[] args)
  68. {
  69. Console.WriteLine (!args.All (d => d.Length == 0));
  70. }
  71. }
  72. ", @"
  73. using System;
  74. using System.Linq;
  75. class FooBar
  76. {
  77. void Test (string[] args)
  78. {
  79. Console.WriteLine (args.Any (d => d.Length != 0));
  80. }
  81. }
  82. ");
  83. }
  84. [Test]
  85. public void TestLambdaBlockNotAny ()
  86. {
  87. Test<SimplifyLinqExpressionIssue>(@"
  88. using System;
  89. using System.Linq;
  90. class FooBar
  91. {
  92. void Test (string[] args)
  93. {
  94. Console.WriteLine (!args.Any (d => {
  95. return d.Length == 0;
  96. }));
  97. }
  98. }
  99. ", @"
  100. using System;
  101. using System.Linq;
  102. class FooBar
  103. {
  104. void Test (string[] args)
  105. {
  106. Console.WriteLine (args.All (d => {
  107. return d.Length != 0;
  108. }));
  109. }
  110. }
  111. ");
  112. }
  113. [Test]
  114. public void TestAnonymousMethodBlockNotAny ()
  115. {
  116. Test<SimplifyLinqExpressionIssue>(@"
  117. using System;
  118. using System.Linq;
  119. class FooBar
  120. {
  121. void Test (string[] args)
  122. {
  123. Console.WriteLine (!args.Any (delegate (string d) {
  124. return d.Length == 0;
  125. }));
  126. }
  127. }
  128. ", @"
  129. using System;
  130. using System.Linq;
  131. class FooBar
  132. {
  133. void Test (string[] args)
  134. {
  135. Console.WriteLine (args.All (delegate (string d) {
  136. return d.Length != 0;
  137. }));
  138. }
  139. }
  140. ");
  141. }
  142. [Test]
  143. public void TestNoSimplifiction ()
  144. {
  145. TestWrongContext<SimplifyLinqExpressionIssue>(@"
  146. using System;
  147. using System.Linq;
  148. class FooBar
  149. {
  150. void Test (object[] args)
  151. {
  152. Console.WriteLine (!args.Any (d => d is FooBar));
  153. }
  154. }
  155. ");
  156. }
  157. [Test]
  158. public void TestDisable ()
  159. {
  160. TestWrongContext<SimplifyLinqExpressionIssue>(@"
  161. using System;
  162. using System.Linq;
  163. class FooBar
  164. {
  165. void Test (string[] args)
  166. {
  167. // ReSharper disable once SimplifyLinqExpression
  168. Console.WriteLine (!args.Any (d => d.Length == 0));
  169. }
  170. }
  171. ");
  172. }
  173. }
  174. }