Пример #1
0
        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();
        }
Пример #2
0
 public UninstallToolCommandTests()
 {
     _reporter   = new BufferedReporter();
     _fileSystem = new FileSystemMockBuilder().Build();
     _shellShimRepositoryMock        = new ShellShimRepositoryMock(new DirectoryPath(ShimsDirectory), _fileSystem);
     _environmentPathInstructionMock = new EnvironmentPathInstructionMock(_reporter, ShimsDirectory);
 }
Пример #3
0
        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();
        }
Пример #4
0
        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();
        }
Пример #5
0
        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 });
        }
Пример #6
0
        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");
        }
Пример #7
0
        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();
        }