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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/PutInsideUsingTests.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
// PutInsideUsingAction.cs
 
3
//  
 
4
// Author:
 
5
//       Mansheng Yang <lightyang0@gmail.com>
 
6
// 
 
7
// Copyright (c) 2012 Mansheng Yang <lightyang0@gmail.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
 
 
27
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
28
using NUnit.Framework;
 
29
 
 
30
namespace ICSharpCode.NRefactory.CSharp.CodeActions
 
31
{
 
32
        [TestFixture]
 
33
        public class PutInsideUsingTests : ContextActionTestBase
 
34
        {
 
35
                [Test]
 
36
                public void Test ()
 
37
                {
 
38
                        Test<PutInsideUsingAction> (@"
 
39
interface ITest : System.IDisposable
 
40
{
 
41
        void Test ();
 
42
}
 
43
class TestClass
 
44
{
 
45
        void TestMethod (int i)
 
46
        {
 
47
                ITest obj $= null;
 
48
                obj.Test ();
 
49
                int a;
 
50
                if (i > 0)
 
51
                        obj.Test ();
 
52
                a = 0;
 
53
        }
 
54
}", @"
 
55
interface ITest : System.IDisposable
 
56
{
 
57
        void Test ();
 
58
}
 
59
class TestClass
 
60
{
 
61
        void TestMethod (int i)
 
62
        {
 
63
                int a;
 
64
                using (ITest obj = null) {
 
65
                        obj.Test ();
 
66
                        if (i > 0)
 
67
                                obj.Test ();
 
68
                }
 
69
                a = 0;
 
70
        }
 
71
}");
 
72
                }
 
73
 
 
74
                [Test]
 
75
                public void TestIDisposable ()
 
76
                {
 
77
                        Test<PutInsideUsingAction> (@"
 
78
class TestClass
 
79
{
 
80
        void TestMethod ()
 
81
        {
 
82
                System.IDisposable obj $= null;
 
83
                obj.Method ();
 
84
        }
 
85
}", @"
 
86
class TestClass
 
87
{
 
88
        void TestMethod ()
 
89
        {
 
90
                using (System.IDisposable obj = null) {
 
91
                        obj.Method ();
 
92
                }
 
93
        }
 
94
}");
 
95
                }
 
96
                
 
97
                [Test]
 
98
                public void TestTypeParameter ()
 
99
                {
 
100
 
 
101
                        Test<PutInsideUsingAction> (@"
 
102
class TestClass
 
103
{
 
104
        void TestMethod<T> ()
 
105
                where T : System.IDisposable, new()
 
106
        {
 
107
                T obj $= new T ();
 
108
                obj.Method ();
 
109
        }
 
110
}", @"
 
111
class TestClass
 
112
{
 
113
        void TestMethod<T> ()
 
114
                where T : System.IDisposable, new()
 
115
        {
 
116
                using (T obj = new T ()) {
 
117
                        obj.Method ();
 
118
                }
 
119
        }
 
120
}");
 
121
                }
 
122
                
 
123
                [Test]
 
124
                public void TestMultipleVariablesDeclaration ()
 
125
                {
 
126
                        Test<PutInsideUsingAction> (@"
 
127
class TestClass
 
128
{
 
129
        void TestMethod ()
 
130
        {
 
131
                System.IDisposable obj, obj2 $= null, obj3;
 
132
                obj2.Method ();
 
133
        }
 
134
}", @"
 
135
class TestClass
 
136
{
 
137
        void TestMethod ()
 
138
        {
 
139
                System.IDisposable obj, obj3;
 
140
                using (System.IDisposable obj2 = null) {
 
141
                        obj2.Method ();
 
142
                }
 
143
        }
 
144
}");
 
145
                }
 
146
 
 
147
                [Test]
 
148
                public void TestNullInitializer ()
 
149
                {
 
150
                        TestWrongContext<PutInsideUsingAction> (@"
 
151
class TestClass
 
152
{
 
153
        void TestMethod ()
 
154
        {
 
155
                System.IDisposable $obj;
 
156
                obj.Method ();
 
157
        }
 
158
}");
 
159
                }
 
160
 
 
161
                [Test]
 
162
                public void TestMoveVariableDeclaration ()
 
163
                {
 
164
                        Test<PutInsideUsingAction> (@"
 
165
class TestClass
 
166
{
 
167
        void TestMethod ()
 
168
        {
 
169
                System.IDisposable obj $= null;
 
170
                int a, b;
 
171
                a = b = 0;
 
172
                obj.Method ();
 
173
                a++;
 
174
        }
 
175
}", @"
 
176
class TestClass
 
177
{
 
178
        void TestMethod ()
 
179
        {
 
180
                int a;
 
181
                using (System.IDisposable obj = null) {
 
182
                        int b;
 
183
                        a = b = 0;
 
184
                        obj.Method ();
 
185
                }
 
186
                a++;
 
187
        }
 
188
}");
 
189
                }
 
190
 
 
191
                [Test]
 
192
                public void TestRemoveDisposeInvocation ()
 
193
                {
 
194
                        Test<PutInsideUsingAction> (@"
 
195
class TestClass
 
196
{
 
197
        void TestMethod ()
 
198
        {
 
199
                System.IDisposable obj $= null;
 
200
                obj.Method ();
 
201
                obj.Dispose();
 
202
        }
 
203
}", @"
 
204
class TestClass
 
205
{
 
206
        void TestMethod ()
 
207
        {
 
208
                using (System.IDisposable obj = null) {
 
209
                        obj.Method ();
 
210
                }
 
211
        }
 
212
}");
 
213
                }
 
214
        }
 
215
 
 
216
}