Skip to content

Commit 8c84172

Browse files
committed
More tests.
1 parent ce0e756 commit 8c84172

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

ReflectionAnalyzers.Tests/REFL019NoMemberMatchesTheTypesTests/Diagnostics.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ public class Diagnostics
1515
[TestCase("GetConstructor(↓new Type[1] { typeof(double) })")]
1616
[TestCase("GetConstructor(↓new Type[] { typeof(double) })")]
1717
[TestCase("GetConstructor(↓new[] { typeof(double) })")]
18+
[TestCase("GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, ↓Type.EmptyTypes, null)")]
1819
public void GetConstructor(string call)
1920
{
2021
var code = @"
2122
namespace RoslynSandbox
2223
{
2324
using System;
25+
using System.Reflection;
2426
2527
public class Foo
2628
{
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
namespace ReflectionAnalyzers.Tests.REFL019NoMemberMatchesTheTypesTests
2+
{
3+
using Gu.Roslyn.Asserts;
4+
using Microsoft.CodeAnalysis.Diagnostics;
5+
using NUnit.Framework;
6+
7+
public class ValidCode
8+
{
9+
private static readonly DiagnosticAnalyzer Analyzer = new GetXAnalyzer();
10+
private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(REFL019NoMemberMatchesTheTypes.Descriptor);
11+
12+
[TestCase("GetConstructor(new[] { typeof(int) })")]
13+
[TestCase("GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(int) }, null)")]
14+
public void GetConstructor(string call)
15+
{
16+
var code = @"
17+
namespace RoslynSandbox
18+
{
19+
using System;
20+
using System.Reflection;
21+
22+
public class Foo
23+
{
24+
public Foo(int value)
25+
{
26+
var ctor = typeof(Foo).GetConstructor(new[] { typeof(int) });
27+
}
28+
}
29+
}".AssertReplace("GetConstructor(new[] { typeof(int) })", call);
30+
31+
AnalyzerAssert.Valid(Analyzer, ExpectedDiagnostic, code);
32+
}
33+
34+
[TestCase("GetConstructor(Type.EmptyTypes)")]
35+
[TestCase("GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null)")]
36+
[TestCase("GetConstructor(new[] { typeof(int) })")]
37+
[TestCase("GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(int) }, null)")]
38+
[TestCase("GetConstructor(new[] { typeof(double) })")]
39+
[TestCase("GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(double) }, null)")]
40+
public void GetConstructorWhenOverloaded(string call)
41+
{
42+
var code = @"
43+
namespace RoslynSandbox
44+
{
45+
using System;
46+
using System.Reflection;
47+
48+
public class Foo
49+
{
50+
public Foo()
51+
{
52+
var ctor = typeof(Foo).GetConstructor(Type.EmptyTypes);
53+
}
54+
55+
public Foo(int value)
56+
{
57+
}
58+
59+
public Foo(double value)
60+
{
61+
}
62+
}
63+
}".AssertReplace("GetConstructor(Type.EmptyTypes)", call);
64+
65+
AnalyzerAssert.Valid(Analyzer, ExpectedDiagnostic, code);
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)