private void AddNewAgent(string name, string agent) { if (string.IsNullOrWhiteSpace(name)) { throw new CommandLineException(Local.AgentsCommandNameRequired); } if (string.Equals(name, Local.ReservedPackageNameAll)) { throw new CommandLineException(Local.AgentsCommandAllNameIsReserved); } if (string.IsNullOrWhiteSpace(agent)) { throw new CommandLineException(Local.AgentsCommandAgentRequired); } if (!Utility.IsValidAgent(agent)) { throw new CommandLineException(Local.AgentsCommandInvalidAgent); } var list = AgentProvider.LoadPackageAgents().ToList(); if (list.Any(pr => string.Equals(name, pr.Name, StringComparison.OrdinalIgnoreCase))) { throw new CommandLineException(Local.AgentsCommandUniqueName); } if (list.Any(pr => string.Equals(agent, pr.Agent, StringComparison.OrdinalIgnoreCase))) { throw new CommandLineException(Local.AgentsCommandUniqueAgent); } var item = new PackageAgent(agent, name); list.Add(item); AgentProvider.SavePackageAgents(list); Console.WriteLine(Local.AgentsCommandAgentAddedSuccessfully, new object[] { name }); }
void AddNewAgent() { if (string.IsNullOrEmpty(Name)) { throw new CommandLineException(Local.AgentsCommandNameRequired); } if (string.Equals(Name, Local.ReservedPackageNameAll)) { throw new CommandLineException(Local.AgentsCommandAllNameIsReserved); } if (string.IsNullOrEmpty(Agent)) { throw new CommandLineException(Local.AgentsCommandAgentRequired); } // Make sure that the Agent given is a valid one. if (!Utility.IsValidAgent(Agent)) { throw new CommandLineException(Local.AgentsCommandInvalidAgent); } ValidateCredentials(); // Check to see if we already have a registered agent with the same name or agent if (AgentProvider.GetPackageAgentByName(Name) != null) { throw new CommandLineException(Local.AgentsCommandUniqueName); } if (AgentProvider.GetPackageAgentByAgent(Agent) != null) { throw new CommandLineException(Local.AgentsCommandUniqueAgent); } var agent = new PackageAgent(Agent, Name); AgentProvider.AddPackageAgent(agent); Console.WriteLine(Local.AgentsCommandAgentAddedSuccessfully, new object[] { Name }); }
void UpdatePackageAgent() { if (string.IsNullOrEmpty(Name)) { throw new CommandLineException(Local.AgentsCommandNameRequired); } var existingAgent = AgentProvider.GetPackageAgentByName(Name); if (existingAgent == null) { throw new CommandLineException(Local.AgentsCommandNoMatchingAgentsFound, new object[] { Name }); } if (!string.IsNullOrEmpty(Agent) && !existingAgent.Agent.Equals(Agent, StringComparison.OrdinalIgnoreCase)) { if (!Utility.IsValidAgent(Agent)) { throw new CommandLineException(Local.AgentsCommandInvalidAgent); } // If the user is updating the agent, verify we don't have a duplicate. if (AgentProvider.GetPackageAgentByAgent(Agent) != null) { throw new CommandLineException(Local.AgentsCommandUniqueAgent); } existingAgent = new PackageAgent(Agent, existingAgent.Name); } ValidateCredentials(); AgentProvider.UpdatePackageAgent(existingAgent, false); Console.WriteLine(Local.AgentsCommandUpdateSuccessful, new object[] { Name }); }
public void When_packageUrl_is_null_Then_it_throws_an_exception_with_a_useful_message() { var packageAgent = new PackageAgent(); Action getPackageAction = () => packageAgent.GetPackage(null).Wait(); getPackageAction .ShouldThrow <ArgumentNullException>("Because the packageUrl cannot be null") .WithMessage("Value cannot be null.\r\nParameter name: packageUri"); }
public void When_packageUrl_is_inaccessible_it_throws_an_exception_with_a_useful_message() { var packageAgent = new PackageAgent(); var packageName = Any.Word() + ".nupkg"; using (var mockService = new MockService() .OnRequest(r => r.Path.ToString() == "/" + packageName) .RespondWith(r => r.StatusCode = 403)) { var packageUri = new Uri(mockService.GetBaseAddress() + packageName); Action getPackageAction = () => packageAgent.GetPackage(packageUri).Wait(); getPackageAction .ShouldThrow <HttpRequestException>("Because the packageUrl cannot be null") .WithMessage("Response status code does not indicate success: 403 (Forbidden)."); } }
public async void When_packageUrl_is_valid_Then_it_returns_the_package() { var packageAgent = new PackageAgent(); var packageName = Any.Word() + ".nupkg"; Package package; using (var mockService = new MockService() .OnRequest(r => r.Path.ToString() == "/" + packageName) .RespondWith(r => r.WriteAsync(Resources.Microsoft_Bcl_1_1_8))) { var packageUri = new Uri(mockService.GetBaseAddress() + packageName); package = await packageAgent.GetPackage(packageUri); } package.Should().NotBeNull("Because it should be retrieved"); package.GetParts() .Should() .HaveCount(92, "Because that is how many package parts are in the Microsoft.Bcl.1.1.8 package"); }
public bool IsPackageAgentEnabled(PackageAgent source) { if (source == null) throw new ArgumentNullException("source"); return string.IsNullOrEmpty(_settingsManager.GetValue("disabledPackageSources", source.Name)); }
public void DisablePackageAgent(PackageAgent source) { if (source == null) throw new ArgumentNullException("source"); _settingsManager.SetValue("disabledPackageSources", source.Name, "true"); }