File tree 1 file changed +51
-0
lines changed
tests/EffectiveCSharp.Analyzers.Tests
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ using EffectiveCSharp . Analyzers . Common ;
2
+ using Microsoft . CodeAnalysis ;
3
+
4
+ namespace EffectiveCSharp . Analyzers . Tests ;
5
+
6
+ public class SupportsTypeTests
7
+ {
8
+ [ Fact ]
9
+ public void Supports_FormattableString ( )
10
+ {
11
+ Compilation compilation = CreateCompilation ( ) ;
12
+
13
+ bool result = compilation . SupportsType ( "System.FormattableString" ) ;
14
+
15
+ Assert . True ( result ) ;
16
+ }
17
+
18
+ [ Fact ]
19
+ public void Supports_StringCreate ( )
20
+ {
21
+ Compilation compilation = CreateCompilation ( ) ;
22
+
23
+ bool result = compilation . SupportsType ( "System.String" , "Create" ) ;
24
+
25
+ Assert . True ( result ) ;
26
+ }
27
+
28
+ private static Compilation CreateCompilation ( )
29
+ {
30
+ const string testCode = """
31
+ public class C
32
+ {
33
+ public void M()
34
+ {
35
+ }
36
+ }
37
+ """ ;
38
+
39
+ Compilation compilation = CreateCompilation ( testCode ) ;
40
+ return compilation ;
41
+ }
42
+
43
+ private static Compilation CreateCompilation ( string sourceCode )
44
+ {
45
+ return CSharpCompilation . Create (
46
+ "TestAssembly" ,
47
+ new [ ] { CSharpSyntaxTree . ParseText ( sourceCode ) } ,
48
+ new [ ] { MetadataReference . CreateFromFile ( typeof ( object ) . Assembly . Location ) } ,
49
+ new CSharpCompilationOptions ( OutputKind . DynamicallyLinkedLibrary ) ) ;
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments