public void GivenAnInstalledShimRemoveCommitsIfTransactionIsCompleted(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = ConfigBasicTestDependecyShellShimRepository(pathToShim); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().NotBeEmpty(); using (var scope = new TransactionScope( TransactionScopeOption.Required, TimeSpan.Zero)) { shellShimRepository.RemoveShim(shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); scope.Complete(); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }
public UninstallToolCommandTests() { _reporter = new BufferedReporter(); _fileSystem = new FileSystemMockBuilder().Build(); _shellShimRepositoryMock = new ShellShimRepositoryMock(new DirectoryPath(ShimsDirectory), _fileSystem); _environmentPathInstructionMock = new EnvironmentPathInstructionMock(_reporter, ShimsDirectory); }
public void GivenAnInstalledShimRemoveDeletesTheShimFiles(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = ConfigBasicTestDependecyShellShimRepository(pathToShim); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().NotBeEmpty(); shellShimRepository.RemoveShim(shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }
public void GivenAnExceptionItWillRollback(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = ConfigBasicTestDependecyShellShimRepository(pathToShim); } Action intendedError = () => throw new ToolPackageException("simulated error"); Action a = () => { using (var scope = new TransactionScope( TransactionScopeOption.Required, TimeSpan.Zero)) { shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); intendedError(); scope.Complete(); } }; a.ShouldThrow <ToolPackageException>().WithMessage("simulated error"); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }
public InstallToolCommandTests() { _reporter = new BufferedReporter(); _fileSystem = new FileSystemMockBuilder().Build(); _toolPackageStore = new ToolPackageStoreMock(new DirectoryPath(PathToPlacePackages), _fileSystem); _shellShimRepositoryMock = new ShellShimRepositoryMock(new DirectoryPath(PathToPlaceShim), _fileSystem); _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 void GivenAShimConflictItWillRollback(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); MakeNameConflictingCommand(pathToShim, shellCommandName); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = ConfigBasicTestDependecyShellShimRepository(pathToShim); } Action a = () => { using (var scope = new TransactionScope( TransactionScopeOption.Required, TimeSpan.Zero)) { shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); scope.Complete(); } }; a.ShouldThrow <ShellShimException>().Where( ex => ex.Message == string.Format( CommonLocalizableStrings.ShellShimConflict, shellCommandName)); Directory .EnumerateFileSystemEntries(pathToShim) .Should() .HaveCount(1, "should only be the original conflicting command"); }
public void GivenANonexistentShimRemoveDoesNotThrow(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = ConfigBasicTestDependecyShellShimRepository(pathToShim); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); shellShimRepository.RemoveShim(shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }