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 GivenAllButNoNugetConfigFilePathItCanDownloadThePackage(bool testMockBehaviorIsInSync) { var reporter = new BufferedReporter(); 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); IToolPackageObtainer packageObtainer; if (testMockBehaviorIsInSync) { packageObtainer = new ToolPackageObtainerMock(toolsPath: toolsPath); } else { packageObtainer = new ToolPackageObtainer( new DirectoryPath(toolsPath), new DirectoryPath("no such path"), () => uniqueTempProjectPath, new Lazy <string>(), new ProjectRestorer(reporter)); } ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath = packageObtainer.ObtainAndReturnExecutablePath( packageId: TestPackageId, packageVersion: TestPackageVersion, targetframework: _testTargetframework); reporter.Lines.Should().BeEmpty(); var executable = toolConfigurationAndExecutablePath.Executable; File.Exists(executable.Value) .Should() .BeTrue(executable + " should have the executable"); File.Delete(executable.Value); }
public InstallToolCommandTests() { _fileSystemWrapper = new FileSystemMockBuilder().Build(); _toolPackageObtainerMock = new ToolPackageObtainerMock(_fileSystemWrapper, toolsPath: PathToPlacePackages); _shellShimMakerMock = new ShellShimMakerMock(PathToPlaceShim, _fileSystemWrapper); _reporter = new BufferedReporter(); _environmentPathInstructionMock = new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim); ParseResult result = Parser.Instance.Parse($"dotnet install tool -g {PackageId}"); _appliedCommand = result["dotnet"]["install"]["tool"]; var parser = Parser.Instance; _parseResult = parser.ParseFrom("dotnet install", new[] { "tool", PackageId }); }
public InstallToolCommandTests() { _fileSystemWrapper = new FileSystemMockBuilder().Build(); _toolPackageObtainerMock = new ToolPackageObtainerMock(_fileSystemWrapper); _shellShimMakerMock = new ShellShimMakerMock(PathToPlaceShim, _fileSystemWrapper); _fakeReporter = new FakeReporter(); _environmentPathInstructionMock = new EnvironmentPathInstructionMock(_fakeReporter, PathToPlaceShim); ParseResult result = Parser.Instance.Parse("dotnet install tool -g global.tool.console.demo"); _appliedCommand = result["dotnet"]["install"]["tool"]; var parser = Parser.Instance; _parseResult = parser.ParseFrom("dotnet install", new[] { "tool", "global.tool.console.demo" }); }
public void GivenCreateShimItShouldHaveNoBrokenFolderOnDisk() { _fileSystemWrapper.File.CreateEmptyFile(ExpectedCommandPath()); // Create conflict shim var toolPackageObtainerSimulatorThatThrows = new ToolPackageObtainerMock( _fileSystemWrapper, true, null, toolsPath: PathToPlacePackages); var installToolCommand = new InstallToolCommand( _appliedCommand, _parseResult, toolPackageObtainerSimulatorThatThrows, _shellShimMakerMock, _environmentPathInstructionMock, _reporter); Action a = () => installToolCommand.Execute(); a.ShouldThrow <GracefulException>(); _fileSystemWrapper.Directory.Exists(Path.Combine(PathToPlacePackages, PackageId)).Should().BeFalse(); }