public void TestInstall_ExistingLibman_WithPromptForProvider() { var testInputReader = HostEnvironment.InputReader as TestInputReader; testInputReader.Inputs.Add("ProviderId", "cdnjs"); string initialContent = @"{ ""version"": ""1.0"", ""libraries"": [ ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); var command = new InstallCommand(HostEnvironment); command.Configure(null); int result = command.Execute("[email protected]", "--destination", "wwwroot"); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json"))); string text = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); string expectedText = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""libraries"": [ { ""library"": ""[email protected]"", ""destination"": ""wwwroot"" } ] }"; Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text)); }
public void TestInstall_Duplicate() { var command = new InstallCommand(HostEnvironment); command.Configure(null); string initialContent = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"" } ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); int result = command.Execute("[email protected]", "--provider", "cdnjs"); var testLogger = HostEnvironment.Logger as TestLogger; Assert.AreEqual("[LIB019]: Cannot restore. Multiple definitions for libraries: jquery", testLogger.Messages.Last().Value); }
public void TestInstall_WithInvalidFiles() { var command = new InstallCommand(HostEnvironment); command.Configure(null); string initialContent = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); command.Execute("jquery", "--files", "abc.js"); string expectedMessage = @"[LIB018]: ""[email protected]"" does not contain the following: abc.js Valid files are core.js, jquery.js, jquery.min.js, jquery.min.map, jquery.slim.js, jquery.slim.min.js, jquery.slim.min.map"; var logger = HostEnvironment.Logger as TestLogger; Assert.AreEqual(expectedMessage, logger.Messages.Last().Value); string actualText = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); Assert.AreEqual(StringHelper.NormalizeNewLines(initialContent), StringHelper.NormalizeNewLines(actualText)); }
public void TestInstall_WithExistingLibmanJson() { var command = new InstallCommand(HostEnvironment); command.Configure(null); string initialContent = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ ] }"; File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent); command.Execute("[email protected]"); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json"))); string actualText = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); string expectedText = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ { ""library"": ""[email protected]"" } ] }"; Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText)); }
public void TestInstall_CleanDirectory() { var command = new InstallCommand(HostEnvironment); command.Configure(null); int result = command.Execute("[email protected]", "--provider", "cdnjs", "--destination", "wwwroot"); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json"))); string text = File.ReadAllText(Path.Combine(WorkingDir, "libman.json")); string expectedText = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""libraries"": [ { ""provider"": ""cdnjs"", ""library"": ""[email protected]"", ""destination"": ""wwwroot"" } ] }"; Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text)); }
public void TestAlreadyInstalledReturnsTrue() { _mResolver.Setup(r => r.CheckInstalled()).Returns(true); InstallCommand installCommand = new InstallCommand(_mResolver.Object, "", _mLogger.Object); Assert.True(installCommand.Execute()); }
public void TestNoExistsReturnsFalse() { _mResolver.Setup(r => r.Exists()).Returns(false); InstallCommand installCommand = new InstallCommand(_mResolver.Object, "", _mLogger.Object); Assert.False(installCommand.Execute()); }
public void TestResolveReturnsTrue() { _mResolver.Setup(r => r.Exists()).Returns(true); _mResolver.Setup(r => r.Resolve()).Returns(true); InstallCommand installCommand = new InstallCommand(_mResolver.Object, "", _mLogger.Object); Assert.True(installCommand.Execute()); }
public void CallThePerformOperationFromTheInstaller() { // Arrange var installerMock = new Mock <IInstaller <IPackage> >(); var packageMock = new Mock <IPackage>(); var installCommand = new InstallCommand(installerMock.Object, packageMock.Object); // Act installCommand.Execute(); // Assert installerMock.Verify(x => x.PerformOperation(packageMock.Object), Times.Once); }
public void CallInstallersPerformOperationMethod_WhenInvoked() { // arrange var installerMock = new Mock <IInstaller <IPackage> >(); var packageStub = new Mock <IPackage>(); installerMock.Setup(x => x.Operation); installerMock.Setup( x => x.PerformOperation(It.Is <IPackage>(y => y == packageStub.Object))); var installCommand = new InstallCommand(installerMock.Object, packageStub.Object); // act installCommand.Execute(); // assert installerMock.Verify(x => x.PerformOperation(It.Is <IPackage>(y => y == packageStub.Object)), Times.Once); }
public void MigratesTheFileSystem( [Frozen] Mock <IFileSystem> fileSystem, [Frozen] Mock <IFileSystemMigrator> fileSystemMigrator) { // Arrange var sut = new InstallCommand( null, null, false, fileSystem.Object, new Mock <IPackageAssemblyResolver>().Object, new Mock <IPackageInstaller>().Object, new Mock <ILog>().Object, fileSystemMigrator.Object); // Act sut.Execute(); // Assert fileSystemMigrator.Verify(m => m.Migrate(), Times.Once); }
public void TestUpdateCommand_AlreadyUpToDate() { var command = new UpdateCommand(HostEnvironment); command.Configure(null); string contents = @"{ ""version"": ""1.0"", ""defaultProvider"": ""cdnjs"", ""defaultDestination"": ""wwwroot"", ""libraries"": [ ] }"; string libmanjsonPath = Path.Combine(WorkingDir, "libman.json"); File.WriteAllText(libmanjsonPath, contents); var installCommand = new InstallCommand(HostEnvironment); installCommand.Configure(null); installCommand.Execute("jquery --files jquery.min.js --files jquery.js".Split(' ')); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); int result = command.Execute("jquery"); Assert.AreEqual(0, result); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js"))); Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js"))); var logger = HostEnvironment.Logger as TestLogger; Assert.AreEqual("The library \"jquery\" is already up to date", logger.Messages.Last().Value); }
public void TestNoResolverReturnsFalse() { InstallCommand installCommand = new InstallCommand("/", _mLogger.Object); Assert.False(installCommand.Execute()); }
static int Main(string[] args) { Logger logger = new Logger(); var app = new CommandLineApplication(); app.Name = "dotnet get"; app.FullName = ".NET Core Tools Global Installer"; app.Description = "Install and use command line tools built on .NET Core"; app.HelpOption("-h|--help"); app.VersionOption("-v|--version", GetAssemblyVersion()); CommandOption verboseOption = app.Option("--verbose", "Enable verbose output", CommandOptionType.NoValue); app.OnExecute(() => { app.ShowHelp(); return(0); }); app.Command("install", c => { c.Description = "Installs a .NET Core tool"; c.HelpOption("-h|--help"); CommandArgument source = c.Argument("<SOURCE>", "The tool to install. Can be a NuGet package"); c.OnExecute(() => { logger = new Logger(verboseOption.HasValue()); if (string.IsNullOrWhiteSpace(source.Value)) { logger.LogError("<SOURCE> argument is required. Use -h|--help to see help"); return(1); } InstallCommand installCommand = new InstallCommand(source.Value, logger); return(installCommand.Execute() ? 0 : 1); }); }); app.Command("update", c => { c.Description = "Updates a .NET Core tool"; c.HelpOption("-h|--help"); CommandArgument source = c.Argument("<SOURCE>", "The tool to update."); c.OnExecute(() => { logger = new Logger(verboseOption.HasValue()); if (string.IsNullOrWhiteSpace(source.Value)) { return(Update(logger) ? 0 : 1); } UpdateCommand updateCommand = new UpdateCommand(source.Value, logger); return(updateCommand.Execute() ? 0 : 1); }); }); app.Command("list", c => { c.Description = "Lists all installed .NET Core tools"; c.HelpOption("-h|--help"); c.OnExecute(() => { logger = new Logger(verboseOption.HasValue()); ListCommand listCommand = new ListCommand(logger); return(listCommand.Execute() ? 0 : 1); }); }); app.Command("uninstall", c => { c.Description = "Uninstalls a .NET Core tool"; c.HelpOption("-h|--help"); CommandArgument source = c.Argument("<SOURCE>", "The tool to uninstall."); c.OnExecute(() => { logger = new Logger(verboseOption.HasValue()); if (string.IsNullOrWhiteSpace(source.Value)) { logger.LogError("<SOURCE> argument is required. Use -h|--help to see help"); return(1); } UninstallCommand uninstallCommand = new UninstallCommand(source.Value, logger); return(uninstallCommand.Execute() ? 0 : 1); }); }); try { return(app.Execute(args)); } catch (CommandParsingException ex) { logger.LogWarning(ex.Message); app.ShowHelp(); return(1); } }