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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/StaticMethodInvocationToExtensionMethodInvocationTests.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
//
 
2
// StaticMethodInvocationToExtensionMethodInvocationTests.cs
 
3
//
 
4
// Author:
 
5
//       Simon Lindgren <simon.n.lindgren@gmail.com>
 
6
//
 
7
// Copyright (c) 2012 Simon Lindgren
 
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
 
 
30
namespace ICSharpCode.NRefactory.CSharp.CodeActions
 
31
{
 
32
 
 
33
        [TestFixture]
 
34
        public class StaticMethodInvocationToExtensionMethodInvocationTests : ContextActionTestBase
 
35
        {
 
36
 
 
37
                [Test]
 
38
                public void HandlesBasicCase()
 
39
                {
 
40
                        Test<StaticMethodInvocationToExtensionMethodInvocationAction>(@"
 
41
class A { }
 
42
static class B
 
43
{
 
44
        public static bool Ext (this A a, int i);
 
45
}
 
46
class C
 
47
{
 
48
        void F()
 
49
        {
 
50
                A a = new A();
 
51
                B.$Ext (a, 1);
 
52
        }
 
53
}", @"
 
54
class A { }
 
55
static class B
 
56
{
 
57
        public static bool Ext (this A a, int i);
 
58
}
 
59
class C
 
60
{
 
61
        void F()
 
62
        {
 
63
                A a = new A();
 
64
                a.Ext (1);
 
65
        }
 
66
}");
 
67
                }
 
68
 
 
69
                [Test]
 
70
                public void HandlesReturnValueUsage()
 
71
                {
 
72
                        Test<StaticMethodInvocationToExtensionMethodInvocationAction>(@"
 
73
class A { }
 
74
static class B
 
75
{
 
76
        public static void Ext (this A a, int i);
 
77
}
 
78
class C
 
79
{
 
80
        void F()
 
81
        {
 
82
                A a = new A();
 
83
                if (B.$Ext (a, 1))
 
84
                        return;
 
85
        }
 
86
}", @"
 
87
class A { }
 
88
static class B
 
89
{
 
90
        public static void Ext (this A a, int i);
 
91
}
 
92
class C
 
93
{
 
94
        void F()
 
95
        {
 
96
                A a = new A();
 
97
                if (a.Ext (1))
 
98
                        return;
 
99
        }
 
100
}");
 
101
                }
 
102
 
 
103
                [Test]
 
104
                public void IgnoresIfNullArgument()
 
105
                {
 
106
                        TestWrongContext<StaticMethodInvocationToExtensionMethodInvocationAction>(@"
 
107
class A { }
 
108
static class B
 
109
{
 
110
        public static void Ext (this A a);
 
111
}
 
112
class C
 
113
{
 
114
        void F()
 
115
        {
 
116
                B.$Ext (null);
 
117
        }
 
118
}");
 
119
                }
 
120
 
 
121
                [Test]
 
122
                public void IgnoresIfNotExtensionMethod()
 
123
                {
 
124
                        TestWrongContext<StaticMethodInvocationToExtensionMethodInvocationAction>(@"
 
125
class A { }
 
126
static class B
 
127
{
 
128
        public static void Ext (A a);
 
129
}
 
130
class C
 
131
{
 
132
        void F()
 
133
        {
 
134
                B.$Ext (new A());
 
135
        }
 
136
}");
 
137
                }
 
138
 
 
139
                [Test]
 
140
                public void IgnoresIfAlreadyExtensionMethodCallSyntax()
 
141
                {
 
142
                        TestWrongContext<StaticMethodInvocationToExtensionMethodInvocationAction>(@"
 
143
class A { }
 
144
static class B
 
145
{
 
146
        public static void Ext (this A a, int i);
 
147
}
 
148
class C
 
149
{
 
150
        void F()
 
151
        {
 
152
                A a = new A();
 
153
                a.$Ext (1);
 
154
        }
 
155
}");
 
156
                }
 
157
 
 
158
                [Test]
 
159
                public void IgnoresPropertyInvocation()
 
160
                {
 
161
                        TestWrongContext<StaticMethodInvocationToExtensionMethodInvocationAction>(@"
 
162
static class B
 
163
{
 
164
        public static int Ext { get; set; }
 
165
}
 
166
class C
 
167
{
 
168
        void F()
 
169
        {
 
170
                B.$Ext();
 
171
        }
 
172
}");
 
173
                }
 
174
        }
 
175
}