public void Sources_WhenAddingSourceWithCredentialsToUserConfigFile_CredentialsWereAddedAndEncryptedInUserConfigFile() { // Arrange using (var configFileDirectory = _fixture.CreateTestDirectory()) { var configFileName = "nuget.config"; var configFilePath = Path.Combine(configFileDirectory, configFileName); string nugetConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> </configuration>"; CreateXmlFile(configFilePath, nugetConfig); var args = new string[] { "nuget", "add", "source", "https://source.test", "--name", "test_source", "--username", "test_user_name", "--password", "test_password", "--configfile", configFilePath }; // Act var result = _fixture.RunDotnet(configFileDirectory, string.Join(" ", args), ignoreExitCode: true); // Assert Assert.True(result.Success, result.AllOutput); var settings = Settings.LoadDefaultSettings( configFileDirectory, configFileName, null); var packageSourcesSection = settings.GetSection("packageSources"); var sourceItem = packageSourcesSection?.GetFirstItemWithAttribute <SourceItem>("key", "test_source"); Assert.Equal("https://source.test", sourceItem.GetValueAsPath()); var sourceCredentialsSection = settings.GetSection("packageSourceCredentials"); var credentialItem = sourceCredentialsSection?.Items.First(c => string.Equals(c.ElementName, "test_source", StringComparison.OrdinalIgnoreCase)) as CredentialsItem; Assert.NotNull(credentialItem); Assert.Equal("test_user_name", credentialItem.Username); var password = EncryptionUtility.DecryptString(credentialItem.Password); Assert.Equal("test_password", password); } }
public void Sources_WarnWhenUpdatingHttpSource(string updateSource, bool shouldWarn) { using (TestDirectory configFileDirectory = _fixture.CreateTestDirectory()) { string configFileName = "nuget.config"; string configFilePath = Path.Combine(configFileDirectory, configFileName); var nugetConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""test_source"" value=""http://source.test.initial"" /> </packageSources> </configuration>"; CreateXmlFile(configFilePath, nugetConfig); ISettings settings = Settings.LoadDefaultSettings( configFileDirectory, configFileName, null); PackageSourceProvider packageSourceProvider = new PackageSourceProvider(settings); var sources = packageSourceProvider.LoadPackageSources().ToList(); Assert.Single(sources); PackageSource source = sources.Single(); Assert.Equal("test_source", source.Name); Assert.Equal("http://source.test.initial", source.Source); // Arrange var args = new string[] { "nuget", "update", "source", "test_source", "--source", updateSource, "--configfile", configFilePath }; // Act CommandRunnerResult result = _fixture.RunDotnet(configFileDirectory, string.Join(" ", args), ignoreExitCode: true); // Assert Assert.True(result.Success, result.Output + " " + result.Errors); ISettings loadedSettings = Settings.LoadDefaultSettings(root: configFileDirectory, configFileName: null, machineWideSettings: null); SettingSection packageSourcesSection = loadedSettings.GetSection("packageSources"); SourceItem sourceItem = packageSourcesSection?.GetFirstItemWithAttribute <SourceItem>("key", "test_source"); Assert.Equal(updateSource, sourceItem.GetValueAsPath()); Assert.Equal(shouldWarn, result.Output.Contains("warn : You are running the 'update source' operation with an 'HTTP' source")); } }
public void RestoreCommand_DisplaysCPVMInPreviewMessageIfCPVMEnabled() { using (var testDirectory = _msbuildFixture.CreateTestDirectory()) { // Arrange var projectName = "ClassLibrary1"; var workingDirectory = Path.Combine(testDirectory, projectName); var projectFile = Path.Combine(workingDirectory, $"{projectName}.csproj"); _msbuildFixture.CreateDotnetNewProject(testDirectory.Path, projectName, " classlib", 60000); using (var stream = new FileStream(projectFile, FileMode.Open, FileAccess.ReadWrite)) { var xml = XDocument.Load(stream); ProjectFileUtils.AddProperty( xml, "ManagePackageVersionsCentrally", "true"); ProjectFileUtils.WriteXmlToFile(xml, stream); } // The test depends on the presence of these packages and their versions. // Change to Directory.Packages.props when new cli that supports NuGet.props will be downloaded var directoryPackagesPropsName = Path.Combine(workingDirectory, $"Directory.Build.props"); var directoryPackagesPropsContent = @"<Project> <PropertyGroup> <CentralPackageVersionsFileImported>true</CentralPackageVersionsFileImported> </PropertyGroup> </Project>"; File.WriteAllText(directoryPackagesPropsName, directoryPackagesPropsContent); // Act var result = _msbuildFixture.RunDotnet(workingDirectory, "restore /v:n"); // Assert Assert.True(result.Output.Contains($"The project {projectFile} is using CentralPackageVersionManagement, a NuGet preview feature.")); } }
public void DotnetToolTests_NoPackageReferenceToolRestore_ThrowsError() { using (var testDirectory = _msbuildFixture.CreateTestDirectory()) { var tfm = "netcoreapp2.0"; var projectName = "ToolRestoreProject"; var workingDirectory = Path.Combine(testDirectory, projectName); var rid = "win-x86"; _msbuildFixture.CreateDotnetToolProject(testDirectory.Path, projectName, tfm, rid); // Act var result = _msbuildFixture.RestoreToolProject(workingDirectory, projectName, string.Empty); // Assert Assert.True(result.ExitCode == 1, result.AllOutput); Assert.Contains("NU1211", result.Output); } }
public void DotnetToolTests_NoPackageReferenceToolRestore_ThrowsError() { using (var testDirectory = _msbuildFixture.CreateTestDirectory()) { var tfm = "netcoreapp2.0"; var projectName = "ToolRestoreProject"; var workingDirectory = Path.Combine(testDirectory, projectName); var source = workingDirectory; var rid = "win-x86"; var packages = new List <PackageIdentity>(); _msbuildFixture.CreateDotnetToolProject(solutionRoot: testDirectory.Path, projectName: projectName, targetFramework: tfm, rid: rid, source: workingDirectory, packages: packages); // Act var result = _msbuildFixture.RestoreToolProject(workingDirectory, projectName, string.Empty); // Assert Assert.True(result.Item1 == 1, result.AllOutput); Assert.Contains("NU1211", result.Item2); } }