2
// ExpressionIsNeverOfProvidedTypeIssueTests.cs
5
// Mansheng Yang <lightyang0@gmail.com>
7
// Copyright (c) 2012 Mansheng Yang <lightyang0@gmail.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 ICSharpCode.NRefactory.CSharp.Refactoring;
28
using NUnit.Framework;
30
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
33
public class ExpressionIsNeverOfProvidedTypeIssueTests : InspectionActionTestBase
36
public void TestClass ()
39
class AnotherClass { }
42
void TestMethod (AnotherClass x)
47
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
51
public void TestClassNoIssue ()
57
void TestMethod (object x)
63
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
67
public void TestSealedClass ()
71
sealed class TestClass
73
void TestMethod (TestClass x)
78
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
82
public void TestNull ()
92
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
96
public void TestObjectToInt ()
99
sealed class TestClass
101
void TestMethod (object x)
106
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
110
public void TestClassIsTypeParameter ()
116
void TestMethod<T, T2> (TestClass x) where T : TestClass2 where T2 : struct
122
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 2);
126
public void TestClassIsTypeParameter2 ()
131
class TestClass2 : TestClass { }
132
class TestClass : TestBase
134
void TestMethod<T, T2, T3> (TestClass x) where T : TestBase where T2 : ITest where T3 : TestClass2
139
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
143
public void TestStructIsTypeParameter ()
147
struct TestStruct : ITest { }
150
void TestMethod<T> (TestStruct x) where T : ITest
155
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
159
public void TestStructIsTypeParameter2 ()
162
struct TestStruct { }
165
void TestMethod<T> (TestStruct x) where T : class
170
// this is possible with T==object
171
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
175
public void TestTypeParameter ()
181
void TestMethod<T> (T x) where T : TestClass2
183
if (x is TestClass) ;
186
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
190
public void TestTypeParameter2 ()
195
void TestMethod<T> (T x) where T : struct
197
if (x is TestClass) ;
200
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
204
public void TestTypeParameter3 ()
210
void TestMethod<T> (T x) where T : ITest, new()
212
if (x is TestClass) ;
215
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
219
public void TestTypeParameter4 ()
223
sealed class TestClass
225
void TestMethod<T> (T x) where T : ITest
227
if (x is TestClass) ;
230
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
234
public void TestTypeParameterIsTypeParameter ()
240
void TestMethod<T, T2> (T x) where T : TestClass where T2 : TestClass2
245
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
249
public void TestTypeParameterIsTypeParameter2 ()
255
void TestMethod<T, T2> (T x) where T : TestClass where T2 : ITest, new()
260
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
264
public void TestObjectArrayToStringArray ()
267
sealed class TestClass
269
void TestMethod (object[] x)
274
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
278
public void UnknownExpression()
281
sealed class TestClass
285
if (unknown is string) ;
288
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
292
public void UnknownType()
295
sealed class TestClass
297
void TestMethod (int x)
302
Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);