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 GiveSucessRestoreButFailedOnNextStepItCanRollBack(bool testMockBehaviorIsInSync) { FilePath nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var reporter = new BufferedReporter(); var packageObtainer = ConstructDefaultPackageObtainer(toolsPath, reporter, testMockBehaviorIsInSync); void FailedStepAfterSuccessRestore() => throw new GracefulException("simulated error"); try { using (var t = new TransactionScope()) { ToolConfigurationAndExecutablePath obtainAndReturnExecutablePathtransactional = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework); FailedStepAfterSuccessRestore(); t.Complete(); } } catch (GracefulException) { // catch the simulated error } AssertRollBack(toolsPath); }
public void GivenNugetConfigAndPackageNameAndVersionAndTargetFrameworkWhenCallItCanDownloadThePackage( bool testMockBehaviorIsInSync) { var reporter = new BufferedReporter(); FilePath nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var packageObtainer = ConstructDefaultPackageObtainer(toolsPath, reporter, testMockBehaviorIsInSync, nugetConfigPath.Value); ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, nugetconfig: nugetConfigPath, targetframework: _testTargetframework); reporter.Lines.Should().BeEmpty(); FilePath executable = toolConfigurationAndExecutablePath.Executable; File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); File.Delete(executable.Value); }
public void GivenNonExistentNugetConfigFileItThrows(bool testMockBehaviorIsInSync) { var reporter = new BufferedReporter(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var packageObtainer = ConstructDefaultPackageObtainer(toolsPath, reporter, testMockBehaviorIsInSync); var nonExistNugetConfigFile = new FilePath("NonExistent.file"); Action a = () => { ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, nugetconfig: nonExistNugetConfigFile, targetframework: _testTargetframework); }; a.ShouldThrow <PackageObtainException>() .And .Message.Should().Contain(string.Format( CommonLocalizableStrings.NuGetConfigurationFileDoesNotExist, Path.GetFullPath(nonExistNugetConfigFile.Value))); reporter.Lines.Should().BeEmpty(); }
public void GivenASourceItCanObtainThePackageFromThatSource(bool testMockBehaviorIsInSync) { var reporter = new BufferedReporter(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var packageObtainer = ConstructDefaultPackageObtainer( toolsPath, reporter, testMockBehaviorIsInSync: testMockBehaviorIsInSync, addSourceFeedWithFilePath: GetTestLocalFeedPath()); ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework, source: GetTestLocalFeedPath()); 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 GivenNugetConfigAndPackageNameAndVersionAndTargetFrameworkWhenCallItCreateAssetFile() { var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var packageObtainer = ConstructDefaultPackageObtainer(toolsPath); ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, nugetconfig: nugetConfigPath, targetframework: _testTargetframework); /* * From mytool.dll to project.assets.json * .dotnet/.tools/packageid/version/packageid/version/mytool.dll * /dependency1 package id/ * /dependency2 package id/ * /project.assets.json */ var assetJsonPath = toolConfigurationAndExecutablePath .Executable .GetDirectoryPath() .GetParentPath() .GetParentPath() .GetParentPath() .GetParentPath() .GetParentPath() .WithFile("project.assets.json").Value; File.Exists(assetJsonPath) .Should() .BeTrue(assetJsonPath + " should be created"); }
public void GivenAllButNoTargetFrameworkItCanDownloadThePackage() { var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var packageObtainer = new ToolPackageObtainer( new DirectoryPath(toolsPath), new DirectoryPath("no such path"), GetUniqueTempProjectPathEachTest, new Lazy <string>(() => BundledTargetFramework.GetTargetFrameworkMoniker()), new PackageToProjectFileAdder(), new ProjectRestorer()); ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, nugetconfig: nugetConfigPath); var executable = toolConfigurationAndExecutablePath.Executable; File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); }
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(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 GivenAllButNoPackageVersionItCanDownloadThePackage() { var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName()); var packageObtainer = ConstructDefaultPackageObtainer(toolsPath); ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, nugetconfig: nugetConfigPath, targetframework: _testTargetframework); var executable = toolConfigurationAndExecutablePath.Executable; File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); }