public static Task <int> Main(string[] args) { MSBuildLocator.RegisterDefaults(); var parser = new CommandLineBuilder() .AddCommand(AddFileCommand.Create()) .AddCommand(AddUrlCommand.Create()) .AddCommand(RefreshCommand.Create()) .AddCommand(RemoveCommand.Create()) .UseDefaults() .Build(); return(parser.InvokeAsync(args)); }
internal static Parser BuildParser(HttpClient client) { var root = new RootCommand(); root.AddCommand(AddFileCommand.Create(client)); root.AddCommand(AddUrlCommand.Create(client)); root.AddCommand(RefreshCommand.Create(client)); root.AddCommand(RemoveCommand.Create(client)); root.AddCommand(ListCommand.Create(client)); var parser = new CommandLineBuilder(root) .UseDefaults() .Build(); return(parser); }
public async Task AddUrlCommand_NoOutputSpecified_Error() { // Arrange var currentDir = Directory.GetCurrentDirectory(); var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); new DirectoryInfo(Path.Combine(currentDir, "TestAssets", "EmptyProject")).CopyTo(tempDir); // Act, Assert Directory.SetCurrentDirectory(tempDir); var command = new AddUrlCommand(new TestConsole(), CreateClient()); await ExceptionAssert.ThrowsAsync <CLIToolException>(() => command.AddUrlAsync(Services.Server, Access.Internal, "ImportDir", SourceUrl, string.Empty)).DefaultTimeout(); // Cleanup Directory.SetCurrentDirectory(currentDir); Directory.Delete(tempDir, true); }
public async Task AddUrlCommand_AddsPackagesAndReferences() { // Arrange var currentDir = Directory.GetCurrentDirectory(); var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); new DirectoryInfo(Path.Combine(currentDir, "TestAssets", "EmptyProject")).CopyTo(tempDir); // Act Directory.SetCurrentDirectory(tempDir); var command = new AddUrlCommand(new TestConsole(), CreateClient()); await command.AddUrlAsync(Services.Server, Access.Internal, "ImportDir", SourceUrl, Path.Combine("Proto", "c.proto")); command.Project.ReevaluateIfNecessary(); // Assert var packageRefs = command.Project.GetItems(CommandBase.PackageReferenceElement); Assert.AreEqual(1, packageRefs.Count); Assert.NotNull(packageRefs.SingleOrDefault(r => r.UnevaluatedInclude == "Grpc.AspNetCore" && !r.HasMetadata(CommandBase.PrivateAssetsElement))); var protoRefs = command.Project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(1, protoRefs.Count); var protoRef = protoRefs.Single(); Assert.AreEqual(Path.Combine("Proto", "c.proto"), protoRef.UnevaluatedInclude); Assert.AreEqual("Server", protoRef.GetMetadataValue(CommandBase.GrpcServicesElement)); Assert.AreEqual("ImportDir", protoRef.GetMetadataValue(CommandBase.AdditionalImportDirsElement)); Assert.AreEqual("Internal", protoRef.GetMetadataValue(CommandBase.AccessElement)); Assert.AreEqual(SourceUrl, protoRef.GetMetadataValue(CommandBase.SourceUrlElement)); Assert.IsNotEmpty(File.ReadAllText(Path.Combine(command.Project.DirectoryPath, "Proto", "c.proto"))); // Cleanup Directory.SetCurrentDirectory(currentDir); Directory.Delete(tempDir, true); }
public async Task <IActionResult> EncodeUrlAsync(AddUrlCommand command) { var model = await _mediator.Send(command); return(Ok(model)); }