public void ShouldGetCompilationDependenciesForIssue129() { var resolver = CreateResolver(); var dependencies = resolver.GetDependencies(TestPathUtils.GetFullPathToTestFixture("Issue129"), true, "netcoreapp2.0"); Assert.Contains(dependencies, d => d.Name == "Auth0.ManagementApi"); }
public void ShouldGetCompilationDependenciesForPackageContainingInlineNuGetPackageReference() { var resolver = CreateResolver(); var dependencies = resolver.GetDependencies(TestPathUtils.GetPathToTestFixtureFolder("InlineNugetPackage"), true, _scriptEnvironment.TargetFramework); Assert.Contains(dependencies, d => d.Name == "AutoMapper"); }
public void ShouldGetCompilationDependenciesForPackageContainingInlineNuGetPackageReference() { var resolver = CreateResolver(); var dependencies = resolver.GetDependencies(TestPathUtils.GetFullPathToTestFixture("InlineNugetPackage"), true, "netcoreapp2.0"); Assert.Contains(dependencies, d => d.Name == "AutoMapper"); }
public void ShouldThrowMeaningfulErrorMessageWhenDependencyIsNotFound() { using (var libraryFolder = new DisposableFolder()) { // Create a package that we can reference ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n SampleLibrary", libraryFolder.Path); ProcessHelper.RunAndCaptureOutput("dotnet", "pack", libraryFolder.Path); using (var scriptFolder = new DisposableFolder()) { var code = new StringBuilder(); code.AppendLine("#r \"nuget:SampleLibrary, 1.0.0\""); code.AppendLine("WriteLine(42)"); var pathToScript = Path.Combine(scriptFolder.Path, "main.csx"); File.WriteAllText(pathToScript, code.ToString()); // Run once to ensure that it is cached. var result = ScriptTestRunner.Default.Execute(pathToScript); Assert.Contains("42", result.output); // Remove the package from the global NuGet cache TestPathUtils.RemovePackageFromGlobalNugetCache("SampleLibrary"); result = ScriptTestRunner.Default.Execute(pathToScript); Assert.Contains("Try executing/publishing the script", result.output); // Run again with the '--no-cache' option to assert that the advice actually worked. result = ScriptTestRunner.Default.Execute($"{pathToScript} --no-cache"); Assert.Contains("42", result.output); } } }
public static void RemovePackageFromGlobalNugetCache(string packageName) { var pathToGlobalPackagesFolder = TestPathUtils.GetPathToGlobalPackagesFolder(); var pathToAutoMapperPackage = Directory.GetDirectories(pathToGlobalPackagesFolder).Single(d => d.Contains(packageName, StringComparison.OrdinalIgnoreCase)); FileUtils.RemoveDirectory(pathToAutoMapperPackage); }
public void ShouldGetCompilationDependenciesForIssue129() { var resolver = CreateResolver(); var dependencies = resolver.GetDependencies(TestPathUtils.GetPathToTestFixtureFolder("Issue129"), true, _scriptEnvironment.TargetFramework); Assert.Contains(dependencies, d => d.Name == "Auth0.ManagementApi"); }
public (string output, int exitCode) ExecuteFixture(string fixture, params string[] arguments) { var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture); var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments(new string[] { pathToFixture }.Concat(arguments ?? Array.Empty <string>()).ToArray())); return(result); }
public void ShouldGetCompilationDependenciesForPackageContainingNativeLibrary() { var resolver = CreateResolver(); var dependencies = resolver.GetDependencies(TestPathUtils.GetFullPathToTestFixture("NativeLibrary"), true, "netcoreapp2.0"); Assert.Contains(dependencies, d => d.Name == "Microsoft.Data.Sqlite"); }
public (string output, int exitcode) ExecuteWithScriptPackage(string fixture, string arguments = null, string workingDirectory = null) { var pathToScriptPackageFixtures = TestPathUtils.GetPathToTestFixtureFolder("ScriptPackage"); var pathToFixture = Path.Combine(pathToScriptPackageFixtures, fixture, $"{fixture}.csx"); return(ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}"), workingDirectory)); }
public void ShouldThrowMeaningfulExceptionWhenScriptPackageIsMissing() { using (var scriptFolder = new DisposableFolder()) { var code = new StringBuilder(); code.AppendLine("#load \"nuget:ScriptPackageWithMainCsx, 1.0.0\""); code.AppendLine("SayHello();"); var pathToScriptFile = Path.Combine(scriptFolder.Path, "main.csx"); File.WriteAllText(pathToScriptFile, code.ToString()); var pathToScriptPackages = Path.GetFullPath(ScriptPackagesFixture.GetPathToPackagesFolder()); // Run once to ensure that it is cached. var result = ScriptTestRunner.Default.Execute($"{pathToScriptFile} -s {pathToScriptPackages}"); Assert.StartsWith("Hello from netstandard2.0", result.output); // Remove the package from the global NuGet cache TestPathUtils.RemovePackageFromGlobalNugetCache("ScriptPackageWithMainCsx"); //Change the source to force a recompile, now with the missing package. code.Append("return 0;"); File.WriteAllText(pathToScriptFile, code.ToString()); result = ScriptTestRunner.Default.Execute($"{pathToScriptFile} -s {pathToScriptPackages}"); Assert.Contains("Try executing/publishing the script", result.output); } }
public void ShouldIgnoreGlobalJsonInScriptFolder() { var fixture = "InvalidGlobalJson"; var workingDirectory = Path.GetDirectoryName(TestPathUtils.GetPathToTestFixture(fixture)); var result = ScriptTestRunner.Default.ExecuteFixture("InvalidGlobalJson", $"--no-cache", workingDirectory); Assert.Contains("Hello world!", result.output); }
public (string output, int exitCode) ExecuteFixture(string fixture, string arguments = null, string workingDirectory = null) { var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture); var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}"), workingDirectory); return(result); }
public void ShouldGetCompilationDependenciesForPackageContainingNativeLibrary() { var resolver = CreateResolver(); var dependencies = resolver.GetDependencies(TestPathUtils.GetPathToTestFixtureFolder("NativeLibrary"), true, _scriptEnvironment.TargetFramework); Assert.Contains(dependencies, d => d.Name == "Microsoft.Data.Sqlite"); }
public void ShouldCopyLocalNuGetConfig() { var provider = CreateProvider(); var pathToProjectFile = provider.CreateProject(TestPathUtils.GetFullPathToTestFixture("LocalNuGetConfig"), RuntimeHelper.TargetFramework, true); var pathToProjectFileFolder = Path.GetDirectoryName(pathToProjectFile); Assert.True(File.Exists(Path.Combine(pathToProjectFileFolder, "NuGet.Config"))); }
public void ShouldHandleSpecifyingPackageSource() { var fixture = "ScriptPackage/WithNoNuGetConfig"; var pathToScriptPackages = TestPathUtils.GetPathToScriptPackages(fixture); var result = ScriptTestRunner.Default.ExecuteFixture(fixture, $"-s {pathToScriptPackages}"); Assert.Contains("Hello", result.output); Assert.Equal(0, result.exitCode); }
public void ShouldGetCompilationDependenciesForPackageContainingInlineNuGetPackageReferenceButSkipExcludedCsx() { var resolver = CreateResolver(); var targetDirectory = TestPathUtils.GetPathToTestFixtureFolder("InlineNugetPackageWithFileFiltering"); var csxFiles = Directory.GetFiles(targetDirectory, "InlineNugetPackage.csx"); var dependencies = resolver.GetDependencies(targetDirectory, csxFiles, true, _scriptEnvironment.TargetFramework); Assert.DoesNotContain(dependencies, d => d.Name == "AutoMapper"); Assert.Contains(dependencies, d => d.Name == "Newtonsoft.Json"); }
private void ClearGlobalPackagesFolder() { var pathToGlobalPackagesFolder = TestPathUtils.GetPathToGlobalPackagesFolder(); var scriptPackageFolders = Directory.GetDirectories(pathToGlobalPackagesFolder).Select(f => f.ToLower()).Where(f => f.Contains("scriptpackage")); foreach (var scriptPackageFolder in scriptPackageFolders) { RemoveDirectory(scriptPackageFolder); } }
public void ShouldHandleSpecifyingPackageSourceWhenEvaluatingCode() { var fixture = "ScriptPackage/WithNoNuGetConfig"; var pathToScriptPackages = TestPathUtils.GetPathToScriptPackages(fixture); var code = @"#load \""nuget:ScriptPackageWithMainCsx,1.0.0\"" SayHello();"; var result = ScriptTestRunner.Default.Execute($"-s {pathToScriptPackages} eval \"{code}\""); Assert.Contains("Hello", result.output); Assert.Equal(0, result.exitCode); }
public void ShouldLogProjectFileContent() { StringBuilder log = new StringBuilder(); var provider = new ScriptProjectProvider(type => ((level, message) => log.AppendLine(message))); provider.CreateProject(TestPathUtils.GetFullPathToTestFixture("HelloWorld"), RuntimeHelper.TargetFramework, true); var output = log.ToString(); Assert.Contains("<Project Sdk=\"Microsoft.NET.Sdk\">", output); }
public void ShouldGetCompilationDependenciesForNuGetPackageWithRefFolder() { var resolver = CreateResolver(); var targetDirectory = TestPathUtils.GetPathToTestFixtureFolder("InlineNugetPackageWithRefFolder"); var csxFiles = Directory.GetFiles(targetDirectory, "*.csx"); var dependencies = resolver.GetDependencies(targetDirectory, csxFiles, true, _scriptEnvironment.TargetFramework); var sqlClientDependency = dependencies.Single(d => d.Name.Equals("System.Data.SqlClient", StringComparison.InvariantCultureIgnoreCase)); Assert.Contains(sqlClientDependency.AssemblyPaths, d => d.Replace("\\", "/").Contains("system.data.sqlclient/4.6.1/ref/")); }
public void ShouldHandleLocalNuGetConfigWithRelativePath() { TestPathUtils.RemovePackageFromGlobalNugetCache("NuGetConfigTestLibrary"); using (var packageLibraryFolder = new DisposableFolder()) { CreateTestPackage(packageLibraryFolder.Path); string pathToScriptFile = CreateTestScript(packageLibraryFolder.Path); var result = ScriptTestRunner.Default.Execute(pathToScriptFile); Assert.Contains("Success", result.output); } }
public void ShouldHandleLocalNuGetFileWhenPathContainsSpace() { TestPathUtils.RemovePackageFromGlobalNugetCache("NuGetConfigTestLibrary"); using (var packageLibraryFolder = new DisposableFolder()) { var packageLibraryFolderPath = Path.Combine(packageLibraryFolder.Path, "library folder"); Directory.CreateDirectory(packageLibraryFolderPath); CreateTestPackage(packageLibraryFolderPath); string pathToScriptFile = CreateTestScript(packageLibraryFolderPath); var result = ScriptTestRunner.Default.Execute($"\"{pathToScriptFile}\""); Assert.Contains("Success", result.output); } }
private static string GetPathToPackagesFolder() { var targetDirectory = TestPathUtils.GetFullPathToTestFixture(Path.Combine("ScriptPackage", "packages")); return(RuntimeHelper.CreateTempFolder(targetDirectory)); }
public int ExecuteFixtureInProcess(string fixture, params string[] arguments) { var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture); return(Program.Main(new[] { pathToFixture }.Concat(arguments ?? Array.Empty <string>()).ToArray())); }
private static string GetPathToPackagesFolder() { var targetDirectory = TestPathUtils.GetPathToTestFixtureFolder(Path.Combine("ScriptPackage", "packages")); return(DependencyModel.ProjectSystem.FileUtils.CreateTempFolder(targetDirectory)); }
public void ShouldHandleIssue189() { var result = ScriptTestRunner.Default.Execute(Path.Combine(TestPathUtils.GetPathToTestFixtureFolder("Issue189"), "SomeFolder", "Script.csx")); Assert.Contains("Newtonsoft.Json.JsonConvert", result.output); }