PageRenderTime 45ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/pombredanne/SharpDevelop
C# | 94 lines | 63 code | 6 blank | 25 comment | 0 complexity | e7dfb094aac59f1d2fbf68323ec39952 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. // ReplaceWithOfTypeWhereIssueTests.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 ReplaceWithOfTypeWhereIssueTests : InspectionActionTestBase
  34. {
  35. [Test]
  36. public void TestCaseBasicWithFollowUpExpresison ()
  37. {
  38. Test<ReplaceWithOfTypeWhereIssue>(@"using System.Linq;
  39. class Test
  40. {
  41. public void Foo(object[] obj)
  42. {
  43. obj.Select (q => q as Test).Where (q => q != null && Foo (q));
  44. }
  45. }", @"using System.Linq;
  46. class Test
  47. {
  48. public void Foo(object[] obj)
  49. {
  50. obj.OfType<Test> ().Where (q => Foo (q));
  51. }
  52. }");
  53. }
  54. [Test]
  55. public void TestDisable ()
  56. {
  57. TestWrongContext<ReplaceWithOfTypeWhereIssue>(@"using System.Linq;
  58. class Test
  59. {
  60. public void Foo(object[] obj)
  61. {
  62. // ReSharper disable once ReplaceWithOfType.Where
  63. obj.Select (q => q as Test).Where (q => q != null);
  64. }
  65. }");
  66. }
  67. [Test]
  68. public void TestJunk ()
  69. {
  70. TestWrongContext<ReplaceWithOfTypeWhereIssue>(@"using System.Linq;
  71. class Test
  72. {
  73. public void Foo(object[] obj)
  74. {
  75. obj.Select (x => q as Test).Where (q => q != null && true);
  76. }
  77. }");
  78. TestWrongContext<ReplaceWithOfTypeWhereIssue>(@"using System.Linq;
  79. class Test
  80. {
  81. public void Foo(object[] obj)
  82. {
  83. obj.Select (q => q as Test).Where (q => 1 != null && true);
  84. }
  85. }");
  86. }
  87. }
  88. }