コード例 #1
0
        public void RestoreCommand_VerifyMinClientVersionV3Source()
        {
            // Arrange
            using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    var specPath = Path.Combine(projectDir, "TestProject", "project.json");
                    var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                    // This package has a minclientversion of 9999
                    XPlatTestUtils.AddDependency(spec, "TestPackage.MinClientVersion", "1.0.0");
                    XPlatTestUtils.WriteJson(spec, specPath);

                    var lockFilePath = Path.Combine(projectDir, "project.lock.json");
                    var log          = new TestCommandOutputLogger();

                    var args = new string[]
                    {
                        "restore",
                        projectDir,
                        "-s",
                        "https://api.nuget.org/v3/index.json",
                        "--packages",
                        packagesDir
                    };

                    // Act
                    var exitCode = Program.MainInternal(args, log);

                    // Assert
                    Assert.Equal(1, log.Errors);
                    Assert.Contains("'TestPackage.MinClientVersion 1.0.0' package requires NuGet client version '9.9999.0' or above", log.ShowMessages());
                    Assert.False(File.Exists(lockFilePath));
                }
        }
コード例 #2
0
        public async Task Restore_FallbackFolderContainsAllPackages()
        {
            using (var sourceDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var fallbackDir1 = TestFileSystemUtility.CreateRandomTestFolder())
                    using (var fallbackDir2 = TestFileSystemUtility.CreateRandomTestFolder())
                        using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder())
                            using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                            {
                                var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json");
                                var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                                XPlatTestUtils.AddDependency(spec, "a", "1.0.0");
                                XPlatTestUtils.AddDependency(spec, "b", "1.0.0");
                                XPlatTestUtils.WriteJson(spec, specPath);

                                var packageA = new SimpleTestPackageContext("a", "1.0.0");
                                var packageB = new SimpleTestPackageContext("b", "1.0.0");

                                var saveMode = PackageSaveMode.Nuspec | PackageSaveMode.Files;

                                await SimpleTestPackageUtility.CreateFolderFeedV3(
                                    fallbackDir2,
                                    saveMode,
                                    packageA,
                                    packageB);

                                var log = new TestCommandOutputLogger();

                                var config = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <config>
        <add key=""globalPackagesFolder"" value=""{packagesDir}"" />
    </config>
    <fallbackPackageFolders>
        <add key=""a"" value=""{fallbackDir1}"" />
        <add key=""b"" value=""{fallbackDir2}"" />
    </fallbackPackageFolders>
    <packageSources>
        <add key=""a"" value=""{sourceDir}"" />
    </packageSources>
</configuration>";

                                File.WriteAllText(Path.Combine(projectDir, "NuGet.Config"), config);

                                var args = new string[]
                                {
                                    "restore",
                                    projectDir,
                                };

                                // Act
                                var exitCode = Program.MainInternal(args, log);

                                // Assert
                                Assert.Equal(0, exitCode);
                                Assert.Equal(0, log.Errors);
                                Assert.Equal(0, log.Warnings);
                                Assert.Equal(0, Directory.GetDirectories(packagesDir).Length);
                            }
        }
コード例 #3
0
        public void Restore_WithMissingConfigFile_Fails()
        {
            using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var configDir = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json");
                    var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                    XPlatTestUtils.AddDependency(spec, "costura.fody", "1.3.3");
                    XPlatTestUtils.AddDependency(spec, "fody", "1.29.4");
                    XPlatTestUtils.WriteJson(spec, specPath);

                    var log = new TestCommandOutputLogger();

                    var args = new string[]
                    {
                        "restore",
                        projectDir,
                        "--configfile",
                        Path.Combine(configDir, "DoesNotExist.config"),
                    };

                    // Act
                    var exitCode = Program.MainInternal(args, log);

                    // Assert
                    Assert.Equal(1, exitCode);
                    Assert.Equal(1, log.Errors);
                    Assert.Contains("DoesNotExist.config", log.ShowErrors()); // file does not exist
                }
        }
