PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/pombredanne/SharpDevelop
C# | 159 lines | 127 code | 7 blank | 25 comment | 0 complexity | 79653f4d19fcc97612f6eb9c7264deb0 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. // DuplicatedLinqToListOrArrayTests.cs
  3. //
  4. // Author:
  5. // Luís Reis <luiscubal@gmail.com>
  6. //
  7. // Copyright (c) 2013 Luís Reis
  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 ICSharpCode.NRefactory.CSharp.CodeActions;
  27. using ICSharpCode.NRefactory.CSharp.Refactoring;
  28. using NUnit.Framework;
  29. namespace ICSharpCode.NRefactory.CSharp.CodeIssues
  30. {
  31. public class DuplicatedLinqToListOrArrayTests : InspectionActionTestBase
  32. {
  33. [Test]
  34. public void TestDisabledForSingleUse()
  35. {
  36. Test<DuplicatedLinqToListOrArrayIssue>(@"
  37. using System.Linq;
  38. class TestClass
  39. {
  40. public void TestMethod()
  41. {
  42. var x = new int[0].ToList ();
  43. }
  44. }", 0);
  45. }
  46. [Test]
  47. public void TestSimpleCase()
  48. {
  49. Test<DuplicatedLinqToListOrArrayIssue>(@"
  50. using System.Linq;
  51. class TestClass
  52. {
  53. public void TestMethod()
  54. {
  55. var x = new int[0].ToList ().ToList ();
  56. }
  57. }", @"
  58. using System.Linq;
  59. class TestClass
  60. {
  61. public void TestMethod()
  62. {
  63. var x = new int[0].ToList ();
  64. }
  65. }");
  66. }
  67. [Test]
  68. public void TestToArray()
  69. {
  70. Test<DuplicatedLinqToListOrArrayIssue>(@"
  71. using System.Linq;
  72. class TestClass
  73. {
  74. public void TestMethod()
  75. {
  76. var x = new int[0].ToArray ().ToArray ();
  77. }
  78. }", @"
  79. using System.Linq;
  80. class TestClass
  81. {
  82. public void TestMethod()
  83. {
  84. var x = new int[0].ToArray ();
  85. }
  86. }");
  87. }
  88. [Test]
  89. public void TestMixed()
  90. {
  91. Test<DuplicatedLinqToListOrArrayIssue>(@"
  92. using System.Linq;
  93. class TestClass
  94. {
  95. public void TestMethod()
  96. {
  97. var x = new int[0].ToList ().ToArray ();
  98. }
  99. }", @"
  100. using System.Linq;
  101. class TestClass
  102. {
  103. public void TestMethod()
  104. {
  105. var x = new int[0].ToArray ();
  106. }
  107. }");
  108. }
  109. [Test]
  110. public void TestParenthesis()
  111. {
  112. Test<DuplicatedLinqToListOrArrayIssue>(@"
  113. using System.Linq;
  114. class TestClass
  115. {
  116. public void TestMethod()
  117. {
  118. var x = ((new int[0]).ToList ()).ToArray ();
  119. }
  120. }", @"
  121. using System.Linq;
  122. class TestClass
  123. {
  124. public void TestMethod()
  125. {
  126. var x = (new int[0]).ToArray ();
  127. }
  128. }");
  129. }
  130. [Test]
  131. public void TestTriple()
  132. {
  133. Test<DuplicatedLinqToListOrArrayIssue>(@"
  134. using System.Linq;
  135. class TestClass
  136. {
  137. public void TestMethod()
  138. {
  139. var x = new int[0].ToList ().ToArray ().ToArray ();
  140. }
  141. }", @"
  142. using System.Linq;
  143. class TestClass
  144. {
  145. public void TestMethod()
  146. {
  147. var x = new int[0].ToArray ();
  148. }
  149. }");
  150. }
  151. }
  152. }