public override void ExecuteCommand() { if (Self) { var selfUpdater = new SelfUpdater(RepositoryFactory) { Console = Console }; selfUpdater.UpdateSelf(); } else { string inputFile = GetInputFile(); if (String.IsNullOrEmpty(inputFile)) { throw new CommandLineException(NuGetResources.InvalidFile); } else if (inputFile.EndsWith(Constants.PackageReferenceFile, StringComparison.OrdinalIgnoreCase)) { UpdatePackages(inputFile); } else { if (!FileSystem.FileExists(inputFile)) { throw new CommandLineException(NuGetResources.UnableToFindSolution, inputFile); } else { string solutionDir = Path.GetDirectoryName(inputFile); UpdateAllPackages(solutionDir); } } } }
public override void ExecuteCommand() { // update with self as parameter if (Self) { var selfUpdater = new SelfUpdater(RepositoryFactory) { Console = Console, IncludePrerelease = Prerelease }; selfUpdater.UpdateSelf(); return; } string inputFile = GetInputFile(); if (string.IsNullOrEmpty(inputFile)) { throw new CommandLineException(NuGetResources.InvalidFile); } string inputFileName = Path.GetFileName(inputFile); // update with packages.config as parameter if (PackageReferenceFile.IsValidConfigFileName(inputFileName)) { UpdatePackages(inputFile); return; } // update with project file as parameter if (ProjectHelper.SupportedProjectExtensions.Contains(Path.GetExtension(inputFile) ?? string.Empty)) { if (!FileSystem.FileExists(inputFile)) { throw new CommandLineException(NuGetResources.UnableToFindProject, inputFile); } UpdatePackages(new MSBuildProjectSystem(inputFile)); return; } if (!FileSystem.FileExists(inputFile)) { throw new CommandLineException(NuGetResources.UnableToFindSolution, inputFile); } // update with solution as parameter string solutionDir = Path.GetDirectoryName(inputFile); UpdateAllPackages(solutionDir); }
public void SelfUpdateNoCommandLinePackageOnServerThrows() { // Arrange var factory = new Mock<IPackageRepositoryFactory>(); factory.Setup(m => m.CreateRepository(It.IsAny<string>())).Returns(new MockPackageRepository()); ConsoleInfo consoleInfo = GetConsoleInfo(); var selfUpdater = new SelfUpdater(factory.Object) { Console = consoleInfo.Console }; // Act ExceptionAssert.Throws<CommandLineException>(() => selfUpdater.SelfUpdate("c:\foo.exe", new SemanticVersion("2.0")), "Unable to find 'NuGet.CommandLine' package."); }
public void SelfUpdateNoNuGetExeInNuGetExePackageThrows() { // Arrange var factory = new Mock<IPackageRepositoryFactory>(); var repository = new MockPackageRepository(); repository.Add(PackageUtility.CreatePackage("NuGet.CommandLine", "3.0")); factory.Setup(m => m.CreateRepository(It.IsAny<string>())).Returns(repository); ConsoleInfo consoleInfo = GetConsoleInfo(); var selfUpdater = new SelfUpdater(factory.Object) { Console = consoleInfo.Console }; // Act & Assert ExceptionAssert.Throws<CommandLineException>(() => selfUpdater.SelfUpdate("c:\foo.exe", new SemanticVersion("2.0")), "Invalid NuGet.CommandLine package. Unable to locate NuGet.exe within the package."); }
public void SelfUpdateOlderVersionDoesNotUpdate() { // Arrange var factory = new Mock<IPackageRepositoryFactory>(); var repository = new MockPackageRepository(); repository.Add(PackageUtility.CreatePackage("NuGet.CommandLine", "1.0")); factory.Setup(m => m.CreateRepository(It.IsAny<string>())).Returns(repository); ConsoleInfo consoleInfo = GetConsoleInfo(); var selfUpdater = new SelfUpdater(factory.Object) { Console = consoleInfo.Console }; // Act selfUpdater.SelfUpdate("c:\foo.exe", new SemanticVersion("2.0")); // Assert Assert.Equal("NuGet.exe is up to date.", consoleInfo.WrittenLines[0]); }