~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantWhereWithPredicateIssueTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using NUnit.Framework;
 
3
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
4
using ICSharpCode.NRefactory.CSharp.CodeActions;
 
5
 
 
6
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
 
7
{
 
8
        [TestFixture]
 
9
        public class RedundantWhereWithPredicateIssueTests : InspectionActionTestBase
 
10
        {
 
11
                [Test]
 
12
                public void TestWhereAnyCase1 ()
 
13
                {
 
14
                        var input = @"using System.Linq;
 
15
public class CSharpDemo {
 
16
        public void Bla () {
 
17
                int[] arr;
 
18
                var bla = arr.Where (x => x < 4).Any ();
 
19
        }
 
20
}";
 
21
                        
 
22
                        TestRefactoringContext context;
 
23
                        var issues = GetIssues (new RedundantWhereWithPredicateIssue (), input, out context);
 
24
                        Assert.AreEqual (1, issues.Count);
 
25
                        CheckFix (context, issues, @"using System.Linq;
 
26
public class CSharpDemo {
 
27
        public void Bla () {
 
28
                int[] arr;
 
29
                var bla = arr.Any (x => x < 4);
 
30
        }
 
31
}");
 
32
                }
 
33
                
 
34
                [Test]
 
35
                public void TestWhereAnyWrongWhere1 ()
 
36
                {
 
37
                        var input = @"using System.Linq;
 
38
public class CSharpDemo {
 
39
        public void Bla () {
 
40
                int[] arr;
 
41
                var bla = arr.Where ((x, i) => x + i < 4).Any ();
 
42
        }
 
43
}";
 
44
                        
 
45
                        TestRefactoringContext context;
 
46
                        var issues = GetIssues (new RedundantWhereWithPredicateIssue (), input, out context);
 
47
                        Assert.AreEqual (0, issues.Count);
 
48
                }
 
49
                
 
50
                [Test]
 
51
                public void TestWhereAnyWrongWhere2 ()
 
52
                {
 
53
                        var input = @"using System;
 
54
using System.Linq;
 
55
public class X
 
56
{
 
57
        X Where (Func<int,int> f) { return null; }
 
58
        bool Any () { return false; }
 
59
        public void Bla () {
 
60
                X ex = null;
 
61
                var bla = ex.Where (x => x + 1).Any ();
 
62
        }
 
63
}";
 
64
                        
 
65
                        TestRefactoringContext context;
 
66
                        var issues = GetIssues (new RedundantWhereWithPredicateIssue (), input, out context);
 
67
                        Assert.AreEqual (0, issues.Count);
 
68
                }
 
69
                
 
70
                [Test]
 
71
                public void TestWhereCount()
 
72
                {
 
73
                        var input = @"using System.Linq;
 
74
public class CSharpDemo {
 
75
        public void Bla () {
 
76
                int[] arr;
 
77
                var bla = arr.Where (x => x < 4).Count ();
 
78
        }
 
79
}";
 
80
                        
 
81
                        TestRefactoringContext context;
 
82
                        var issues = GetIssues (new RedundantWhereWithPredicateIssue (), input, out context);
 
83
                        Assert.AreEqual (1, issues.Count);
 
84
                        CheckFix (context, issues, @"using System.Linq;
 
85
public class CSharpDemo {
 
86
        public void Bla () {
 
87
                int[] arr;
 
88
                var bla = arr.Count (x => x < 4);
 
89
        }
 
90
}");
 
91
                }
 
92
        }
 
93
}