5
// Mike KrĆ¼ger <mkrueger@xamarin.com>
7
// Copyright (c) 2012 Xamarin <http://xamarin.com>
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
27
using NUnit.Framework;
28
using ICSharpCode.NRefactory.CSharp.Refactoring;
30
namespace ICSharpCode.NRefactory.CSharp.CodeActions
33
public class CreateFieldTests : ContextActionTestBase
36
public void TestWrongContext2 ()
38
TestWrongContext<CreateFieldAction> (
39
"using System;" + Environment.NewLine +
40
"class TestClass" + Environment.NewLine +
41
"{" + Environment.NewLine +
42
" void Test ()" + Environment.NewLine +
43
" {" + Environment.NewLine +
44
" Console.WriteLine ($Foo());" + Environment.NewLine +
45
" }" + Environment.NewLine +
51
public void TestWrongContext3 ()
53
// May be syntactically possible, but very unlikely.
54
TestWrongContext<CreateFieldAction> (
55
"using System;" + Environment.NewLine +
56
"class TestClass" + Environment.NewLine +
57
"{" + Environment.NewLine +
58
" void Test ()" + Environment.NewLine +
59
" {" + Environment.NewLine +
60
" $foo();" + Environment.NewLine +
61
" }" + Environment.NewLine +
67
public void TestSimpleMethodCall ()
69
string result = RunContextAction (
70
new CreateFieldAction (),
71
"using System;" + Environment.NewLine +
72
"class TestClass" + Environment.NewLine +
73
"{" + Environment.NewLine +
74
" void Test ()" + Environment.NewLine +
75
" {" + Environment.NewLine +
76
" Console.WriteLine ($foo);" + Environment.NewLine +
77
" }" + Environment.NewLine +
80
Console.WriteLine (result);
82
"using System;" + Environment.NewLine +
83
"class TestClass" + Environment.NewLine +
84
"{" + Environment.NewLine +
85
" object foo;" + Environment.NewLine +
86
" void Test ()" + Environment.NewLine +
87
" {" + Environment.NewLine +
88
" Console.WriteLine (foo);" + Environment.NewLine +
89
" }" + Environment.NewLine +
94
public void TestAssignment ()
96
string result = RunContextAction (
97
new CreateFieldAction (),
98
"using System;" + Environment.NewLine +
99
"class TestClass" + Environment.NewLine +
100
"{" + Environment.NewLine +
101
" void Test ()" + Environment.NewLine +
102
" {" + Environment.NewLine +
103
" $foo = 0x10;" + Environment.NewLine +
104
" }" + Environment.NewLine +
109
"using System;" + Environment.NewLine +
110
"class TestClass" + Environment.NewLine +
111
"{" + Environment.NewLine +
112
" int foo;" + Environment.NewLine +
113
" void Test ()" + Environment.NewLine +
114
" {" + Environment.NewLine +
115
" foo = 0x10;" + Environment.NewLine +
116
" }" + Environment.NewLine +
121
public void TestOutParamCall ()
123
string result = RunContextAction (
124
new CreateFieldAction (),
125
"using System;" + Environment.NewLine +
126
"class TestClass" + Environment.NewLine +
127
"{" + Environment.NewLine +
128
" void FooBar(out string par) {}" + Environment.NewLine +
129
" void Test ()" + Environment.NewLine +
130
" {" + Environment.NewLine +
131
" FooBar(out $foo);" + Environment.NewLine +
132
" }" + Environment.NewLine +
137
"using System;" + Environment.NewLine +
138
"class TestClass" + Environment.NewLine +
139
"{" + Environment.NewLine +
140
" void FooBar(out string par) {}" + Environment.NewLine +
141
" string foo;" + Environment.NewLine +
142
" void Test ()" + Environment.NewLine +
143
" {" + Environment.NewLine +
144
" FooBar(out foo);" + Environment.NewLine +
145
" }" + Environment.NewLine +
150
public void TestStaticClassField ()
152
// Not 100% correct input code, but should work in that case as well.
153
Test<CreateFieldAction> (@"static class TestClass
159
}", @"static class TestClass
170
public void TestEnumCase()
172
TestWrongContext<CreateFieldAction>(@"
186
public void TestThisMemberReferenceCreation ()
188
string result = RunContextAction (
189
new CreateFieldAction (),
190
"using System;" + Environment.NewLine +
191
"class TestClass" + Environment.NewLine +
192
"{" + Environment.NewLine +
193
" void Test ()" + Environment.NewLine +
194
" {" + Environment.NewLine +
195
" this.$foo = 0x10;" + Environment.NewLine +
196
" }" + Environment.NewLine +
201
"using System;" + Environment.NewLine +
202
"class TestClass" + Environment.NewLine +
203
"{" + Environment.NewLine +
204
" int foo;" + Environment.NewLine +
205
" void Test ()" + Environment.NewLine +
206
" {" + Environment.NewLine +
207
" this.foo = 0x10;" + Environment.NewLine +
208
" }" + Environment.NewLine +
213
public void TestObjectInitializer ()
215
// Not 100% correct input code, but should work in that case as well.
216
Test<CreateFieldAction> (@"class TestClass
221
$NonExistantProperty = 5
224
}", @"class TestClass
226
int NonExistantProperty;
230
NonExistantProperty = 5
237
public void TestObjectInitializerInStaticMethod ()
239
// Not 100% correct input code, but should work in that case as well.
240
Test<CreateFieldAction> (@"class TestClass
242
static void TestMethod ()
245
$NonExistantProperty = 5
248
}", @"class TestClass
250
int NonExistantProperty;
251
static void TestMethod ()
254
NonExistantProperty = 5
b'\\ No newline at end of file'