77using Microsoft . CodeAnalysis . CSharp ;
88using Microsoft . CodeAnalysis . Text ;
99
10- using XunitAssert = Xunit . Assert ;
1110using System . Net . Http ;
1211using System . Collections . Concurrent ;
1312using System . Collections . ObjectModel ;
@@ -16,76 +15,13 @@ namespace FluentAssertions.Analyzers.TestUtils
1615{
1716 public class CsProjectGenerator
1817 {
19- static CsProjectGenerator ( )
20- {
21- References = new [ ]
22- {
23- typeof ( object ) , // System.Private.CoreLib
24- typeof ( Console ) , // System
25- typeof ( Uri ) , // System.Private.Uri
26- typeof ( Enumerable ) , // System.Linq
27- typeof ( CSharpCompilation ) , // Microsoft.CodeAnalysis.CSharp
28- typeof ( Compilation ) , // Microsoft.CodeAnalysis
29- typeof ( AssertionScope ) , // FluentAssertions.Core
30- typeof ( AssertionExtensions ) , // FluentAssertions
31- typeof ( HttpRequestMessage ) , // System.Net.Http
32- typeof ( ImmutableArray ) , // System.Collections.Immutable
33- typeof ( ConcurrentBag < > ) , // System.Collections.Concurrent
34- typeof ( ReadOnlyDictionary < , > ) , // System.ObjectModel
35- typeof ( Microsoft . VisualStudio . TestTools . UnitTesting . Assert ) , // MsTest
36- typeof ( XunitAssert ) , // Xunit
37- } . Select ( type => type . GetTypeInfo ( ) . Assembly . Location )
38- . Append ( GetSystemAssemblyPathByName ( "System.Globalization.dll" ) )
39- . Append ( GetSystemAssemblyPathByName ( "System.Text.RegularExpressions.dll" ) )
40- . Append ( GetSystemAssemblyPathByName ( "System.Runtime.Extensions.dll" ) )
41- . Append ( GetSystemAssemblyPathByName ( "System.Data.Common.dll" ) )
42- . Append ( GetSystemAssemblyPathByName ( "System.Threading.Tasks.dll" ) )
43- . Append ( GetSystemAssemblyPathByName ( "System.Runtime.dll" ) )
44- . Append ( GetSystemAssemblyPathByName ( "System.Reflection.dll" ) )
45- . Append ( GetSystemAssemblyPathByName ( "System.Xml.dll" ) )
46- . Append ( GetSystemAssemblyPathByName ( "System.Xml.XDocument.dll" ) )
47- . Append ( GetSystemAssemblyPathByName ( "System.Private.Xml.Linq.dll" ) )
48- . Append ( GetSystemAssemblyPathByName ( "System.Linq.Expressions.dll" ) )
49- . Append ( GetSystemAssemblyPathByName ( "System.Collections.dll" ) )
50- . Append ( GetSystemAssemblyPathByName ( "netstandard.dll" ) )
51- . Append ( GetSystemAssemblyPathByName ( "System.Xml.ReaderWriter.dll" ) )
52- . Append ( GetSystemAssemblyPathByName ( "System.Private.Xml.dll" ) )
53- . Select ( location => ( MetadataReference ) MetadataReference . CreateFromFile ( location ) )
54- . ToImmutableArray ( ) ;
55-
56- string GetSystemAssemblyPathByName ( string assemblyName )
57- {
58- var root = System . IO . Path . GetDirectoryName ( typeof ( object ) . Assembly . Location ) ;
59- return System . IO . Path . Combine ( root , assemblyName ) ;
60- }
61- }
62-
63- private static readonly ImmutableArray < MetadataReference > References ;
64-
6518 private static readonly string DefaultFilePathPrefix = "Test" ;
6619 private static readonly string CSharpDefaultFileExt = "cs" ;
6720 private static readonly string VisualBasicDefaultExt = "vb" ;
6821 private static readonly string TestProjectName = "TestProject" ;
6922
7023 public static Document CreateDocument ( CsProjectArguments arguments ) => CreateProject ( arguments ) . Documents . First ( ) ;
7124
72- /// <summary>
73- /// Create a project using the inputted strings as sources.
74- /// </summary>
75- /// <param name="sources">Classes in the form of strings</param>
76- /// <param name="language">The language the source code is in</param>
77- /// <returns>A Project created out of the Documents created from the source strings</returns>
78- public static Project CreateProject ( string [ ] sources , string language = LanguageNames . CSharp )
79- {
80- var arguments = new CsProjectArguments
81- {
82- Language = language ,
83- Sources = sources ,
84- TargetFramework = TargetFramework . Net8_0 ,
85- } ;
86- return CreateProject ( arguments ) . AddMetadataReferences ( References ) ;
87- }
88-
8925 public static Project CreateProject ( CsProjectArguments arguments )
9026 {
9127 string fileNamePrefix = DefaultFilePathPrefix ;
0 commit comments