public void PackageSourceCredentialsTest(string name) { var resourcesFolder = Path.Combine(Directory.GetCurrentDirectory().ToString(), "Assets/Tests/Resources"); var path = Path.Combine(resourcesFolder, "NuGet.config"); var username = "******"; var password = "******"; NugetConfigFile file = NugetConfigFile.CreateDefaultFile(path); NugetPackageSource inputSource = new NugetPackageSource(name, "localhost") { UserName = username, SavedPassword = password }; file.PackageSources.Add(inputSource); file.Save(path); var loaded = NugetConfigFile.Load(path); var parsedSource = loaded.PackageSources.Find(p => p.Name == name); Assert.That(parsedSource.HasPassword, Is.True); Assert.That(parsedSource.UserName, Is.EqualTo(username)); Assert.That(parsedSource.SavedPassword, Is.EqualTo(password)); }
public async Task LoadConfigFileAsync() { var configContent = (await _fileService.ReadFromFileAsync(_defaultGlobalConfigFilePath, CancellationToken.None)) !; // todo handle the lack of nugetconfig file var document = XDocument.Parse(configContent); var root = document.Root !; var sourcesNode = root.Element("packageSources") !; var credentialsListNode = root.Element("packageSourceCredentials") !; var sources = sourcesNode.Elements("add").Select(e => { var key = e.Attribute("key") !.Value; var path = e.Attribute("value") !.Value; XElement?credentialsNode; try { credentialsNode = credentialsListNode.Element(key); } catch (XmlException) { return(new NugetPackageSource { Key = key, Path = path, Credentials = null }); } if (credentialsNode == null) { return(new NugetPackageSource { Key = key, Path = path, Credentials = null }); } var userName = GetValue(credentialsNode, "Username") ?? throw new NullReferenceException("Username not found"); var clearPassword = GetValue(credentialsNode, "ClearTextPassword"); return(new NugetPackageSource { Key = key, Path = path, Credentials = new Credentials { IsPasswordClearText = true, Password = clearPassword, Username = userName } }); }); var repositoryPath = GetValue(root.Element("config") !, "repositoryPath") !; _configFile = new NugetConfigFile(sources, repositoryPath); }
public void Test1(string resource) { NugetConfigFile config; CSProjFile proj; GenerateNuspec task = new GenerateNuspec(); using (Stream stream = typeof(TestValidation).Assembly.GetManifestResourceStream($"Gehtsoft.Build.Nuget.Test.res.{resource}.xml")) { config = new NugetConfigFile(stream); } using (Stream stream = typeof(TestValidation).Assembly.GetManifestResourceStream($"Gehtsoft.Build.Nuget.Test.res.{resource}.csproj")) { proj = new CSProjFile(stream); } NugetSpecificationFile spec; Action action = () => spec = task.HandleProject(config.Projects[0], proj, new FileInfo(typeof(TestValidation).Assembly.Location), config); action.Should().NotThrow(); ; }