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

« back to all changes in this revision

Viewing changes to tests/UnitTests/MonoDevelop.CSharpBinding.Refactoring/ResolveNamespaceTests.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:
35
35
using MonoDevelop.CSharp;
36
36
using MonoDevelop.CSharp.Completion;
37
37
using MonoDevelop.Refactoring;
 
38
using System.Linq;
38
39
 
39
40
namespace MonoDevelop.CSharpBinding.Refactoring
40
41
{
41
 
        [TestFixture()]
 
42
        [TestFixture]
42
43
        public class ResolveNamespaceTests : UnitTests.TestBase
43
44
        {
44
45
                static Document Setup (string input)
45
46
                {
46
 
                        TestWorkbenchWindow tww = new TestWorkbenchWindow ();
 
47
                        var tww = new TestWorkbenchWindow ();
47
48
                        var content = new TestViewContent ();
48
49
                        tww.ViewContent = content;
49
50
                        content.ContentName = "a.cs";
50
51
                        content.GetTextEditorData ().Document.MimeType = "text/x-csharp";
51
 
 
52
 
                        Document doc = new Document (tww);
 
52
                        var doc = new Document (tww);
53
53
 
54
54
                        var text = input;
55
55
                        int endPos = text.IndexOf ('$');
57
57
                                text = text.Substring (0, endPos) + text.Substring (endPos + 1);
58
58
 
59
59
                        content.Text = text;
60
 
                        content.CursorPosition = System.Math.Max (0, endPos);
 
60
                        content.CursorPosition = Math.Max (0, endPos);
61
61
 
62
62
                        var compExt = new CSharpCompletionTextEditorExtension ();
63
63
                        compExt.Initialize (doc);
67
67
                        return doc;
68
68
                }
69
69
 
70
 
                HashSet<string> GetResult (string input)
 
70
                HashSet<MonoDevelop.Refactoring.ResolveCommandHandler.PossibleNamespace> GetResult (string input)
71
71
                {
72
72
                        var doc = Setup (input);
73
73
                        var location = doc.Editor.Caret.Location;
74
74
                        ResolveResult resolveResult;
75
75
                        AstNode node;
76
76
                        doc.TryResolveAt (location, out resolveResult, out node);
77
 
                        return ResolveCommandHandler.GetPossibleNamespaces (doc, node, resolveResult);
 
77
                        return ResolveCommandHandler.GetPossibleNamespaces (doc, node, ref resolveResult);
78
78
                }
79
79
 
80
 
                [Test ()]
 
80
                [Test]
81
81
                public void TestObjectCreationType ()
82
82
                {
83
83
                        var result = GetResult (@"class Test {
86
86
                var list = new $List<string> ();
87
87
        }
88
88
}");
89
 
                        Assert.IsTrue (result.Contains ("System.Collections.Generic"));
 
89
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
90
90
                }
91
91
 
92
 
                [Test ()]
 
92
                [Test]
93
93
                public void TestLocalVariableType ()
94
94
                {
95
95
                        var result = GetResult (@"class Test {
98
98
                $List<string> list;
99
99
        }
100
100
}");
101
 
                        Assert.IsTrue (result.Contains ("System.Collections.Generic"));
 
101
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
102
102
                }
103
103
 
104
 
                [Test ()]
 
104
                [Test]
105
105
                public void TestParameterType ()
106
106
                {
107
107
                        var result = GetResult (@"class Test {
109
109
        {
110
110
        }
111
111
}");
112
 
                        Assert.IsTrue (result.Contains ("System.Collections.Generic"));
 
112
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
113
113
                }
114
114
                
115
 
                [Test ()]
 
115
                [Test]
116
116
                public void TestFieldType ()
117
117
                {
118
118
                        var result = GetResult (@"class Test {
119
119
        $List<string> list;
120
120
}");
121
 
                        Assert.IsTrue (result.Contains ("System.Collections.Generic"));
 
121
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
122
122
                }
123
123
                
124
124
                
125
 
                [Test ()]
 
125
                [Test]
126
126
                public void TestBaseType ()
127
127
                {
128
128
                        var result = GetResult (@"class Test : $List<string> {}");
129
 
                        Assert.IsTrue (result.Contains ("System.Collections.Generic"));
 
129
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
130
130
                }
131
131
                
132
132
 
133
 
                [Test ()]
 
133
                [Test]
134
134
                public void TestLocalVariableValid ()
135
135
                {
136
136
                        var result = GetResult (@"using System.Collections.Generic;
143
143
                        Assert.AreEqual (0, result.Count);
144
144
                }
145
145
 
146
 
                [Test ()]
 
146
                [Test]
147
147
                public void TestAttributeCase1 ()
148
148
                {
149
149
                        var result = GetResult (@"
150
150
[$Obsolete]
151
151
class Test {
152
152
}");
153
 
                        Assert.IsTrue (result.Contains ("System"));
 
153
                        Assert.IsTrue (result.Any (t => t.Namespace == "System"));
154
154
                }
155
155
                
156
 
                [Test ()]
 
156
                [Test]
157
157
                public void TestAttributeCase2 ()
158
158
                {
159
159
 
161
161
[$SerializableAttribute]
162
162
class Test {
163
163
}");
164
 
                        Assert.IsTrue (result.Contains ("System"));
 
164
                        Assert.IsTrue (result.Any (t => t.Namespace == "System"));
165
165
                }
166
166
 
167
 
                [Test ()]
 
167
                [Test]
168
168
                public void TestAmbigiousResolveResult ()
169
169
                {
170
170
 
186
186
}");
187
187
                        foreach (var a in result)
188
188
                                Console.WriteLine (a);
189
 
                        Assert.IsTrue (result.Contains ("Foo"));
190
 
                        Assert.IsTrue (result.Contains ("Foo2"));
 
189
                        Assert.IsTrue (result.Any (t => t.Namespace == "Foo"));
 
190
                        Assert.IsTrue (result.Any (t => t.Namespace == "Foo2"));
191
191
                }
192
192
 
193
 
                [Test ()]
 
193
                [Test]
194
194
                public void TestExtensionMethod ()
195
195
                {
196
196
                        var result = GetResult (@"class Program
202
202
}");
203
203
                        foreach (var a in result)
204
204
                                Console.WriteLine (a);
205
 
                        Assert.IsTrue (result.Contains ("System.Linq"));
 
205
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Linq"));
206
206
                }
207
207
 
208
208
 
209
209
                #region Bug 3453 - [New Resolver] "Resolve" doesn't show up from time
210
 
                [Test ()]
 
210
                [Test]
211
211
                public void TestBug3453Case1 ()
212
212
                {
213
213
                        var result = GetResult (@"class Test {
217
217
                return encoding.EncodingName;
218
218
        }
219
219
}");
220
 
                        Assert.IsTrue (result.Contains ("System.Text"));
 
220
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Text"));
221
221
                }
222
222
 
223
 
                [Test ()]
 
223
                [Test]
224
224
                public void TestBug3453Case2 ()
225
225
                {
226
226
                        var result = GetResult (@"class Test {
230
230
                return encoding.EncodingName;
231
231
        }
232
232
}");
233
 
                        Assert.IsTrue (result.Contains ("System.Text"));
 
233
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Text"));
234
234
                }
235
235
 
236
 
                [Test ()]
 
236
                [Test]
237
237
                public void TestBug3453Case3 ()
238
238
                {
239
239
                        var result = GetResult (@"class Test {
242
242
                $Encoding.
243
243
        }
244
244
}");
245
 
                        Assert.IsTrue (result.Contains ("System.Text"));
 
245
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Text"));
246
246
                }
247
247
 
248
 
                [Test ()]
 
248
                [Test]
249
249
                public void TestBug3453Case3WithGeneris ()
250
250
                {
251
251
                        var result = GetResult (@"class Test {
254
254
                $List<string>.
255
255
        }
256
256
}");
257
 
                        Assert.IsTrue (result.Contains ("System.Collections.Generic"));
 
257
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
258
258
                }
259
259
                #endregion
260
260
 
261
261
                /// <summary>
262
262
                /// Bug 4361 - Cannot 'resolve' an unknown type
263
263
                /// </summary>
264
 
                [Test ()]
 
264
                [Test]
265
265
                public void TestBug4361 ()
266
266
                {
267
267
                        var result = GetResult (@"using System;
280
280
}");
281
281
                        foreach (var a in result)
282
282
                                Console.WriteLine (a);
283
 
                        Assert.IsTrue (result.Contains ("System.Threading"));
 
283
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Threading"));
284
284
                }
285
285
 
286
 
                [Test ()]
 
286
                [Test]
287
287
                public void TestBug4361Case2 ()
288
288
                {
289
289
                        var result = GetResult (@"using System;
302
302
}");
303
303
                        foreach (var a in result)
304
304
                                Console.WriteLine (a);
305
 
                        Assert.IsTrue (result.Contains ("System.Threading"));
 
305
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Threading"));
306
306
                }
307
307
 
308
308
                /// <summary>
309
309
                /// Bug 4493 - 'Resolve' context action offers incorrect options
310
310
                /// </summary>
311
 
                [Test ()]
 
311
                [Test]
312
312
                public void TestBug4493 ()
313
313
                {
314
314
                        var result = GetResult (@"using System;
325
325
}"
326
326
                        );
327
327
 
328
 
                        Assert.IsFalse (result.Contains ("System.Collections"));
329
 
                        Assert.IsTrue (result.Contains ("System.Collections.Generic"));
 
328
                        Assert.IsFalse (result.Any (t => t.Namespace == "System.Collections"));
 
329
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Collections.Generic"));
330
330
                }
331
331
 
332
332
 
333
333
                /// <summary>
334
334
                /// Bug 5206 - Resolve -> Add Using statement does not work after "|" 
335
335
                /// </summary>
336
 
                [Test ()]
 
336
                [Test]
337
337
                public void TestBug5206 ()
338
338
                {
339
339
                        var result = GetResult (@"using System;
350
350
}"
351
351
                        );
352
352
 
353
 
                        Assert.IsTrue (result.Contains ("System.Reflection"));
354
 
                }
355
 
 
 
353
                        Assert.IsTrue (result.Any (t => t.Namespace == "System.Reflection"));
 
354
                }
 
355
 
 
356
                /// <summary>
 
357
                /// Bug 4749 - Resolve is incorrect for inner classes
 
358
                /// </summary>
 
359
                [Test]
 
360
                public void TestBug4749 ()
 
361
                {
 
362
 
 
363
                        var result = GetResult (@"namespace Test { public class Foo { public class Bar {} } }
 
364
 
 
365
class Program
 
366
{
 
367
        public static void Main ()
 
368
        {
 
369
                $Bar bar;
 
370
        }
 
371
}
 
372
");
 
373
                        foreach (var a in result)
 
374
                                Console.WriteLine (a);
 
375
                        Assert.IsTrue (result.Any (t => t.Namespace == "Test.Foo" && !t.IsAccessibleWithGlobalUsing));
 
376
                }
 
377
 
 
378
 
 
379
                /// <summary>
 
380
                /// Bug 10059 - Resolve type fails for nested static types
 
381
                /// </summary>
 
382
                [Test]
 
383
                public void TestBug10059 ()
 
384
                {
 
385
                        var result = GetResult (@"namespace ConsoleTest
 
386
{
 
387
    class MainClass
 
388
    {
 
389
        $Environment.SpecialFolder F { get; }
 
390
    }
 
391
}
 
392
"
 
393
                                                );
 
394
                        
 
395
                        Assert.IsTrue (result.Any (t => t.Namespace == "System"));
 
396
                }
356
397
 
357
398
 
358
399
        }