Ejemplo n.º 1
0
        /// <summary>
        /// Create a v3 folder of nupkgs
        /// </summary>
        public static async Task CreateFolderFeedV3(string root, PackageSaveMode saveMode, params SimpleTestPackageContext[] contexts)
        {
            using (var tempRoot = TestFileSystemUtility.CreateRandomTestFolder())
            {
                CreatePackages(tempRoot, contexts);

                await CreateFolderFeedV3(root, saveMode, Directory.GetFiles(tempRoot));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a packagets.config folder of nupkgs
        /// </summary>
        public static void CreateFolderFeedPackagesConfig(string root, params SimpleTestPackageContext[] contexts)
        {
            using (var tempRoot = TestFileSystemUtility.CreateRandomTestFolder())
            {
                CreatePackages(tempRoot, contexts);

                CreateFolderFeedPackagesConfig(root, Directory.GetFiles(tempRoot));
            }
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     // Try to delete the sub folder first, avoid removing
     // the parent folder containing extra test info
     // if the sub folder cannot be removed.
     if (TestFileSystemUtility.DeleteRandomTestFolder(Path))
     {
         TestFileSystemUtility.DeleteRandomTestFolder(_parentPath);
     }
 }
        public void Dispose()
        {
            TestFileSystemUtility.AssertNotTempPath(Path);

            try
            {
                Directory.Delete(Path, recursive: true);
            }
            catch
            {
            }
        }
Ejemplo n.º 5
0
        private static void UpdateCliWithLatestNuGetAssemblies(string cliDirectory)
        {
            var artifactsDirectory = TestFileSystemUtility.GetArtifactsDirectoryInRepo();
            var pathToSdkInCli     = Path.Combine(
                Directory.EnumerateDirectories(Path.Combine(cliDirectory, "sdk"))
                .Where(d => !string.Equals(Path.GetFileName(d), "NuGetFallbackFolder", StringComparison.OrdinalIgnoreCase))
                .First());
            const string configuration =
#if DEBUG
                "Debug";
#else
                "Release";
#endif
            CopyPackSdkArtifacts(artifactsDirectory, pathToSdkInCli, configuration);
            CopyRestoreArtifacts(artifactsDirectory, pathToSdkInCli, configuration);
        }
Ejemplo n.º 6
0
        // For fullframework code path, the test project dll could not be used to dynamically determine which SDK version to copy,
        // so we need to specify the sdkVersion and sdkTfm in order to patch the right version of SDK.
        public static TestDirectory CopyAndPatchLatestDotnetCli(string sdkVersion, string sdkTfm)
        {
            CliDirSource = Path.GetDirectoryName(TestFileSystemUtility.GetDotnetCli());
            SdkDirSource = Path.Combine(CliDirSource, "sdk" + Path.DirectorySeparatorChar);

            // Use specified sdkVersion
            SdkVersion = GetSdkToTestByVersion(sdkVersion);

            // Use specified sdkTfm
            SdkTfm = NuGetFramework.Parse(sdkTfm);

            var cliDirDestination = TestDirectory.Create();

            CopyLatestCliToTestDirectory(cliDirDestination);
            UpdateCliWithLatestNuGetAssemblies(cliDirDestination);

            return(cliDirDestination);
        }
Ejemplo n.º 7
0
        // For non fullframework code path, we could dynamically determine which SDK version to copy by checking the TFM of test project assembly and the dotnet.dll.
        public static TestDirectory CopyAndPatchLatestDotnetCli(string testAssemblyPath)
        {
            CliDirSource = Path.GetDirectoryName(TestFileSystemUtility.GetDotnetCli());
            SdkDirSource = Path.Combine(CliDirSource, "sdk" + Path.DirectorySeparatorChar);

            // Dynamically determine which SDK version to copy
            SdkVersion = GetSdkToTestByAssemblyPath(testAssemblyPath);

            // Dynamically determine the TFM of the dotnet.dll
            SdkTfm = AssemblyReader.GetTargetFramework(Path.Combine(SdkDirSource, SdkVersion, "dotnet.dll"));

            var cliDirDestination = TestDirectory.Create();

            CopyLatestCliToTestDirectory(cliDirDestination);
            UpdateCliWithLatestNuGetAssemblies(cliDirDestination);

            return(cliDirDestination);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create an unzipped repository folder of nupkgs
        /// </summary>
        public static void CreateFolderFeedUnzip(string root, params PackageIdentity[] packages)
        {
            var contexts = packages.Select(package => new SimpleTestPackageContext(package)).ToList();

            foreach (var context in contexts)
            {
                var name = $"{context.Id}.{context.Version.ToString()}";

                var nupkgPath  = Path.Combine(root, name + ".nupkg");
                var folder     = Path.Combine(root, name);
                var nuspecPath = Path.Combine(root, name, name + ".nuspec");

                Directory.CreateDirectory(folder);

                using (var tempRoot = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    CreatePackages(tempRoot, context);

                    var input = Directory.GetFiles(tempRoot).Single();

                    using (var zip = new ZipArchive(File.OpenRead(input)))
                    {
                        zip.ExtractAll(folder);
                    }

                    foreach (var file in Directory.GetFiles(folder))
                    {
                        if (file.EndsWith(".nuspec"))
                        {
                            File.Move(file, nuspecPath);
                        }

                        // Delete the rest
                        File.Delete(file);
                    }

                    // move the nupkg
                    File.Move(input, nupkgPath);
                }
            }
        }
Ejemplo n.º 9
0
        // For non fullframework code path, we could dynamically determine which SDK version to copy by checking the TFM of TestDotnetCLiUtility.dll and the dotnet.dll,
        // so there is no need to pass sdkVersion or sdkTfm.
        // But for fullframework code path, the test project dll could not be used to dynamically determine which SDK version to copy,
        // so we need to specify the sdkVersion and sdkTfm in order to patch the right version of SDK.
        public static TestDirectory CopyAndPatchLatestDotnetCli(string sdkVersion = null, string sdkTfm = null)
        {
            CliDirSource = Path.GetDirectoryName(TestFileSystemUtility.GetDotnetCli());
            SdkDirSource = Path.Combine(CliDirSource, "sdk" + Path.DirectorySeparatorChar);

            if (sdkVersion == null)
            {
#if !IS_DESKTOP
                // Dynamically determine which SDK version to copy
                SdkVersion = GetSdkToTest();
#endif
            }
            else
            {
                // Use specified sdkVersion
                SdkVersion = GetSdkToTest(sdkVersion);
            }


            if (sdkTfm == null)
            {
#if !IS_DESKTOP
                // Dynamically determine the TFM of the dotnet.dll
                SdkTfm = AssemblyReader.GetTargetFramework(Path.Combine(SdkDirSource, SdkVersion, "dotnet.dll"));
#endif
            }
            else
            {
                // Use specified sdkVersion
                SdkTfm = NuGetFramework.Parse(sdkTfm);
            }

            var cliDirDestination = TestDirectory.Create();
            CopyLatestCliToTestDirectory(cliDirDestination);
            UpdateCliWithLatestNuGetAssemblies(cliDirDestination);

            return(cliDirDestination);
        }
        public static string GetDotnetCli()
        {
            var cliDirName = "cli";
            var dir        = TestFileSystemUtility.ParentDirectoryLookup()
                             .FirstOrDefault(d => Directory.Exists(Path.Combine(d.FullName, cliDirName)));

            if (dir != null)
            {
                var dotnetCli = Path.Combine(dir.FullName, cliDirName, DotnetCliExe);
                if (File.Exists(dotnetCli))
                {
                    return(dotnetCli);
                }

                dotnetCli = Path.Combine(dir.FullName, cliDirName, DotnetCliBinary);
                if (File.Exists(dotnetCli))
                {
                    return(dotnetCli);
                }
            }

            return(null);
        }
Ejemplo n.º 11
0
 public void Dispose()
 {
     TestFileSystemUtility.DeleteRandomTestFolder(Path);
 }