2
// CallToStaticMemberViaDerivedType.cs
5
// Simon Lindgren <simon.n.lindgren@gmail.com>
7
// Copyright (c) 2012 Simon Lindgren
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.CodeActions;
29
using ICSharpCode.NRefactory.CSharp.Refactoring;
31
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
34
public class ReferenceToStaticMemberViaDerivedTypeTests : InspectionActionTestBase
37
public void MemberInvocation()
42
public static void F() { }
52
TestRefactoringContext context;
53
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
54
Assert.AreEqual(1, issues.Count);
55
Assert.AreEqual(11, issues [0].Start.Line);
57
CheckFix(context, issues [0], @"
60
public static void F() { }
74
public void PropertyAccess()
79
public static string Property { get; set; }
86
System.Console.WriteLine(B.Property);
89
TestRefactoringContext context;
90
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
91
Assert.AreEqual(1, issues.Count);
92
Assert.AreEqual(11, issues [0].Start.Line);
94
CheckFix(context, issues [0], @"
97
public static string Property { get; set; }
104
System.Console.WriteLine(A.Property);
111
public void FieldAccess()
116
public static string Property;
123
System.Console.WriteLine(B.Property);
126
TestRefactoringContext context;
127
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
128
Assert.AreEqual(1, issues.Count);
129
Assert.AreEqual(11, issues [0].Start.Line);
131
CheckFix(context, issues [0], @"
134
public static string Property;
141
System.Console.WriteLine(A.Property);
148
public void NestedClass()
155
public static void F() { }
157
public class C : B { }
166
TestRefactoringContext context;
167
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
168
Assert.AreEqual(1, issues.Count);
169
Assert.AreEqual(14, issues [0].Start.Line);
171
CheckFix(context, issues [0], @"
176
public static void F() { }
178
public class C : B { }
191
public void ExpandsTypeWithNamespaceIfNeccessary()
198
public static void F() { }
203
public class B : First.A { }
212
TestRefactoringContext context;
213
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
214
Assert.AreEqual(1, issues.Count);
215
Assert.AreEqual(16, issues [0].Start.Line);
217
CheckFix(context, issues [0], @"
222
public static void F() { }
227
public class B : First.A { }
240
public void IgnoresCorrectCalls()
245
public static void F() { }
254
TestRefactoringContext context;
255
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
256
Assert.AreEqual(0, issues.Count);
260
public void IgnoresNonStaticCalls()
276
TestRefactoringContext context;
277
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
278
Assert.AreEqual(0, issues.Count);
282
public void IgnoresOwnMemberFunctions()
287
protected static void F() { }
298
TestRefactoringContext context;
299
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
300
Assert.AreEqual(0, issues.Count);
304
public void IgnoresCuriouslyRecurringTemplatePattern()
309
public static void F() { }
311
class Derived : Base<Derived> {}
319
// do not suggest replacing 'Derived.F()' with 'Base<Derived>.F()'
320
TestRefactoringContext context;
321
var issues = GetIssues(new ReferenceToStaticMemberViaDerivedTypeIssue(), input, out context);
322
Assert.AreEqual(0, issues.Count);