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"); }
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(); }
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."); }
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)); }
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 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(); }