public CompilationResult Compile(List <string> fileContents) { var references = GetReferences(); var roslynCompilationService = new RoslynCompilationService(); return(roslynCompilationService.Compile(fileContents, references)); }
public void E2ETest() { SetCurrentCulture(); var serviceCollection = SetupInitialServices(); var logger = new InMemoryCommandLogger("E2ETest"); serviceCollection.AddScoped(typeof(ILogger), sp => logger); var fileService = new InMemoryFileService(); serviceCollection.AddScoped(typeof(IFileService), sp => fileService); var provider = GetMetadataModelProvider(serviceCollection); var configuration = new ReverseEngineeringConfiguration { Provider = provider, ConnectionString = E2EConnectionString, Namespace = TestNamespace, CustomTemplatePath = null, // not used for this test OutputPath = TestOutputDir }; var expectedFileContents = InitializeE2EExpectedFileContents(); var serviceProvider = serviceCollection.BuildServiceProvider(); var generator = serviceProvider.GetRequiredService <ReverseEngineeringGenerator>(); var filePaths = generator.GenerateAsync(configuration).Result; Assert.Equal(_E2ETestExpectedWarnings.Count, logger.WarningMessages.Count); // loop over warnings instead of using the collection form of Assert.Equal() // to give better error messages if it does fail. Similarly for file paths below. var i = 0; foreach (var expectedWarning in _E2ETestExpectedWarnings) { Assert.Equal(expectedWarning, logger.WarningMessages[i++]); } Assert.Equal(0, logger.InformationMessages.Count); Assert.Equal(0, logger.VerboseMessages.Count); var expectedFilePaths = _E2ETestExpectedFileNames.Select(name => Path.Combine(TestOutputDir, name)); Assert.Equal(expectedFilePaths.Count(), filePaths.Count); i = 0; foreach (var expectedFilePath in expectedFilePaths) { Assert.Equal(expectedFilePath, filePaths[i++]); } var listOfFileContents = new List <string>(); foreach (var fileName in _E2ETestExpectedFileNames) { var fileContents = fileService.RetrieveFileContents(TestOutputDir, fileName); Assert.Equal(expectedFileContents[fileName], fileContents); listOfFileContents.Add(fileContents); } // compile generated code var metadataReferencesProvider = (MetadataReferencesProvider)serviceProvider.GetService(typeof(MetadataReferencesProvider)); var metadataReferences = SetupMetadataReferencesForCompilationOfGeneratedCode(metadataReferencesProvider); var roslynCompilationService = new RoslynCompilationService(); var compilationResult = roslynCompilationService.Compile(listOfFileContents, metadataReferences); if (compilationResult.Messages.Any()) { _output.WriteLine("Compilation Errors from compiling generated code"); _output.WriteLine("================================================"); foreach (var message in compilationResult.Messages) { _output.WriteLine(message); } _output.WriteLine("================================================"); Assert.Equal(string.Empty, "See Compilation Errors in Output."); } }