Esempio n. 1
0
        public async Task GetSatelliteFilesAsync_ReturnsSatelliteFilesForSatellitePackage()
        {
            using (var testDirectory = TestDirectory.Create())
            {
                var packageIdentity     = new PackageIdentity("A", new NuGetVersion("1.2.3"));
                var packagePathResolver = new PackagePathResolver(testDirectory.Path);
                var packageFileInfo     = await TestPackagesCore.GetRuntimePackageAsync(
                    testDirectory.Path,
                    packageIdentity.Id,
                    packageIdentity.Version.ToNormalizedString());

                var satellitePackageInfo = await TestPackagesCore.GetSatellitePackageAsync(
                    testDirectory.Path,
                    packageIdentity.Id,
                    packageIdentity.Version.ToNormalizedString(),
                    language : "fr");

                using (var packageReader = new PackageArchiveReader(File.OpenRead(satellitePackageInfo.FullName)))
                {
                    var result = await PackageHelper.GetSatelliteFilesAsync(packageReader, packagePathResolver, CancellationToken.None);

                    var runtimePackageDirectory = result.Item1;
                    var satelliteFiles          = result.Item2;

                    Assert.Equal(testDirectory.Path, runtimePackageDirectory);
                    Assert.Equal(new[] { "lib/net45/fr/A.resources.dll" }, satelliteFiles);
                }
            }
        }
Esempio n. 2
0
        public async Task GetInstalledSatelliteFilesAsync_ReturnsInstalledSatelliteFiles()
        {
            using (var testDirectory = TestDirectory.Create())
            {
                var packageIdentity     = new PackageIdentity("A", new NuGetVersion("1.2.3"));
                var packagePathResolver = new PackagePathResolver(testDirectory.Path);
                var packageFileInfo     = await TestPackagesCore.GetRuntimePackageAsync(
                    testDirectory.Path,
                    packageIdentity.Id,
                    packageIdentity.Version.ToNormalizedString());

                var satellitePackageInfo = await TestPackagesCore.GetSatellitePackageAsync(
                    testDirectory.Path,
                    packageIdentity.Id,
                    packageIdentity.Version.ToNormalizedString(),
                    language : "fr");

                // Install runtime package
                using (var packageReader = new PackageArchiveReader(File.OpenRead(packageFileInfo.FullName)))
                    using (var packageStream = File.OpenRead(packageFileInfo.FullName))
                    {
                        await PackageExtractor.ExtractPackageAsync(
                            packageReader,
                            packageStream,
                            packagePathResolver,
                            new PackageExtractionContext(NullLogger.Instance),
                            CancellationToken.None);
                    }

                // Install satellite package
                using (var packageReader = new PackageArchiveReader(File.OpenRead(satellitePackageInfo.FullName)))
                    using (var packageStream = File.OpenRead(satellitePackageInfo.FullName))
                    {
                        await PackageExtractor.ExtractPackageAsync(
                            packageReader,
                            packageStream,
                            packagePathResolver,
                            new PackageExtractionContext(NullLogger.Instance),
                            CancellationToken.None);
                    }

                using (var packageReader = new PackageArchiveReader(File.OpenRead(satellitePackageInfo.FullName)))
                {
                    var result = await PackageHelper.GetInstalledSatelliteFilesAsync(
                        packageReader,
                        packagePathResolver,
                        PackageSaveMode.Defaultv3,
                        CancellationToken.None);

                    var runtimePackageDirectory = result.Item1;
                    var satelliteFiles          = result.Item2.ToArray();
                    var packageDirectoryName    = $"{packageIdentity.Id}.{packageIdentity.Version.ToNormalizedString()}";

                    Assert.Equal(Path.Combine(testDirectory.Path, packageDirectoryName), runtimePackageDirectory);
                    Assert.Equal(1, satelliteFiles.Length);
                    Assert.Equal(Path.Combine(testDirectory.Path, packageDirectoryName, "lib/net45/fr/A.resources.dll"), satelliteFiles[0].FileFullPath);
                }
            }
        }
        public async Task GetInstalledSatelliteFilesAsync_ReturnsEmptyEnumerableForNoInstalledSatelliteFiles()
        {
            using (var test = PackageHelperTest.Create(TestPackagesCore.GetPackageContentReaderTestPackage()))
            {
                using (var testDirectory = TestDirectory.Create())
                {
                    var packageIdentity     = new PackageIdentity("A", new NuGetVersion("1.2.3"));
                    var packagePathResolver = new PackagePathResolver(testDirectory.Path);
                    var packageFileInfo     = await TestPackagesCore.GetRuntimePackageAsync(
                        testDirectory.Path,
                        packageIdentity.Id,
                        packageIdentity.Version.ToNormalizedString());

                    var satellitePackageInfo = await TestPackagesCore.GetSatellitePackageAsync(
                        testDirectory.Path,
                        packageIdentity.Id,
                        packageIdentity.Version.ToNormalizedString(),
                        language : "fr");

                    // Install runtime package
                    using (var packageReader = new PackageArchiveReader(File.OpenRead(packageFileInfo.FullName)))
                        using (var packageStream = File.OpenRead(packageFileInfo.FullName))
                        {
                            await PackageExtractor.ExtractPackageAsync(
                                test.Root,
                                packageReader,
                                packageStream,
                                packagePathResolver,
                                new PackageExtractionContext(
                                    PackageSaveMode.Defaultv2,
                                    PackageExtractionBehavior.XmlDocFileSaveMode,
                                    NullLogger.Instance,
                                    signedPackageVerifier : null,
                                    signedPackageVerifierSettings : null),
                                CancellationToken.None);
                        }

                    using (var packageReader = new PackageArchiveReader(File.OpenRead(satellitePackageInfo.FullName)))
                    {
                        var result = await PackageHelper.GetInstalledSatelliteFilesAsync(
                            packageReader,
                            packagePathResolver,
                            PackageSaveMode.Defaultv3,
                            CancellationToken.None);

                        var runtimePackageDirectory = result.Item1;
                        var satelliteFiles          = result.Item2;
                        var packageDirectoryName    = $"{packageIdentity.Id}.{packageIdentity.Version.ToNormalizedString()}";

                        Assert.Equal(Path.Combine(testDirectory.Path, packageDirectoryName), runtimePackageDirectory);
                        Assert.Empty(satelliteFiles);
                    }
                }
            }
        }
