private ToolUninstallCommand CreateUninstallCommand(string options, Action uninstallCallback = null) { ParseResult result = Parser.Instance.Parse("dotnet tool uninstall " + options); (IToolPackageStore, IToolPackageStoreQuery, IToolPackageUninstaller) createToolPackageStoreAndUninstaller( DirectoryPath?directoryPath) { var store = new ToolPackageStoreMock( new DirectoryPath(_toolsDirectory), _fileSystem); var packageUninstaller = new ToolPackageUninstallerMock(_fileSystem, store, uninstallCallback); return(store, store, packageUninstaller); } return(new ToolUninstallCommand( result["dotnet"]["tool"]["uninstall"], result, createToolPackageStoreAndUninstaller, (_) => new ShellShimRepository( new DirectoryPath(_shimsDirectory), fileSystem: _fileSystem, appHostShellShimMaker: new AppHostShellShimMakerMock(_fileSystem)), _reporter)); }
) Setup( bool useMock, List <MockFeed> feeds = null, FilePath?tempProject = null, DirectoryPath?offlineFeed = null, FilePath?writeLocalFeedToNugetConfig = null, [CallerMemberName] string callingMethod = "", string identiifer = null) { var root = new DirectoryPath(_testAssetsManager.CreateTestDirectory(callingMethod, identifier: useMock.ToString() + identiifer).Path); var reporter = new BufferedReporter(); IFileSystem fileSystem; IToolPackageStore store; IToolPackageStoreQuery storeQuery; IToolPackageInstaller installer; IToolPackageUninstaller uninstaller; if (useMock) { fileSystem = new FileSystemMockBuilder().Build(); var frameworksMap = new Dictionary <PackageId, IEnumerable <NuGetFramework> >() { { TestPackageId, TestFrameworks } }; WriteNugetConfigFileToPointToTheFeed(fileSystem, writeLocalFeedToNugetConfig); var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem, frameworksMap); store = toolPackageStoreMock; storeQuery = toolPackageStoreMock; installer = new ToolPackageInstallerMock( fileSystem: fileSystem, store: toolPackageStoreMock, projectRestorer: new ProjectRestorerMock( fileSystem: fileSystem, reporter: reporter, feeds: feeds == null ? GetMockFeedsForConfigFile(writeLocalFeedToNugetConfig) : feeds.Concat(GetMockFeedsForConfigFile(writeLocalFeedToNugetConfig)).ToList()), frameworksMap: frameworksMap); uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock); } else { fileSystem = new FileSystemWrapper(); WriteNugetConfigFileToPointToTheFeed(fileSystem, writeLocalFeedToNugetConfig); var toolPackageStore = new ToolPackageStoreAndQuery(root); store = toolPackageStore; storeQuery = toolPackageStore; installer = new ToolPackageInstaller( store: store, projectRestorer: new Stage2ProjectRestorer(Log, reporter), tempProject: tempProject ?? GetUniqueTempProjectPathEachTest(), offlineFeed: offlineFeed ?? new DirectoryPath("does not exist")); uninstaller = new ToolPackageUninstaller(store); } store.Root.Value.Should().Be(Path.GetFullPath(root.Value)); return(store, storeQuery, installer, uninstaller, reporter, fileSystem); }
) Setup( bool useMock, List <MockFeed> feeds = null, FilePath?tempProject = null, DirectoryPath?offlineFeed = null, [CallerMemberName] string testName = "", string identifier = null) { var root = new DirectoryPath(_testAssetsManager.CreateTestDirectory(testName, identifier).Path); var reporter = new BufferedReporter(); IFileSystem fileSystem; IToolPackageStore store; IToolPackageStoreQuery storeQuery; IToolPackageInstaller installer; IToolPackageUninstaller uninstaller; if (useMock) { var packagedShimsMap = new Dictionary <PackageId, IReadOnlyList <FilePath> > { [TestPackageId] = new FilePath[] { new FilePath("path/demo.exe") } }; fileSystem = new FileSystemMockBuilder().Build(); var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem); store = toolPackageStoreMock; storeQuery = toolPackageStoreMock; installer = new ToolPackageInstallerMock( fileSystem: fileSystem, store: toolPackageStoreMock, projectRestorer: new ProjectRestorerMock( fileSystem: fileSystem, reporter: reporter, feeds: feeds), packagedShimsMap: packagedShimsMap); uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock); } else { fileSystem = new FileSystemWrapper(); var toolPackageStore = new ToolPackageStoreAndQuery(root); store = toolPackageStore; storeQuery = toolPackageStore; installer = new ToolPackageInstaller( store: store, projectRestorer: new Stage2ProjectRestorer(Log, reporter), tempProject: tempProject ?? GetUniqueTempProjectPathEachTest(), offlineFeed: offlineFeed ?? new DirectoryPath("does not exist")); uninstaller = new ToolPackageUninstaller(store); } store.Root.Value.Should().Be(Path.GetFullPath(root.Value)); return(store, storeQuery, installer, uninstaller, reporter, fileSystem); }
) Setup( bool useMock, IEnumerable <MockFeed> feeds = null, FilePath?tempProject = null, DirectoryPath?offlineFeed = null) { var root = new DirectoryPath(Path.Combine(TempRoot.Root, Path.GetRandomFileName())); var reporter = new BufferedReporter(); IFileSystem fileSystem; IToolPackageStore store; IToolPackageStoreQuery storeQuery; IToolPackageInstaller installer; IToolPackageUninstaller uninstaller; if (useMock) { var packagedShimsMap = new Dictionary <PackageId, IReadOnlyList <FilePath> > { [TestPackageId] = new FilePath[] { new FilePath("path/demo.exe") } }; fileSystem = new FileSystemMockBuilder().Build(); var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem); store = toolPackageStoreMock; storeQuery = toolPackageStoreMock; installer = new ToolPackageInstallerMock( fileSystem: fileSystem, store: toolPackageStoreMock, projectRestorer: new ProjectRestorerMock( fileSystem: fileSystem, reporter: reporter, feeds: feeds), packagedShimsMap: packagedShimsMap); uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock); } else { fileSystem = new FileSystemWrapper(); var toolPackageStore = new ToolPackageStoreAndQuery(root); store = toolPackageStore; storeQuery = toolPackageStore; installer = new ToolPackageInstaller( store: store, projectRestorer: new ProjectRestorer(reporter), tempProject: tempProject ?? GetUniqueTempProjectPathEachTest(), offlineFeed: offlineFeed ?? new DirectoryPath("does not exist")); uninstaller = new ToolPackageUninstaller(store); } store.Root.Value.Should().Be(Path.GetFullPath(root.Value)); return(store, storeQuery, installer, uninstaller, reporter, fileSystem); }
) Setup( bool useMock, List <MockFeed> feeds = null, FilePath?tempProject = null, DirectoryPath?offlineFeed = null, FilePath?writeLocalFeedToNugetConfig = null) { var root = new DirectoryPath(Path.Combine(TempRoot.Root, Path.GetRandomFileName())); var reporter = new BufferedReporter(); IFileSystem fileSystem; IToolPackageStore store; IToolPackageStoreQuery storeQuery; IToolPackageInstaller installer; IToolPackageUninstaller uninstaller; if (useMock) { fileSystem = new FileSystemMockBuilder().Build(); WriteNugetConfigFileToPointToTheFeed(fileSystem, writeLocalFeedToNugetConfig); var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem); store = toolPackageStoreMock; storeQuery = toolPackageStoreMock; installer = new ToolPackageInstallerMock( fileSystem: fileSystem, store: toolPackageStoreMock, projectRestorer: new ProjectRestorerMock( fileSystem: fileSystem, reporter: reporter, feeds: feeds == null ? GetMockFeedsForConfigFile(writeLocalFeedToNugetConfig) : feeds.Concat(GetMockFeedsForConfigFile(writeLocalFeedToNugetConfig)).ToList())); uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock); } else { fileSystem = new FileSystemWrapper(); WriteNugetConfigFileToPointToTheFeed(fileSystem, writeLocalFeedToNugetConfig); var toolPackageStore = new ToolPackageStoreAndQuery(root); store = toolPackageStore; storeQuery = toolPackageStore; installer = new ToolPackageInstaller( store: store, projectRestorer: new ProjectRestorer(reporter), tempProject: tempProject ?? GetUniqueTempProjectPathEachTest(), offlineFeed: offlineFeed ?? new DirectoryPath("does not exist")); uninstaller = new ToolPackageUninstaller(store); } store.Root.Value.Should().Be(Path.GetFullPath(root.Value)); return(store, storeQuery, installer, uninstaller, reporter, fileSystem); }
public void GivenOfflineFeedInstallWhenCallWithprereleaseItSucceeds(bool testMockBehaviorIsInSync) { IToolPackageInstaller installer = null; IToolPackageUninstaller uninstaller = null; if (testMockBehaviorIsInSync == false) { var testFeedWithOnlyPreviewPackages = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(testFeedWithOnlyPreviewPackages); var tempFeed = GetTestLocalFeedPath(); File.Copy(Path.Combine(GetTestLocalFeedPath(), "global.tool.console.demo.1.0.4.nupkg"), Path.Combine(testFeedWithOnlyPreviewPackages, "global.tool.console.demo.1.0.4.nupkg")); File.Copy(Path.Combine(GetTestLocalFeedPath(), "global.tool.console.demo.2.0.1-preview1.nupkg"), Path.Combine(testFeedWithOnlyPreviewPackages, "global.tool.console.demo.2.0.1-preview1.nupkg")); var(store, storeQuery, realInstaller, realUninstaller, reporter, fileSystem) = Setup( useMock: testMockBehaviorIsInSync, offlineFeed: new DirectoryPath(testFeedWithOnlyPreviewPackages), feeds: GetOfflineMockFeed()); installer = realInstaller; uninstaller = realUninstaller; } else { var fileSystem = new FileSystemMockBuilder().Build(); var root = new DirectoryPath(_testAssetsManager .CreateTestDirectory(nameof(GivenOfflineFeedInstallWhenCallWithprereleaseItSucceeds) + testMockBehaviorIsInSync).Path); var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem); var store = toolPackageStoreMock; var storeQuery = toolPackageStoreMock; installer = new ToolPackageInstallerMock( fileSystem: fileSystem, store: toolPackageStoreMock, projectRestorer: new ProjectRestorerMock( fileSystem: fileSystem, reporter: new BufferedReporter(), feeds: new List <MockFeed> { new MockFeed { Type = MockFeedType.ImplicitAdditionalFeed, Packages = new List <MockFeedPackage> { new MockFeedPackage { PackageId = TestPackageId.ToString(), Version = "1.0.4", ToolCommandName = "SimulatorCommand" }, new MockFeedPackage { PackageId = TestPackageId.ToString(), Version = "2.0.1-preview1", ToolCommandName = "SimulatorCommand" } } } })); uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock); } var package = installer.InstallPackage(new PackageLocation(), packageId: TestPackageId, versionRange: VersionRange.Parse("*-*"), targetFramework: _testTargetframework); package.Version.ToNormalizedString().Should().Be("2.0.1-preview1"); uninstaller.Uninstall(package.PackageDirectory); var package2 = installer.InstallPackage(new PackageLocation(), packageId: TestPackageId, versionRange: VersionRange.Parse("2.0*-*"), targetFramework: _testTargetframework); package2.Version.ToNormalizedString().Should().Be("2.0.1-preview1"); uninstaller.Uninstall(package.PackageDirectory); }
public void GivenAPackageWhenCallFromUninstallRedirectCommandItUninstalls() { CreateInstallCommand($"-g {PackageId}").Execute().Should().Be(0); _reporter .Lines .Last() .Should() .Contain(string.Format( InstallLocalizableStrings.InstallationSucceeded, ProjectRestorerMock.DefaultToolCommandName, PackageId, PackageVersion)); var packageDirectory = new DirectoryPath(Path.GetFullPath(_toolsDirectory)) .WithSubDirectories(PackageId, PackageVersion); var shimPath = Path.Combine( _shimsDirectory, ProjectRestorerMock.DefaultToolCommandName + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")); _fileSystem.Directory.Exists(packageDirectory.Value).Should().BeTrue(); _fileSystem.File.Exists(shimPath).Should().BeTrue(); _reporter.Lines.Clear(); ParseResult result = Parser.Instance.Parse("dotnet tool uninstall " + $"-g {PackageId}"); (IToolPackageStore, IToolPackageStoreQuery, IToolPackageUninstaller) CreateToolPackageStoreAndUninstaller( DirectoryPath?directoryPath) { var store = new ToolPackageStoreMock( new DirectoryPath(_toolsDirectory), _fileSystem); var packageUninstaller = new ToolPackageUninstallerMock(_fileSystem, store); return(store, store, packageUninstaller); } var toolUninstallGlobalOrToolPathCommand = new ToolUninstallGlobalOrToolPathCommand( result, CreateToolPackageStoreAndUninstaller, (_) => new ShellShimRepository( new DirectoryPath(_shimsDirectory), fileSystem: _fileSystem, appHostShellShimMaker: new AppHostShellShimMakerMock(_fileSystem)), _reporter); var uninstallCommand = new ToolUninstallCommand( result, toolUninstallGlobalOrToolPathCommand: toolUninstallGlobalOrToolPathCommand); uninstallCommand.Execute().Should().Be(0); _reporter .Lines .Single() .Should() .Contain(string.Format( LocalizableStrings.UninstallSucceeded, PackageId, PackageVersion)); _fileSystem.Directory.Exists(packageDirectory.Value).Should().BeFalse(); _fileSystem.File.Exists(shimPath).Should().BeFalse(); }