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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ExtensionMethodInvocationToStaticMethodInvocationTests.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
// ExtensionMethodInvocationToStaticMethodInvocationTests.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 System;
 
27
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
28
using NUnit.Framework;
 
29
 
 
30
namespace ICSharpCode.NRefactory.CSharp.CodeActions
 
31
{
 
32
        [TestFixture]
 
33
        public class ExtensionMethodInvocationToStaticMethodInvocationTests : ContextActionTestBase
 
34
        {
 
35
 
 
36
                [Test]
 
37
                public void HandlesBasicCase()
 
38
                {
 
39
                        Test<ExtensionMethodInvocationToStaticMethodInvocationAction>(@"
 
40
class A { }
 
41
static class B
 
42
{
 
43
        public static void Ext (this A a, int i);
 
44
}
 
45
class C
 
46
{
 
47
        void F()
 
48
        {
 
49
                A a = new A();
 
50
                a.$Ext (1);
 
51
        }
 
52
}", @"
 
53
class A { }
 
54
static class B
 
55
{
 
56
        public static void Ext (this A a, int i);
 
57
}
 
58
class C
 
59
{
 
60
        void F()
 
61
        {
 
62
                A a = new A();
 
63
                B.Ext (a, 1);
 
64
        }
 
65
}");
 
66
                }
 
67
 
 
68
                [Test]
 
69
                public void HandlesReturnValueUsage()
 
70
                {
 
71
                        Test<ExtensionMethodInvocationToStaticMethodInvocationAction>(@"
 
72
class A { }
 
73
static class B
 
74
{
 
75
        public static bool Ext (this A a, int i)
 
76
        {
 
77
                return false;
 
78
        }
 
79
}
 
80
class C
 
81
{
 
82
        void F()
 
83
        {
 
84
                A a = new A();
 
85
                if (a.$Ext (1))
 
86
                        return;
 
87
        }
 
88
}", @"
 
89
class A { }
 
90
static class B
 
91
{
 
92
        public static bool Ext (this A a, int i)
 
93
        {
 
94
                return false;
 
95
        }
 
96
}
 
97
class C
 
98
{
 
99
        void F()
 
100
        {
 
101
                A a = new A();
 
102
                if (B.Ext (a, 1))
 
103
                        return;
 
104
        }
 
105
}");
 
106
                }
 
107
 
 
108
                [Test]
 
109
                public void IgnoresStaticMethodCalls()
 
110
                {
 
111
                        TestWrongContext<ExtensionMethodInvocationToStaticMethodInvocationAction>(@"
 
112
class A { }
 
113
static class B
 
114
{
 
115
        public static void Ext (this A a);
 
116
}
 
117
class C
 
118
{
 
119
        void F()
 
120
        {
 
121
                B.Ext (a, 1);
 
122
        }
 
123
}");
 
124
                }
 
125
 
 
126
                [Test]
 
127
                public void IgnoresRegularMemberMethodCalls()
 
128
                {
 
129
                        TestWrongContext<ExtensionMethodInvocationToStaticMethodInvocationAction>(@"
 
130
class A
 
131
{
 
132
        public void Ext (int i);
 
133
}
 
134
class C
 
135
{
 
136
        void F()
 
137
        {
 
138
                A a = new A();
 
139
                a.Ext (1);
 
140
        }
 
141
}");
 
142
                }
 
143
        }
 
144
}
 
145