Esempio n. 4
0
        public async Task PushToServerWhichRejectsDuplicates_SkipDuplicate_Succeeds(PackageSource packageSource)
        {
            // Arrange
            using (var packageDir = TestDirectory.Create())
                using (TestFileSystemUtility.SetCurrentDirectory(packageDir))
                {
                    var packageId      = "XPlatPushTests.PushToServerSucceeds";
                    var packageVersion = "1.0.0";
                    var packageFile    = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);

                    var configFile    = XPlatTestUtils.CopyFuncTestConfig(packageDir);
                    var logFirstPush  = new TestCommandOutputLogger();
                    var logSecondPush = new TestCommandOutputLogger();

                    var apiKey = XPlatTestUtils.ReadApiKey(packageSource.Name);
                    Assert.False(string.IsNullOrEmpty(apiKey));
                    var pushArgs = new List <string>
                    {
                        "push",
                        packageFile.FullName,
                        "--source",
                        packageSource.Source,
                        "--api-key",
                        apiKey,
                        "--skip-duplicate"
                    };

                    // Act
                    var exitCodeFirstPush  = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), logFirstPush);
                    var exitCodeSecondPush = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), logSecondPush);

                    // Assert First Push - it should happen without error.
                    var outputMessagesFirstPush = logFirstPush.ShowMessages();
                    Assert.Equal(string.Empty, logFirstPush.ShowErrors());
                    Assert.Equal(0, exitCodeFirstPush);

                    // Assert Second Push - it should happen without error, even though a duplicate is present.
                    var outputMessagesSecondPush = logSecondPush.ShowMessages();

                    Assert.Equal(string.Empty, logSecondPush.ShowErrors());
                    Assert.Equal(0, exitCodeSecondPush);
                    Assert.Contains($"PUT {packageSource.Source}", outputMessagesSecondPush);
                    Assert.DoesNotContain("already exists at feed", outputMessagesSecondPush);
                    Assert.Contains("Your package was pushed.", outputMessagesSecondPush);
                }
        }
Esempio n. 5
0
        public async Task Verify_UnSignedPackage_Fails()
        {
            using (var packageDir = TestDirectory.Create())
            {
                var packageId      = "Unsigned.PackageX";
                var packageVersion = "1.0.0";
                var packageFile    = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);

                //Act
                var result = _msbuildFixture.RunDotnet(
                    packageDir,
                    $"nuget verify {packageFile.FullName}",
                    ignoreExitCode: true);

                result.Success.Should().BeFalse(because: result.AllOutput);
                result.Output.Should().Contain(_notSignedErrorCode);
            }
        }
Esempio n. 6
0
        public async Task PushToServerSkipDuplicateSucceeds(PackageSource packageSource)
        {
            // Arrange
            using (var packageDir = TestDirectory.Create())
                using (TestFileSystemUtility.SetCurrentDirectory(packageDir))
                {
                    var packageId      = "XPlatPushTests.PushToServerSucceeds";
                    var packageVersion = "1.0.0";
                    var packageFile    = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);

                    var configFile = XPlatTestUtils.CopyFuncTestConfig(packageDir);
                    var log        = new TestCommandOutputLogger();

                    var apiKey = XPlatTestUtils.ReadApiKey(packageSource.Name);
                    Assert.False(string.IsNullOrEmpty(apiKey));

                    var pushArgs = new List <string>
                    {
                        "push",
                        packageFile.FullName,
                        "--source",
                        packageSource.Source,
                        "--api-key",
                        apiKey,
                        "--skip-duplicate"
                    };

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

                    // Assert
                    var outputMessages = log.ShowMessages();

                    Assert.Equal(string.Empty, log.ShowErrors());
                    Assert.Equal(0, exitCode);
                    Assert.Contains($"PUT {packageSource.Source}", outputMessages);


                    //info: PUT http://localhost:5000/api/v2/package/
                    //info: Conflict http://localhost:5000/api/v2/package/ 127ms
                    Assert.Contains("already exists at feed", outputMessages);
                    Assert.Contains("Your package was pushed.", outputMessages);
                }
        }
Esempio n. 7
0
        // [InlineData(TestServers.Klondike, nameof(TestServers.Klondike), false)] // 500 Internal Server Error pushing
        // [InlineData(TestServers.NuGetServer, nameof(TestServers.NuGetServer), false)] // 500 - missing manifest?
        public async Task PushToServerSucceeds(string sourceUri, string feedName, bool mustDeleteFirst)
        {
            // Arrange
            using (var packageDir = TestDirectory.Create())
                using (TestFileSystemUtility.SetCurrentDirectory(packageDir))
                {
                    var packageId      = "XPlatPushTests.PushToServerSucceeds";
                    var packageVersion = "1.0.0";
                    var packageFile    = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);

                    var configFile = XPlatTestUtils.CopyFuncTestConfig(packageDir);
                    var log        = new TestCommandOutputLogger();

                    var apiKey = XPlatTestUtils.ReadApiKey(feedName);
                    Assert.False(string.IsNullOrEmpty(apiKey));

                    if (mustDeleteFirst)
                    {
                        DeletePackageBeforePush(packageId, packageVersion, sourceUri, apiKey);
                    }

                    var pushArgs = new List <string>()
                    {
                        "push",
                        packageFile.FullName,
                        "--source",
                        sourceUri,
                        "--api-key",
                        apiKey
                    };

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

                    // Assert
                    Assert.Equal(string.Empty, log.ShowErrors());
                    Assert.Equal(0, exitCode);
                    Assert.Contains($"PUT {sourceUri}", log.ShowMessages());
                    Assert.Contains("Your package was pushed.", log.ShowMessages());
                }
        }
Esempio n. 8
0
        public async Task GetInstalledSatelliteFilesAsync_ReturnsRuntimePackageDirectoryIfRuntimePackageExistsButIsNotInstalled()
        {
            using (var test = PackageHelperTest.Create(TestPackagesCore.GetPackageContentReaderTestPackage()))
            {
                using (var testDirectory = TestDirectory.Create())
                {
                    var packageIdentity     = new PackageIdentity("A", new NuGetVersion("1.2.3"));
                    var packagePathResolver = new PackagePathResolver(testDirectory.Path);
                    var packageFileInfo     = await TestPackagesCore.GetRuntimePackageAsync(
                        testDirectory.Path,
                        packageIdentity.Id,
                        packageIdentity.Version.ToNormalizedString());

                    var satellitePackageInfo = await TestPackagesCore.GetSatellitePackageAsync(
                        testDirectory.Path,
                        packageIdentity.Id,
                        packageIdentity.Version.ToNormalizedString(),
                        language : "fr");

                    using (var packageReader = new PackageArchiveReader(File.OpenRead(satellitePackageInfo.FullName)))
                    {
                        var result = await PackageHelper.GetInstalledSatelliteFilesAsync(
                            packageReader,
                            packagePathResolver,
                            PackageSaveMode.Defaultv3,
                            CancellationToken.None);

                        var runtimePackageDirectory = result.Item1;
                        var satelliteFiles          = result.Item2;

                        Assert.Equal(testDirectory.Path, runtimePackageDirectory);
                        Assert.Empty(satelliteFiles);
                    }
                }
            }
        }
Esempio n. 9
0
        public async Task PushMultiplePathsToFileSystemSource()
        {
            using (var packageDirectory = TestDirectory.Create())
                using (var source = TestDirectory.Create())
                {
                    // Arrange
                    var log = new TestCommandOutputLogger();
                    var packageInfoCollection = new[]
                    {
                        await TestPackagesCore.GetRuntimePackageAsync(packageDirectory, "testPackageA", "1.1.0"),
                        await TestPackagesCore.GetRuntimePackageAsync(packageDirectory, "testPackageB", "1.1.0"),
                    };

                    var pushArgs = new List <string>
                    {
                        "push",
                        packageInfoCollection[0].FullName,
                        packageInfoCollection[1].FullName,
                        "--source",
                        source,
                    };

                    // Act
                    var exitCode = CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), log);

                    // Assert
                    Assert.Equal(string.Empty, log.ShowErrors());
                    Assert.Equal(0, exitCode);

                    foreach (var packageInfo in packageInfoCollection)
                    {
                        Assert.Contains($"Pushing {packageInfo.Name}", log.ShowMessages());
                        Assert.True(File.Exists(Path.Combine(source, packageInfo.Name)));
                    }
                }
        }