PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/pombredanne/SharpDevelop
C# | 114 lines | 82 code | 7 blank | 25 comment | 0 complexity | d644181d3ffbebc4ce921180be2538fd 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. // ReplaceWithOfTypeLongCountIssueTests.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 NUnit.Framework;
  28. using ICSharpCode.NRefactory.CSharp.Refactoring;
  29. using ICSharpCode.NRefactory.CSharp.CodeActions;
  30. namespace ICSharpCode.NRefactory.CSharp.CodeIssues
  31. {
  32. [TestFixture]
  33. public class ReplaceWithOfTypeLongCountIssueTests : InspectionActionTestBase
  34. {
  35. [Test]
  36. public void TestCaseBasic ()
  37. {
  38. Test<ReplaceWithOfTypeLongCountIssue>(@"using System.Linq;
  39. class Test
  40. {
  41. public void Foo(object[] obj)
  42. {
  43. obj.Select (q => q as Test).LongCount (q => q != null);
  44. }
  45. }", @"using System.Linq;
  46. class Test
  47. {
  48. public void Foo(object[] obj)
  49. {
  50. obj.OfType<Test> ().LongCount ();
  51. }
  52. }");
  53. }
  54. [Test]
  55. public void TestCaseBasicWithFollowUpExpresison ()
  56. {
  57. Test<ReplaceWithOfTypeLongCountIssue>(@"using System.Linq;
  58. class Test
  59. {
  60. public void Foo(object[] obj)
  61. {
  62. obj.Select (q => q as Test).LongCount (q => q != null && Foo (q));
  63. }
  64. }", @"using System.Linq;
  65. class Test
  66. {
  67. public void Foo(object[] obj)
  68. {
  69. obj.OfType<Test> ().LongCount (q => Foo (q));
  70. }
  71. }");
  72. }
  73. [Test]
  74. public void TestDisable ()
  75. {
  76. TestWrongContext<ReplaceWithOfTypeLongCountIssue>(@"using System.Linq;
  77. class Test
  78. {
  79. public void Foo(object[] obj)
  80. {
  81. // ReSharper disable once ReplaceWithOfType.LongCount
  82. obj.Select (q => q as Test).LongCount (q => q != null);
  83. }
  84. }");
  85. }
  86. [Test]
  87. public void TestJunk ()
  88. {
  89. TestWrongContext<ReplaceWithOfTypeLongCountIssue>(@"using System.Linq;
  90. class Test
  91. {
  92. public void Foo(object[] obj)
  93. {
  94. obj.Select (x => q as Test).LongCount (q => q != null);
  95. }
  96. }");
  97. TestWrongContext<ReplaceWithOfTypeLongCountIssue>(@"using System.Linq;
  98. class Test
  99. {
  100. public void Foo(object[] obj)
  101. {
  102. obj.Select (q => q as Test).LongCount (q => 1 != null);
  103. }
  104. }");
  105. }
  106. }
  107. }