コード例 #1
0
ファイル: ShellShimMakerTests.cs プロジェクト: yanchenw/cli
        public void GivenAnExecutablePathWithExistingSameNameShimItRollsBack(bool testMockBehaviorIsInSync)
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            var pathToShim = GetNewCleanFolderUnderTempRoot();

            MakeNameConflictingCommand(pathToShim, shellCommandName);

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(pathToShim);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(pathToShim);
            }

            Action a = () =>
            {
                using (var t = new TransactionScope())
                {
                    shellShimMaker.CreateShim(new FilePath("dummy.dll"), shellCommandName);

                    t.Complete();
                }
            };

            a.ShouldThrow <GracefulException>();

            Directory.GetFiles(pathToShim).Should().HaveCount(1, "there is only intent conflicted command");
        }
コード例 #2
0
ファイル: ShellShimMakerTests.cs プロジェクト: yanchenw/cli
        public void GivenAnExecutablePathErrorHappensItRollsBack(bool testMockBehaviorIsInSync)
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            var pathToShim = GetNewCleanFolderUnderTempRoot();

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(pathToShim);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(pathToShim);
            }

            Action intendedError = () => throw new PackageObtainException();

            Action a = () =>
            {
                using (var t = new TransactionScope())
                {
                    shellShimMaker.CreateShim(new FilePath("dummy.dll"), shellCommandName);

                    intendedError();
                    t.Complete();
                }
            };

            a.ShouldThrow <PackageObtainException>();

            Directory.GetFiles(pathToShim).Should().BeEmpty();
        }
コード例 #3
0
ファイル: ShellShimMakerTests.cs プロジェクト: yanchenw/cli
        public void GivenAnExecutablePathWithExistingSameNameShimItThrows(bool testMockBehaviorIsInSync)
        {
            var shellCommandName         = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
            var cleanFolderUnderTempRoot = GetNewCleanFolderUnderTempRoot();

            MakeNameConflictingCommand(cleanFolderUnderTempRoot, shellCommandName);

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(cleanFolderUnderTempRoot);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(cleanFolderUnderTempRoot);
            }

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldThrow <GracefulException>()
            .And.Message
            .Should().Contain(
                $"Failed to install tool {shellCommandName}. A command with the same name already exists.");
        }
コード例 #4
0
        public void GivenAnExecutablePathWithExistingSameNameShimItThrows(bool testMockBehaviorIsInSync)
        {
            var shellCommandName         = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
            var cleanFolderUnderTempRoot = GetNewCleanFolderUnderTempRoot();

            MakeNameConflictingCommand(cleanFolderUnderTempRoot, shellCommandName);

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(cleanFolderUnderTempRoot);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(cleanFolderUnderTempRoot);
            }

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldThrow <GracefulException>()
            .And.Message
            .Should().Contain(
                string.Format(CommonLocalizableStrings.FailInstallToolSameName, shellCommandName));
        }
コード例 #5
0
        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 });
        }
コード例 #6
0
        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" });
        }
コード例 #7
0
ファイル: ShellShimMakerTests.cs プロジェクト: matthid/cli
        public void GivenAnExecutablePathWithoutExistingSameNameShimItShouldNotThrow(bool testMockBehaviorIsInSync)
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(TempRoot.Root);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(TempRoot.Root);
            }

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldNotThrow();
        }