public void Given_Empty_List_Of_Strings_When_Testing_DependenciesGenerator() { var input = new List <string>(); var sut = new DependenciesGenerator(input); var result = sut.Generate(); var expected = ""; Assert.Equal(expected, result); }
public void Given_List_Of_Strings_When_Testing_DependenciesGenerator() { var input = new List <string> { "System", "System.Collections.Generic", "Autogeneration.Domain", "Xunit" }; var sut = new DependenciesGenerator(input); var result = sut.Generate(); var expected = String.Join( Environment.NewLine, "using System;", "using System.Collections.Generic;", "using Autogeneration.Domain;", "using Xunit;", ""); Assert.Equal(expected, result); }
public static int Run(string?project, string?workspace, string?msbuildPath, string?tfm, bool forceWebConversion, bool preview, bool diffOnly, bool noBackup, bool keepCurrentTfms, decimal?generateDependenciesVersion) { if (!string.IsNullOrWhiteSpace(project) && !string.IsNullOrWhiteSpace(workspace)) { Console.WriteLine("Cannot specify both a project and a workspace."); return(-1); } if (!string.IsNullOrWhiteSpace(tfm) && keepCurrentTfms) { Console.WriteLine($"Both '{nameof(tfm)}' and '{nameof(keepCurrentTfms)}' cannot be specified. Please pick one."); return(-1); } try { if (generateDependenciesVersion != null) { Console.WriteLine($"Generating dependencies for {generateDependenciesVersion} version"); DependenciesGenerator.Generate(generateDependenciesVersion.Value); return(0); } msbuildPath = MSBuildHelpers.HookAssemblyResolveForMSBuild(msbuildPath); if (string.IsNullOrWhiteSpace(msbuildPath)) { Console.WriteLine("Could not find an MSBuild."); return(-1); } if (!string.IsNullOrWhiteSpace(tfm)) { tfm = tfm.Trim(); if (!TargetFrameworkHelper.IsValidTargetFramework(tfm)) { Console.WriteLine($"Invalid framework specified for --target-framework: '{tfm}'"); return(-1); } } else { tfm = TargetFrameworkHelper.FindHighestInstalledTargetFramework(preview); } var workspacePath = string.Empty; MSBuildConversionWorkspaceType workspaceType; if (!string.IsNullOrWhiteSpace(project)) { workspacePath = Path.GetFullPath(project, Environment.CurrentDirectory); workspaceType = MSBuildConversionWorkspaceType.Project; } else { var(isSolution, workspaceFilePath) = MSBuildConversionWorkspaceFinder.FindWorkspace(Environment.CurrentDirectory, workspace); workspaceType = isSolution ? MSBuildConversionWorkspaceType.Solution : MSBuildConversionWorkspaceType.Project; workspacePath = workspaceFilePath; } var workspaceLoader = new MSBuildConversionWorkspaceLoader(workspacePath, workspaceType); // do not create backup if --diff-only specified noBackup = noBackup || diffOnly; var msbuildWorkspace = workspaceLoader.LoadWorkspace(workspacePath, noBackup, tfm, keepCurrentTfms, forceWebConversion); if (msbuildWorkspace.WorkspaceItems.Length is 0) { Console.WriteLine("No projects converted."); return(0); } foreach (var item in msbuildWorkspace.WorkspaceItems) { if (diffOnly) { var differ = new Differ(item.UnconfiguredProject.FirstConfiguredProject, item.SdkBaselineProject.Project.FirstConfiguredProject); var parent = Directory.GetParent(workspacePath); if (parent is null) { differ.GenerateReport(workspacePath); } else { differ.GenerateReport(parent.FullName); } } else { var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement, noBackup); converter.Convert(item.ProjectRootElement.FullPath); } } } catch (Exception e) { Console.WriteLine(e.ToString()); return(-1); } Console.WriteLine("Conversion complete!"); return(0); }