static AsyncCodeConfiguration Configure() { var xmlConfig = new FileInfo("AsyncGenerator.xml"); if (xmlConfig.Exists) { using (var stream = xmlConfig.OpenRead()) { return(AsyncCodeConfiguration.Create() .LoggerFactory(new Log4NetLoggerFactory()) .ConfigureFromStream <XmlFileConfigurator>(stream, Environment.CurrentDirectory)); } } var ymlConfig = new FileInfo("AsyncGenerator.yml"); if (ymlConfig.Exists) { using (var stream = ymlConfig.OpenRead()) { return(AsyncCodeConfiguration.Create() .LoggerFactory(new Log4NetLoggerFactory()) .ConfigureFromStream <YamlFileConfigurator>(stream, Environment.CurrentDirectory)); } } return(null); }
public async Task TestNullableRestoreDirective() { var ignore = false; var config = AsyncCodeConfiguration.Create() .ConfigureProject(GetTestProjectPath("NullableRestore"), p => p .ConfigureAnalyzation(a => a .MethodConversion(s => MethodConversion.Smart) .CancellationTokens(true)) .ConfigureTransformation(t => t .AfterTransformation(result => { if (((CSharpCompilationOptions)result.Project.CompilationOptions).NullableContextOptions == NullableContextOptions.Disable) { ignore = true; return; } AssertValidAnnotations(result); Assert.AreEqual(1, result.Documents.Count); var document = result.Documents[0]; Assert.NotNull(document.OriginalModified); Assert.AreEqual(GetOutputFile("NullableRestore"), document.Transformed.ToFullString()); })) .ApplyChanges(false)); await AsyncCodeGenerator.GenerateAsync(config); if (ignore) { Assert.Ignore("Nullable is not enabled."); } }
public Task TestProject() { var config = AsyncCodeConfiguration.Create() .ConfigureProject(GetTestProjectPath("MultiTargetFrameworks"), p => p .TargetFramework("net461") .ApplyChanges(false) .RegisterPlugin <NUnitAsyncCounterpartsFinder>()); return(AsyncCodeGenerator.GenerateAsync(config)); }
public Task TestYamlAfterTransformation() { var configPath = Path.GetFullPath(Path.Combine(GetExternalProjectDirectory("NHibernate"), "src", "AsyncGenerator.yml")); var config = AsyncCodeConfiguration.Create() .LoggerFactory(new Log4NetLoggerFactory()) .ConfigureFromFile <YamlFileConfigurator>(configPath); return(AsyncCodeGenerator.GenerateAsync(config)); }
public Task TestSolution() { var config = AsyncCodeConfiguration.Create() .ConfigureSolution(GetTestSolutionPath("MultiTargetFrameworks"), s => s .TargetFramework("net461") .ApplyChanges(false) .ConfigureProject("MultiTargetFrameworks", p => p .RegisterPlugin(new NUnitPlugin(false)))); return(AsyncCodeGenerator.GenerateAsync(config)); }
public Task TestYamlProjectConfigurationAfterTransformation() { var asm = Assembly.GetExecutingAssembly(); var resource = $"{GetType().Namespace}.ProjectConfiguration.yml"; var stream = asm.GetManifestResourceStream(resource); var config = AsyncCodeConfiguration.Create() .LoggerFactory(new Log4NetLoggerFactory()) .ConfigureFromStream <YamlFileConfigurator>(stream); return(AsyncCodeGenerator.GenerateAsync(config)); }
public virtual AsyncCodeConfiguration Configure(Action <IFluentProjectConfiguration> action = null) { var filePath = Path.GetFullPath(Path.Combine(GetBaseDirectory(), "..", "..", "..", "AsyncGenerator.Tests.csproj")); return(AsyncCodeConfiguration.Create() .ConfigureProject(filePath, p => { p.ConfigureAnalyzation(a => a .DocumentSelection(o => string.Join("/", o.Folders) == InputFolderPath) ); action?.Invoke(p); }) ); }
public AsyncCodeConfiguration Configure(string fileName, Action <IFluentProjectConfiguration> action = null) { var slnFilePath = Path.GetFullPath(Path.Combine(GetBaseDirectory(), "..", "..", "..", "..", "AsyncGenerator.sln")); return(AsyncCodeConfiguration.Create() .ConfigureSolution(slnFilePath, c => c .ConfigureProject("AsyncGenerator.Tests", p => { p.ConfigureAnalyzation(a => a .DocumentSelection(o => string.Join("/", o.Folders) == InputFolderPath && o.Name == fileName + ".cs") ); action?.Invoke(p); }) )); }
public AsyncCodeConfiguration Configure(Action <IProjectConfiguration> action = null) { var slnFilePath = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\..\AsyncGenerator.sln"); return(AsyncCodeConfiguration.Create() .ConfigureSolution(slnFilePath, c => c .ConfigureProject("AsyncGenerator.Tests", p => { p.ConfigureAnalyzation(a => a .DocumentSelection(o => string.Join("/", o.Folders) == FolderPath && o.Name == FileName + ".cs") //.ScanMethodBody(true) ); action?.Invoke(p); }) )); }
public async Task TestCS0103LocalizationAfterTransformation(string culture) { var origUiCluture = CultureInfo.CurrentUICulture; try { var cultureInfo = CultureInfo.GetCultureInfo(culture); CultureInfo.CurrentUICulture = cultureInfo; CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; await AsyncCodeGenerator.GenerateAsync(AsyncCodeConfiguration.Create() .ConfigureProject(GetTestProjectPath("Localization"), o => o .ConfigureAnalyzation(a => a .CancellationTokens(true) .DocumentSelection(d => d.Name == "PrivateMethods.cs") .MethodConversion(symbol => symbol.Name == "List" ? MethodConversion.Smart : MethodConversion.Unknown) ) .ConfigureParsing(p => p .AddPreprocessorSymbolName("TEST") ) .ConfigureTransformation(t => t .AfterTransformation(result => { AssertValidAnnotations(result); Assert.AreEqual(1, result.Documents.Count); var document = result.Documents[0]; Assert.NotNull(document.OriginalModified); Assert.AreEqual(GetOutputFile("PrivateMethods"), document.Transformed.ToFullString()); }) ) .ApplyChanges(false))); } finally { CultureInfo.CurrentUICulture = origUiCluture; CultureInfo.DefaultThreadCurrentUICulture = origUiCluture; } }
public AsyncCodeConfiguration ConfigureByXml(string xmlConfig, string fileName = null, Action <IFluentProjectConfiguration> action = null) { return(AsyncCodeConfiguration.Create() .ConfigureFromStream(GenerateStreamFromString(xmlConfig), new TestProjectXmlFileConfigurator(InputFolderPath, fileName, action))); }
public Task TestAfterTransformation() { var slnFilePath = Path.GetFullPath(Path.Combine(GetExternalProjectDirectory("NHibernate"), "src", "NHibernate.sln")); var config = AsyncCodeConfiguration.Create() .LoggerFactory(new Log4NetLoggerFactory()) .ConfigureSolution(slnFilePath, s => s .ConcurrentRun() .SuppressDiagnosticFailures("NHibernate.Test.VisualBasic.vbproj") .ConfigureProject("NHibernate", p => p .ConfigureAnalyzation(a => a .MethodConversion(GetMethodConversion) .SearchForAsyncCounterparts(symbol => { switch (symbol.Name) { case "GetFieldValue": case "IsDBNull": case "WriteLine": return(false); } return(true); }) .CallForwarding(true) .CancellationTokens(t => t .Guards(true) .ParameterGeneration(symbolInfo => { if (IsPubliclyExposedType(symbolInfo.Symbol.ContainingType) || // For public types generate default parameter symbolInfo.ImplementedInterfaces.Any(o => IsPubliclyExposedType(o.ContainingType))) // The rule for public types shall be passed to implementors { return(MethodCancellationToken.Optional); } return(MethodCancellationToken.Required); }) .RequiresCancellationToken(symbol => { if (IsEventListener(symbol.ContainingType)) { return(true); } return(null); // Leave the decision to the generator }) ) .ScanMethodBody(true) ) .ConfigureTransformation(t => t .AsyncLock("NHibernate.Util.AsyncLock", "LockAsync") .LocalFunctions(true) .ConfigureAwaitArgument(false) .DocumentationComments(d => d .AddOrReplaceMethodSummary(GetMethodSummary) ) ) .RegisterPlugin <EmptyRegionRemover>() .RegisterPlugin <TransactionScopeAsyncFlowAdder>() // Rewrite TransactionScope in AdoNetWithDistributedTransactionFactory ) .ConfigureProject("NHibernate.DomainModel", p => p .ConfigureAnalyzation(a => a .ScanForMissingAsyncMembers(true) .ScanMethodBody(true) ) ) .ConfigureProject("NHibernate.Test", p => p .ConfigureAnalyzation(a => a .MethodConversion(symbol => { if (symbol.GetAttributes().Any(o => o.AttributeClass.Name == "IgnoreAttribute")) { return(MethodConversion.Ignore); } if (symbol.GetAttributes().Any(o => o.AttributeClass.Name == "TestAttribute")) { return(MethodConversion.Smart); } return(MethodConversion.Unknown); }) .AsyncExtensionMethods(e => e .ProjectFile("NHibernate", "LinqExtensionMethods.cs") ) .PreserveReturnType(symbol => symbol.GetAttributes().Any(o => o.AttributeClass.Name == "TestAttribute")) .ScanForMissingAsyncMembers(o => o.AllInterfaces.Any(i => i.ContainingAssembly.Name == "NHibernate")) .CancellationTokens(t => t .RequiresCancellationToken(symbol => symbol.GetAttributes().Any(o => o.AttributeClass.Name == "TestAttribute") ? (bool?)false : null)) .ScanMethodBody(true) .DocumentSelection(doc => { return // AsQueryable method is called on a retrieved list from db and the result is used elsewhere in code (!doc.FilePath.EndsWith(@"Linq\MathTests.cs") // It looks like that GC.Collect works differently with async. // if "await Task.Yield();" is added after DoLinqInSeparateSessionAsync then the test runs successfully (TODO: discover why) && !doc.FilePath.EndsWith(@"Linq\ExpressionSessionLeakTest.cs") ); }) .TypeConversion(type => { if (type.Name == "NorthwindDbCreator" || // Ignored for performance reasons type.Name == "ObjectAssert" || // Has a TestFixture attribute but is not a test type.Name == "LinqReadonlyTestsContext") // SetUpFixture { return(TypeConversion.Ignore); } if (type.GetAttributes().Any(o => o.AttributeClass.Name == "IgnoreAttribute")) { return(TypeConversion.Ignore); } if (type.GetAttributes().Any(o => o.AttributeClass.Name == "TestFixtureAttribute")) { return(TypeConversion.NewType); } var currentType = type; while (currentType != null) { if (currentType.Name == "TestCase") { return(TypeConversion.Ignore); } currentType = currentType.BaseType; } return(TypeConversion.Unknown); }) ) .RegisterPlugin <TransactionScopeAsyncFlowAdder>() .RegisterPlugin(new NUnitPlugin(false)) ) .ApplyChanges(true) ); return(AsyncCodeGenerator.GenerateAsync(config)); }