コード例 #4
0
        public void RestoreCommand_VerifyMinClientVersionLocalFolder()
        {
            // Arrange
            using (var sourceDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder())
                    using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                    {
                        var packageContext = new SimpleTestPackageContext()
                        {
                            Id               = "packageA",
                            Version          = "1.0.0",
                            MinClientVersion = "9.9.9"
                        };

                        SimpleTestPackageUtility.CreatePackages(sourceDir, packageContext);

                        var specPath = Path.Combine(projectDir, "TestProject", "project.json");
                        var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                        XPlatTestUtils.AddDependency(spec, "packageA", "1.0.0");
                        XPlatTestUtils.WriteJson(spec, specPath);

                        var lockFilePath = Path.Combine(projectDir, "project.lock.json");
                        var log          = new TestCommandOutputLogger();

                        var args = new string[]
                        {
                            "restore",
                            projectDir,
                            "-s",
                            sourceDir,
                            "--packages",
                            packagesDir
                        };

                        // Act
                        var exitCode = Program.MainInternal(args, log);

                        // Assert
                        Assert.Equal(1, log.Errors);
                        Assert.Contains("'packageA 1.0.0' package requires NuGet client version '9.9.9' or above", log.ShowMessages());
                        Assert.False(File.Exists(lockFilePath));
                    }
        }
コード例 #5
0
        public void Restore_WithConfigFileInDifferentDirectory_Succeeds(string sourceUri)
        {
            using (var packagesDir = TestDirectory.Create())
                using (var projectDir = TestDirectory.Create())
                    using (var configDir = TestDirectory.Create())
                    {
                        var configFile = XPlatTestUtils.CopyFuncTestConfig(configDir);

                        var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json");
                        var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                        XPlatTestUtils.AddDependency(spec, "costura.fody", "1.3.3");
                        XPlatTestUtils.AddDependency(spec, "fody", "1.29.4");
                        XPlatTestUtils.WriteJson(spec, specPath);

                        var log = new TestCommandOutputLogger();

                        var args = new List <string>()
                        {
                            "restore",
                            projectDir,
                            "--packages",
                            packagesDir,
                            "--source",
                            sourceUri,
                            "--no-cache",
                            "--configfile",
                            configFile
                        };

                        // Act
                        int exitCode = NuGet.CommandLine.XPlat.Program.MainInternal(args.ToArray(), log);

                        Assert.Contains($@"OK {sourceUri}/FindPackagesById()?id='fody'", log.ShowMessages());
                        Assert.Equal(string.Empty, log.ShowErrors());
                        Assert.Equal(0, exitCode);

                        var lockFilePath = Path.Combine(projectDir, "XPlatRestoreTests", "project.lock.json");
                        Assert.True(File.Exists(lockFilePath));
                    }
        }
コード例 #6
0
        public async Task RestoreCommand_VerifyMinClientVersionAlreadyInstalled()
        {
            // Arrange
            using (var emptyDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder())
                    using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder())
                        using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                        {
                            var logger = new TestLogger();

                            var packageContext = new SimpleTestPackageContext()
                            {
                                Id               = "packageA",
                                Version          = "1.0.0",
                                MinClientVersion = "9.9.9"
                            };

                            var packagePath = Path.Combine(workingDir, "packageA.1.0.0.nupkg");

                            SimpleTestPackageUtility.CreatePackages(workingDir, packageContext);

                            // install the package
                            using (var fileStream = File.OpenRead(packagePath))
                            {
                                await PackageExtractor.InstallFromSourceAsync((stream) =>
                                                                              fileStream.CopyToAsync(stream, 4096, CancellationToken.None),
                                                                              new VersionFolderPathContext(new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")),
                                                                                                           packagesDir,
                                                                                                           logger,
                                                                                                           PackageSaveMode.Defaultv3,
                                                                                                           XmlDocFileSaveMode.None),
                                                                              CancellationToken.None);
                            }

                            var specPath = Path.Combine(projectDir, "TestProject", "project.json");
                            var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                            XPlatTestUtils.AddDependency(spec, "packageA", "1.0.0");
                            XPlatTestUtils.WriteJson(spec, specPath);

                            var lockFilePath = Path.Combine(projectDir, "project.lock.json");
                            var log          = new TestCommandOutputLogger();

                            var args = new string[]
                            {
                                "restore",
                                projectDir,
                                "-s",
                                emptyDir,
                                "--packages",
                                packagesDir
                            };

                            // Act
                            var exitCode = Program.MainInternal(args, log);

                            // Assert
                            Assert.Equal(1, log.Errors);
                            Assert.Contains("'packageA 1.0.0' package requires NuGet client version '9.9.9' or above", log.ShowMessages());
                            Assert.False(File.Exists(lockFilePath));
                        }
        }