public void GivenAllButNoNugetConfigFilePathItCanDownloadThePackage() { var uniqueTempProjectPath = GetUniqueTempProjectPathEachTest(); var tempProjectDirectory = uniqueTempProjectPath.GetDirectoryPath(); var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); Directory.CreateDirectory(tempProjectDirectory.Value); /* * In test, we don't want NuGet to keep look up, so we point current directory to nugetconfig. */ Directory.SetCurrentDirectory(nugetConfigPath.GetDirectoryPath().Value); var packageObtainer = new ToolPackageObtainer( new DirectoryPath(toolsPath), new DirectoryPath("no such path"), () => uniqueTempProjectPath, new Lazy <string>(), new PackageToProjectFileAdder(), new ProjectRestorer()); ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework); var executable = toolConfigurationAndExecutablePath.Executable; File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); }
public void GivenAllButNoTargetFrameworkItCanDownloadThePackage() { var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var packageObtainer = new ToolPackageObtainer( new DirectoryPath(toolsPath), GetUniqueTempProjectPathEachTest, new Lazy <string>(() => BundledTargetFramework.GetTargetFrameworkMoniker()), new PackageToProjectFileAdder(), new ProjectRestorer()); ToolConfigurationAndExecutableDirectory toolConfigurationAndExecutableDirectory = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, nugetconfig: nugetConfigPath); var executable = toolConfigurationAndExecutableDirectory .ExecutableDirectory .WithFile( toolConfigurationAndExecutableDirectory .Configuration .ToolAssemblyEntryPoint); File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); }
public void GivenOfflineFeedWhenCallItCanDownloadThePackage() { var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); ToolPackageObtainer packageObtainer = new ToolPackageObtainer( toolsPath: new DirectoryPath(toolsPath), offlineFeedPath: new DirectoryPath(GetTestLocalFeedPath()), getTempProjectPath: GetUniqueTempProjectPathEachTest, bundledTargetFrameworkMoniker: new Lazy<string>(), projectRestorer: new ProjectRestorer()); ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework); var executable = toolConfigurationAndExecutablePath .Executable; File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); executable.Value.Should().NotContain(GetTestLocalFeedPath(), "Executable should not be still in fallbackfolder"); executable.Value.Should().Contain(toolsPath, "Executable should be copied to tools Path"); File.Delete(executable.Value); }
public void GivenAllButNoTargetFrameworkItCanDownloadThePackage(bool testMockBehaviorIsInSync) { var reporter = new BufferedReporter(); var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); IToolPackageObtainer packageObtainer; if (testMockBehaviorIsInSync) { packageObtainer = new ToolPackageObtainerMock(additionalFeeds: new List <MockFeed> { new MockFeed { Type = MockFeedType.ExplicitNugetConfig, Uri = nugetConfigPath.Value, Packages = new List <MockFeedPackage> { new MockFeedPackage { PackageId = TestPackageId, Version = "1.0.4" } } } }, toolsPath: toolsPath); } else { packageObtainer = new ToolPackageObtainer( new DirectoryPath(toolsPath), new DirectoryPath("no such path"), GetUniqueTempProjectPathEachTest, new Lazy <string>(() => BundledTargetFramework.GetTargetFrameworkMoniker()), new ProjectRestorer(reporter)); } ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, nugetconfig: nugetConfigPath); reporter.Lines.Should().BeEmpty(); var executable = toolConfigurationAndExecutablePath.Executable; File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); File.Delete(executable.Value); }
public void GivenNoFeedItThrows() { var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); ToolPackageObtainer packageObtainer = ConstructDefaultPackageObtainer(toolsPath); Action a = () => packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework); a.ShouldThrow <PackageObtainException>(); }
private static ToolConfigurationAndExecutablePath ObtainPackage( DirectoryPath executablePackagePath, DirectoryPath offlineFeedPath) { try { FilePath?configFile = null; if (_configFilePath != null) { configFile = new FilePath(_configFilePath); } var toolPackageObtainer = new ToolPackageObtainer( executablePackagePath, offlineFeedPath, () => new DirectoryPath(Path.GetTempPath()) .WithSubDirectories(Path.GetRandomFileName()) .WithFile(Path.GetRandomFileName() + ".csproj"), new Lazy <string>(BundledTargetFramework.GetTargetFrameworkMoniker), new PackageToProjectFileAdder(), new ProjectRestorer()); return(toolPackageObtainer.ObtainAndReturnExecutablePath( packageId: _packageId, packageVersion: _packageVersion, nugetconfig: configFile, targetframework: _framework, source: _source)); } catch (PackageObtainException ex) { throw new GracefulException( message: string.Format(LocalizableStrings.InstallFailedNuget, ex.Message), innerException: ex); } catch (ToolConfigurationException ex) { throw new GracefulException( message: string.Format( LocalizableStrings.InstallFailedPackage, ex.Message), innerException: ex); } }
private static ToolConfigurationAndExecutableDirectory ObtainPackage( string packageId, string packageVersion, FilePath?configFile, string framework, DirectoryPath executablePackagePath) { try { var toolPackageObtainer = new ToolPackageObtainer( executablePackagePath, () => new DirectoryPath(Path.GetTempPath()) .WithSubDirectories(Path.GetRandomFileName()) .WithFile(Path.GetRandomFileName() + ".csproj"), new Lazy <string>(BundledTargetFramework.GetTargetFrameworkMoniker), new PackageToProjectFileAdder(), new ProjectRestorer()); return(toolPackageObtainer.ObtainAndReturnExecutablePath( packageId: packageId, packageVersion: packageVersion, nugetconfig: configFile, targetframework: framework)); } catch (PackageObtainException ex) { throw new GracefulException( message: $"Install failed. Failed to download package:{Environment.NewLine}" + $"NuGet returned:{Environment.NewLine}" + $"{Environment.NewLine}" + $"{ex.Message}", innerException: ex); } catch (ToolConfigurationException ex) { throw new GracefulException( message: $"Install failed. The settings file in the tool's NuGet package is not valid. Please contact the owner of the NuGet package.{Environment.NewLine}" + $"The error was:{Environment.NewLine}" + $"{Environment.NewLine}" + $"{ex.Message}", innerException: ex); } }
public void GivenNoFeedItThrows() { var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); ToolPackageObtainer packageObtainer = new ToolPackageObtainer( new DirectoryPath(toolsPath), new DirectoryPath("no such path"), GetUniqueTempProjectPathEachTest, new Lazy<string>(), new ProjectRestorer()); Action a = () => packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework); a.ShouldThrow<PackageObtainException>(); }
public void GivenAllButNoNugetConfigFilePathItCanDownloadThePackage() { var uniqueTempProjectPath = GetUniqueTempProjectPathEachTest(); var tempProjectDirectory = uniqueTempProjectPath.GetDirectoryPath(); var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); Directory.CreateDirectory(tempProjectDirectory.Value); /* * No nuget config means you don't need nuget config passed in during call * NuGet needs a way to find the package, in production, it will keep look up folders for Nuget.Config * and use the feed there. * In test, we don't want NuGet to keep look up, so we just copy paste beside the project. */ File.Copy(nugetConfigPath.Value, tempProjectDirectory.WithFile("nuget.config").Value); var packageObtainer = new ToolPackageObtainer( new DirectoryPath(toolsPath), () => uniqueTempProjectPath, new Lazy <string>(), new PackageToProjectFileAdder(), new ProjectRestorer()); ToolConfigurationAndExecutableDirectory toolConfigurationAndExecutableDirectory = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework); var executable = toolConfigurationAndExecutableDirectory .ExecutableDirectory .WithFile( toolConfigurationAndExecutableDirectory .Configuration .ToolAssemblyEntryPoint); File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); }