PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/pombredanne/SharpDevelop
C# | 139 lines | 109 code | 5 blank | 25 comment | 0 complexity | 71cb5aab4033c5fb64ccca05d21c027e 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. // PartOfBodyCanBeConvertedToQueryIssueTests.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 ICSharpCode.NRefactory.CSharp.CodeActions;
  27. using ICSharpCode.NRefactory.CSharp.Refactoring;
  28. using NUnit.Framework;
  29. namespace ICSharpCode.NRefactory.CSharp.CodeIssues
  30. {
  31. [Ignore]
  32. [TestFixture]
  33. public class PartOfBodyCanBeConvertedToQueryIssueTests : InspectionActionTestBase
  34. {
  35. [Test]
  36. public void TestWhere()
  37. {
  38. Test<LoopCanBeConvertedToQueryIssue>(@"
  39. using System;
  40. public class Bar
  41. {
  42. public void Foo (int[] i)
  43. {
  44. foreach (var x in i) {
  45. if (x < 10) {
  46. Console.WriteLine(x);
  47. }
  48. }
  49. }
  50. }
  51. ", @"
  52. using System;
  53. using System.Linq;
  54. public class Bar
  55. {
  56. public void Foo (int[] i)
  57. {
  58. foreach (var x in i.Where (x => x < 10)) {
  59. Console.WriteLine(x);
  60. }
  61. }
  62. }
  63. ");
  64. }
  65. [Test]
  66. public void TestOfType()
  67. {
  68. Test<LoopCanBeConvertedToQueryIssue>(@"
  69. using System;
  70. public class Bar
  71. {
  72. public void Foo(object[] i)
  73. {
  74. foreach (var x in i) {
  75. if (x is int) {
  76. Console.WriteLine(x);
  77. }
  78. }
  79. }
  80. }
  81. ", @"
  82. using System;
  83. using System.Linq;
  84. public class Bar
  85. {
  86. public void Foo(object[] i)
  87. {
  88. foreach (var x in i.OfType<int> ()) {
  89. Console.WriteLine(x);
  90. }
  91. }
  92. }
  93. ");
  94. }
  95. [Test]
  96. public void TestOfTypeTakeWhile()
  97. {
  98. Test<LoopCanBeConvertedToQueryIssue>(@"
  99. using System;
  100. public class Bar
  101. {
  102. public void Foo(object[] i)
  103. {
  104. foreach (var x in i) {
  105. if (x is int) {
  106. if ((int)x < 10)
  107. break;
  108. Console.WriteLine(x);
  109. }
  110. }
  111. }
  112. }
  113. ", @"
  114. using System;
  115. using System.Linq;
  116. public class Bar
  117. {
  118. public void Foo(object[] i)
  119. {
  120. foreach (var x in i.OfType<int> ().TakeWhile (x => x >= 10)) {
  121. Console.WriteLine(x);
  122. }
  123. }
  124. }
  125. ");
  126. }
  127. }
  128. }