public void ShouldGetCompilationDependenciesForIssue129()
        {
            var resolver     = CreateResolver();
            var dependencies = resolver.GetDependencies(TestPathUtils.GetFullPathToTestFixture("Issue129"), true, "netcoreapp2.0");

            Assert.Contains(dependencies, d => d.Name == "Auth0.ManagementApi");
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 4
0
        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);
                }
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void ShouldGetCompilationDependenciesForIssue129()
        {
            var resolver     = CreateResolver();
            var dependencies = resolver.GetDependencies(TestPathUtils.GetPathToTestFixtureFolder("Issue129"), true, _scriptEnvironment.TargetFramework);

            Assert.Contains(dependencies, d => d.Name == "Auth0.ManagementApi");
        }
Exemplo n.º 7
0
        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");
        }
Exemplo n.º 9
0
        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);
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 16
0
        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");
        }
Exemplo n.º 17
0
        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/"));
        }
Exemplo n.º 21
0
        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);
            }
        }
Exemplo n.º 22
0
        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);
            }
        }
Exemplo n.º 23
0
        private static string GetPathToPackagesFolder()
        {
            var targetDirectory = TestPathUtils.GetFullPathToTestFixture(Path.Combine("ScriptPackage", "packages"));

            return(RuntimeHelper.CreateTempFolder(targetDirectory));
        }
Exemplo n.º 24
0
        public int ExecuteFixtureInProcess(string fixture, params string[] arguments)
        {
            var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture);

            return(Program.Main(new[] { pathToFixture }.Concat(arguments ?? Array.Empty <string>()).ToArray()));
        }
Exemplo n.º 25
0
        private static string GetPathToPackagesFolder()
        {
            var targetDirectory = TestPathUtils.GetPathToTestFixtureFolder(Path.Combine("ScriptPackage", "packages"));

            return(DependencyModel.ProjectSystem.FileUtils.CreateTempFolder(targetDirectory));
        }
Exemplo n.º 26
0
        public void ShouldHandleIssue189()
        {
            var result = ScriptTestRunner.Default.Execute(Path.Combine(TestPathUtils.GetPathToTestFixtureFolder("Issue189"), "SomeFolder", "Script.csx"));

            Assert.Contains("Newtonsoft.Json.JsonConvert", result.output);
        }