コード例 #1
0
#pragma warning restore xUnit1004 // Test methods should not be skipped
        public async Task CacheSkipInvalidTemplatesTest()
        {
            string cacheLocation  = TestUtils.CreateTemporaryFolder();
            string v2FileLocation = SetupInvalidTemplateCache(cacheLocation);

            var environment = A.Fake <IEnvironment>();

            var engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(hostIdentifier: this.GetType().Name, virtualize: true, environment: environment);
            var templatePackageManager    = new TemplatePackageManager(engineEnvironmentSettings);

            engineEnvironmentSettings.Components.AddComponent(typeof(ITemplateSearchProviderFactory), new NuGetMetadataSearchProviderFactory());

            NewCommand        myCommand   = (NewCommand)NewCommandFactory.Create("new", _ => engineEnvironmentSettings.Host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var               parseResult = myCommand.Parse($"new search --unknown");
            SearchCommandArgs args        = new SearchCommandArgs((SearchCommand)parseResult.CommandResult.Command, parseResult);

            var templatePackages = await templatePackageManager.GetManagedTemplatePackagesAsync(false, default).ConfigureAwait(false);

            TemplateSearchCoordinator searchCoordinator = CliTemplateSearchCoordinatorFactory.CreateCliTemplateSearchCoordinator(engineEnvironmentSettings);
            CliSearchFiltersFactory   factory           = new CliSearchFiltersFactory(templatePackages);

            A.CallTo(() => environment.GetEnvironmentVariable("DOTNET_NEW_SEARCH_FILE_OVERRIDE")).Returns(v2FileLocation);
            var searchResults = await searchCoordinator.SearchAsync(
                factory.GetPackFilter(args),
                CliSearchFiltersFactory.GetMatchingTemplatesFilter(args),
                default).ConfigureAwait(false);

            Assert.Equal(1, searchResults.Count);
            Assert.Single(searchResults, result => result.Provider.Factory.DisplayName == "NuGet.org");
            var nugetSearchResults = searchResults.Single(result => result.Provider.Factory.DisplayName == "NuGet.org");

            Assert.Equal(0, nugetSearchResults.SearchHits.Count);
        }
コード例 #2
0
        public Task CanShowTemplateOptions_MultipleTemplate_MultipleParams()
        {
            var template1 = new MockTemplateInfo("foo", identity: "foo.1", groupIdentity: "foo.group", precedence: 0)
                            .WithChoiceParameter("choice", new[] { "val1", "val2" }, description: "my description", defaultValue: "def-val-not-shown", defaultIfNoOptionValue: "def-val-not-shown")
                            .WithParameter("bool", paramType: "boolean", description: "my bool", defaultValue: "false", defaultIfNoOptionValue: "false");
            var template2 = new MockTemplateInfo("foo", identity: "foo.2", groupIdentity: "foo.group", precedence: 2)
                            .WithChoiceParameter("choice", new[] { "val1", "val3" }, description: "my description", defaultValue: "def-val", defaultIfNoOptionValue: "def-val-no-arg")
                            .WithParameter("int", paramType: "integer", description: "my int", defaultValue: "0", defaultIfNoOptionValue: "10");
            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(
                CliTemplateInfo.FromTemplateInfo(new[] { template1, template2 }, A.Fake <IHostSpecificDataLoader>()))
                                          .Single();

            ITemplateEngineHost        host           = TestHost.GetVirtualHost();
            IEngineEnvironmentSettings settings       = new EngineEnvironmentSettings(host, virtualizeSettings: true);
            TemplatePackageManager     packageManager = A.Fake <TemplatePackageManager>();

            NewCommand myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            TemplateCommand templateCommand1 = new TemplateCommand(myCommand, settings, packageManager, templateGroup, templateGroup.Templates[0]);
            TemplateCommand templateCommand2 = new TemplateCommand(myCommand, settings, packageManager, templateGroup, templateGroup.Templates[1]);

            StringWriter sw          = new StringWriter();
            HelpContext  helpContext = new HelpContext(new HelpBuilder(LocalizationResources.Instance), myCommand, sw);

            InstantiateCommand.ShowTemplateSpecificOptions(new[] { templateCommand2, templateCommand1 }, helpContext);
            return(Verifier.Verify(sw.ToString(), _verifySettings.Settings));
        }
コード例 #3
0
        public void HasTypeMismatch_HasGroupLanguageMatch()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(
                new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.T1", groupIdentity: "Console.App.Test")
                .WithTag("language", "L1")
                .WithTag("type", "project")
                .WithBaselineInfo("app", "standard"));

            templatesToSearch.Add(
                new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.T2", groupIdentity: "Console.App.Test")
                .WithTag("language", "L2")
                .WithTag("type", "project")
                .WithBaselineInfo("app", "standard"));

            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(CliTemplateInfo.FromTemplateInfo(templatesToSearch, A.Fake <IHostSpecificDataLoader>())).Single();

            ITemplateEngineHost        host     = TestHost.GetVirtualHost();
            IEngineEnvironmentSettings settings = new EngineEnvironmentSettings(host, virtualizeSettings: true);

            NewCommand myCommand         = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var        parseResult       = myCommand.Parse($"new console --language L2 --type item");
            var        args              = InstantiateCommandArgs.FromNewCommandArgs(new NewCommandArgs(myCommand, parseResult));
            var        matchingTemplates = InstantiateCommand.GetMatchingTemplates(args, settings, A.Fake <TemplatePackageManager>(), templateGroup);

            Assert.Equal(0, matchingTemplates.Count());
        }
コード例 #4
0
        public void CanCompleteTypes()
        {
            var template1 = new MockTemplateInfo("foo", identity: "foo.1", groupIdentity: "foo.group")
                            .WithTag("type", "project");

            var template2 = new MockTemplateInfo("foo", identity: "foo.2", groupIdentity: "foo.group")
                            .WithTag("type", "solution");

            var templateGroups = TemplateGroup.FromTemplateList(
                CliTemplateInfo.FromTemplateInfo(new[] { template1, template2 }, A.Fake <IHostSpecificDataLoader>()));

            ITemplateEngineHost        host           = TestHost.GetVirtualHost();
            IEngineEnvironmentSettings settings       = new EngineEnvironmentSettings(host, virtualizeSettings: true);
            TemplatePackageManager     packageManager = A.Fake <TemplatePackageManager>();

            NewCommand             myCommand         = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var                    parseResult       = myCommand.Parse($" new foo --type ");
            InstantiateCommandArgs args              = InstantiateCommandArgs.FromNewCommandArgs(new NewCommandArgs(myCommand, parseResult));
            var                    completionContext = parseResult.GetCompletionContext() as TextCompletionContext;

            Assert.NotNull(completionContext);

            var result = InstantiateCommand.GetTemplateCompletions(args, templateGroups, settings, packageManager, completionContext !).Select(l => l.Label);

            Assert.Equal(new[] { "project", "solution" }, result);
        }
コード例 #5
0
        public Task FailedToResolveTemplate_WhenMultipleLanguagesAreFound()
        {
            IReadOnlyList <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>()
            {
                new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.L1", groupIdentity: "Console.App.Test").WithTag("language", "L1"),
                new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.L2", groupIdentity: "Console.App.Test").WithTag("language", "L2"),
                new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.L3", groupIdentity: "Console.App.Test").WithTag("language", "L3")
            };

            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(CliTemplateInfo.FromTemplateInfo(templatesToSearch, A.Fake <IHostSpecificDataLoader>())).Single();

            ITemplateEngineHost        host     = TestHost.GetVirtualHost();
            IEngineEnvironmentSettings settings = new EngineEnvironmentSettings(host, virtualizeSettings: true);

            NewCommand myCommand         = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var        parseResult       = myCommand.Parse($" new console");
            var        args              = InstantiateCommandArgs.FromNewCommandArgs(new NewCommandArgs(myCommand, parseResult));
            var        matchingTemplates = InstantiateCommand.GetMatchingTemplates(args, settings, A.Fake <TemplatePackageManager>(), templateGroup);

            Assert.Equal(3, matchingTemplates.Count());
            StringWriter output   = new StringWriter();
            Reporter     reporter = new Reporter(new AnsiConsole(output));

            Assert.False(InstantiateCommand.VerifyMatchingTemplates(settings, matchingTemplates, reporter, out _));
            return(Verifier.Verify(output.ToString(), _verifySettings.Settings));
        }
コード例 #6
0
        public void DefaultLanguageDisambiguates()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.L1", groupIdentity: "Console.App.Test").WithTag("language", "L1"));
            templatesToSearch.Add(new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.L2", groupIdentity: "Console.App.Test").WithTag("language", "L2"));

            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(CliTemplateInfo.FromTemplateInfo(templatesToSearch, A.Fake <IHostSpecificDataLoader>())).Single();

            var defaultParams = new Dictionary <string, string>();

            defaultParams["prefs:language"] = "L1";

            ITemplateEngineHost        host     = TestHost.GetVirtualHost(defaultParameters: defaultParams);
            IEngineEnvironmentSettings settings = new EngineEnvironmentSettings(host, virtualizeSettings: true);

            NewCommand myCommand         = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var        parseResult       = myCommand.Parse($" new console");
            var        args              = InstantiateCommandArgs.FromNewCommandArgs(new NewCommandArgs(myCommand, parseResult));
            var        matchingTemplates = InstantiateCommand.GetMatchingTemplates(args, settings, A.Fake <TemplatePackageManager>(), templateGroup);

            Assert.Equal(2, matchingTemplates.Count());
            StringWriter output   = new StringWriter();
            Reporter     reporter = new Reporter(new AnsiConsole(output));

            Assert.True(InstantiateCommand.VerifyMatchingTemplates(settings, matchingTemplates, reporter, out IEnumerable <TemplateCommand>?filtered));
            Assert.Equal(1, filtered?.Count());
            Assert.Equal("Console.App.L1", filtered?.Single().Template.Identity);
            Assert.Empty(output.ToString());
        }
コード例 #7
0
        internal void Create_CanEvaluateTemplateToRun(string command, string templateSet, string?defaultLanguage, string?expectedIdentitiesStr)
        {
            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(
                CliTemplateInfo.FromTemplateInfo(_testSets[templateSet], A.Fake <IHostSpecificDataLoader>()))
                                          .Single();

            string[] expectedIdentities = expectedIdentitiesStr?.Split("|") ?? Array.Empty <string>();

            var defaultParams = new Dictionary <string, string>();

            if (defaultLanguage != null)
            {
                defaultParams["prefs:language"] = defaultLanguage;
            }

            ITemplateEngineHost        host     = TestHost.GetVirtualHost(defaultParameters: defaultParams);
            IEngineEnvironmentSettings settings = new EngineEnvironmentSettings(host, virtualizeSettings: true);

            NewCommand myCommand          = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var        parseResult        = myCommand.Parse($"new create {command}");
            var        instantiateCommand = (InstantiateCommand)parseResult.CommandResult.Command;
            var        args             = new InstantiateCommandArgs(instantiateCommand, parseResult);
            var        templateCommands = InstantiateCommand.GetTemplateCommand(args, settings, A.Fake <TemplatePackageManager>(), templateGroup);

            Assert.Equal(expectedIdentities.Count(), templateCommands.Count);
            Assert.Equal(expectedIdentities.OrderBy(s => s), templateCommands.Select(templateCommand => templateCommand.Template.Identity).OrderBy(s => s));
        }
コード例 #8
0
        internal void Create_CanDetectParseErrorsChoiceTemplateOptions(
            string command,
            string parameterName,
            string parameterValues,
            bool isRequired,
            string?defaultValue,
            string?defaultIfNoOptionValue,
            string expectedError)
        {
            var template = new MockTemplateInfo("foo", identity: "foo.1", groupIdentity: "foo.group")
                           .WithChoiceParameter(parameterName, parameterValues.Split("|"), isRequired, defaultValue, defaultIfNoOptionValue);

            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(
                CliTemplateInfo.FromTemplateInfo(new[] { template }, A.Fake <IHostSpecificDataLoader>()))
                                          .Single();

            ITemplateEngineHost        host           = TestHost.GetVirtualHost();
            IEngineEnvironmentSettings settings       = new EngineEnvironmentSettings(host, virtualizeSettings: true);
            TemplatePackageManager     packageManager = A.Fake <TemplatePackageManager>();

            NewCommand myCommand          = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var        parseResult        = myCommand.Parse($" new create {command}");
            var        instantiateCommand = (InstantiateCommand)parseResult.CommandResult.Command;
            var        args = new InstantiateCommandArgs(instantiateCommand, parseResult);

            TemplateCommand templateCommand     = new TemplateCommand(instantiateCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single());
            Parser          parser              = ParserFactory.CreateParser(templateCommand);
            ParseResult     templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty <string>());

            Assert.True(templateParseResult.Errors.Any());
            Assert.Equal(expectedError, templateParseResult.Errors.Single().Message);
        }
コード例 #9
0
        internal void CanParseAllowScriptsOption(string command, AllowRunScripts?result)
        {
            var template = new MockTemplateInfo("foo", identity: "foo.1", groupIdentity: "foo.group")
                           .WithPostActions(ProcessStartPostActionProcessor.ActionProcessorId);

            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(
                CliTemplateInfo.FromTemplateInfo(new[] { template }, A.Fake <IHostSpecificDataLoader>()))
                                          .Single();

            ITemplateEngineHost        host           = TestHost.GetVirtualHost();
            IEngineEnvironmentSettings settings       = new EngineEnvironmentSettings(host, virtualizeSettings: true);
            TemplatePackageManager     packageManager = A.Fake <TemplatePackageManager>();

            NewCommand             myCommand   = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var                    parseResult = myCommand.Parse(command);
            InstantiateCommandArgs args        = InstantiateCommandArgs.FromNewCommandArgs(new NewCommandArgs(myCommand, parseResult));

            TemplateCommand templateCommand     = new TemplateCommand(myCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single());
            Parser          parser              = ParserFactory.CreateParser(templateCommand);
            ParseResult     templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty <string>());

            TemplateCommandArgs templateArgs = new TemplateCommandArgs(templateCommand, myCommand, templateParseResult);

            Assert.Equal(result, templateArgs.AllowScripts);
        }
コード例 #10
0
        internal void CanParseMultiChoiceTemplateOptions(string command, string parameterName, string parameterValues, string?defaultIfNoOptionValue, string?expectedValue)
        {
            var template = new MockTemplateInfo("foo", identity: "foo.1", groupIdentity: "foo.group")
                           .WithChoiceParameter(parameterName, parameterValues.Split("|"), defaultIfNoOptionValue: defaultIfNoOptionValue, allowMultipleValues: true);

            TemplateGroup templateGroup = TemplateGroup.FromTemplateList(
                CliTemplateInfo.FromTemplateInfo(new[] { template }, A.Fake <IHostSpecificDataLoader>()))
                                          .Single();

            ITemplateEngineHost        host           = TestHost.GetVirtualHost();
            IEngineEnvironmentSettings settings       = new EngineEnvironmentSettings(host, virtualizeSettings: true);
            TemplatePackageManager     packageManager = A.Fake <TemplatePackageManager>();

            NewCommand             myCommand           = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var                    parseResult         = myCommand.Parse($" new {command}");
            InstantiateCommandArgs args                = InstantiateCommandArgs.FromNewCommandArgs(new NewCommandArgs(myCommand, parseResult));
            TemplateCommand        templateCommand     = new TemplateCommand(myCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single());
            Parser                 parser              = ParserFactory.CreateParser(templateCommand);
            ParseResult            templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty <string>());
            var                    templateArgs        = new TemplateCommandArgs(templateCommand, myCommand, templateParseResult);

            if (string.IsNullOrWhiteSpace(expectedValue))
            {
                Assert.False(templateArgs.TemplateParameters.ContainsKey(parameterName));
            }
            else
            {
                Assert.True(templateArgs.TemplateParameters.ContainsKey(parameterName));
                Assert.Equal(expectedValue, templateArgs.TemplateParameters[parameterName]);
            }
        }
コード例 #11
0
ファイル: UpdateTests.cs プロジェクト: dotnet/templating
        public void Update_Legacy_CanParseInteractiveOption(string testCase)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult        = myCommand.Parse(testCase);
            UpdateCommandArgs args = new UpdateCommandArgs((BaseUpdateCommand)parseResult.CommandResult.Command, parseResult);

            Assert.True(args.Interactive);
        }
コード例 #12
0
        public Task Search_GetAllSuggestions()
        {
            ITemplateEngineHost host = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            var myCommand            = NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse("new search ");
            var result      = parseResult.GetCompletions().ToArray();

            return(Verifier.Verify(result, _verifySettings.Settings));
        }
コード例 #13
0
        public void Install_GetSuggestionsAfterOptionWithoutArg()
        {
            ITemplateEngineHost host = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            var myCommand            = NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse("new install --nuget-source ");
            var result      = parseResult.GetCompletions().ToArray();

            Assert.Empty(result);
        }
コード例 #14
0
ファイル: UpdateTests.cs プロジェクト: dotnet/templating
        public void Update_Error_WhenArguments(string commandName)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse($"new {commandName} source");

            Assert.True(parseResult.Errors.Any());
            Assert.Contains(parseResult.Errors, error => error.Message.Contains("Unrecognized command or argument 'source'"));
        }
コード例 #15
0
ファイル: SearchTests.cs プロジェクト: dotnet/templating
        public void Search_CannotParseUnknownColumns(string command)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse(command);

            Assert.NotEmpty(parseResult.Errors);
            Assert.Contains("Argument 'c1' not recognized. Must be one of:", parseResult.Errors.First().Message);
        }
コード例 #16
0
ファイル: SearchTests.cs プロジェクト: dotnet/templating
        public void Search_Legacy_CannotParseArgsAtBothLevels()
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse("new smth --search smth-else");

            Assert.NotEmpty(parseResult.Errors);
            Assert.Equal("Unrecognized command or argument(s): 'smth'.", parseResult.Errors.First().Message);
        }
コード例 #17
0
        public void List_CannotParseMultipleArgs(string command)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse(command);

            Assert.NotEmpty(parseResult.Errors);
            Assert.Equal("Unrecognized command or argument 'cr2'.", parseResult.Errors.First().Message);
        }
コード例 #18
0
ファイル: SearchTests.cs プロジェクト: dotnet/templating
        public void Search_CannotParseOptionsAtNewLevel(string command, string expectedFilter)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse(command);

            Assert.NotEmpty(parseResult.Errors);
            Assert.Equal($"Unrecognized command or argument(s): '{expectedFilter}','filter-value'.", parseResult.Errors.First().Message);
        }
コード例 #19
0
        public void CanShowUsage_ForMultipleShortNames()
        {
            ITemplateEngineHost host = TestHost.GetVirtualHost();

            NewCommand   myCommand   = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            StringWriter sw          = new StringWriter();
            HelpContext  helpContext = new HelpContext(new HelpBuilder(LocalizationResources.Instance), myCommand, sw);

            InstantiateCommand.ShowUsage(myCommand, new[] { "short-name1", "short-name2" }, helpContext);
            Assert.Equal($"Usage:{Environment.NewLine}  new short-name1 [options] [template options]{Environment.NewLine}  new short-name2 [options] [template options]{Environment.NewLine}{Environment.NewLine}", sw.ToString());
        }
コード例 #20
0
#pragma warning restore xUnit1004 // Test methods should not be skipped
        public void Install_GetSuggestionsAfterInteractive()
        {
            ITemplateEngineHost host = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            var myCommand            = NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse("new install --interactive ");
            var result      = parseResult.GetCompletions().Select(l => l.Label).ToArray();

            Assert.Equal(2, result.Length);
            Assert.Contains("--nuget-source", result);
        }
コード例 #21
0
        public void Instantiate_CanSuggestTemplate_StartsWith()
        {
            ITemplateEngineHost host = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            var myCommand            = NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse("new co");
            var suggestions = parseResult.GetCompletions().Select(l => l.Label).ToArray();

            Assert.Single(suggestions);
            Assert.Equal("console", suggestions.Single());
        }
コード例 #22
0
ファイル: SearchTests.cs プロジェクト: dotnet/templating
        public void Search_CanParseColumnsAll(string command)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse(command);

            SearchCommandArgs args = new SearchCommandArgs((BaseSearchCommand)parseResult.CommandResult.Command, parseResult);

            Assert.True(args.DisplayAllColumns);
        }
コード例 #23
0
        public void Instantiate_CanParseTemplateWithOptions()
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var parseResult             = myCommand.Parse("new console --framework net5.0");
            InstantiateCommandArgs args = InstantiateCommandArgs.FromNewCommandArgs(new NewCommandArgs(myCommand, parseResult));

            Assert.Equal("console", args.ShortName);
            Assert.Contains("--framework", args.RemainingArguments);
            Assert.Contains("net5.0", args.RemainingArguments);
        }
コード例 #24
0
        public void Uninstall_NoArguments(string commandName)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult           = myCommand.Parse($"new {commandName}");
            UninstallCommandArgs args = new UninstallCommandArgs((BaseUninstallCommand)parseResult.CommandResult.Command, parseResult);

            Assert.Empty(parseResult.Errors);
            Assert.Empty(args.TemplatePackages);
        }
コード例 #25
0
ファイル: UpdateTests.cs プロジェクト: dotnet/templating
        public void Update_CanParseAddSourceOption_MultipleEntries(string testCase)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            var parseResult        = myCommand.Parse(testCase);
            UpdateCommandArgs args = new UpdateCommandArgs((UpdateCommand)parseResult.CommandResult.Command, parseResult);

            Assert.Equal(2, args.AdditionalSources?.Count);
            Assert.Contains("my-custom-source1", args.AdditionalSources);
            Assert.Contains("my-custom-source2", args.AdditionalSources);
        }
コード例 #26
0
ファイル: InstallTests.cs プロジェクト: dotnet/templating
        public void Install_Legacy_Error_NoArguments()
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse($"new --install --interactive");

            Assert.True(parseResult.Errors.Any());
            Assert.Contains(parseResult.Errors, error => error.Message.Contains("Required argument missing"));

            Assert.Throws <ArgumentException>(() => new InstallCommandArgs((LegacyInstallCommand)parseResult.CommandResult.Command, parseResult));
        }
コード例 #27
0
        public void Instantiate_CanSuggestTemplateOption_StartsWith()
        {
            ITemplateEngineHost host = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            var myCommand            = NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult = myCommand.Parse("new console --framework net7.0 --l");
            var suggestions = parseResult.GetCompletions().Select(l => l.Label).ToArray();

            Assert.Equal(2, suggestions.Length);
            Assert.Contains("--langVersion", suggestions);
            Assert.Contains("--language", suggestions);
        }
コード例 #28
0
ファイル: InstallTests.cs プロジェクト: dotnet/templating
        public void Install_Legacy_CanParseMultipleArgs(string testCase)
        {
            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult         = myCommand.Parse(testCase);
            InstallCommandArgs args = new InstallCommandArgs((LegacyInstallCommand)parseResult.CommandResult.Command, parseResult);

            Assert.Equal(2, args.TemplatePackages.Count);
            Assert.Contains("source1", args.TemplatePackages);
            Assert.Contains("source2", args.TemplatePackages);
        }
コード例 #29
0
        private static int Main(string[] args)
        {
            VerificationLookup["dir_exists"]            = CheckDirectoryExists;
            VerificationLookup["file_exists"]           = CheckFileExists;
            VerificationLookup["dir_does_not_exist"]    = CheckDirectoryDoesNotExist;
            VerificationLookup["file_does_not_exist"]   = CheckFileDoesNotExist;
            VerificationLookup["file_contains"]         = CheckFileContains;
            VerificationLookup["file_does_not_contain"] = CheckFileDoesNotContain;

            int    batteryCount = int.Parse(args[0], CultureInfo.InvariantCulture);
            string outputPath   = args[batteryCount + 1];

            List <string> passThroughArgs = new List <string>();

            passThroughArgs.AddRange(args.Skip(2 + batteryCount));
            passThroughArgs.Add("--debug:ephemeral-hive");

            ITemplateEngineHost host = CreateHost();

            host.VirtualizeDirectory(outputPath);

            var command = NewCommandFactory.Create(CommandName, _ => host, _ => new TelemetryLogger(null), new NewCommandCallbacks());

            int result = ParserFactory.CreateParser(command).Parse(passThroughArgs.ToArray()).Invoke();

            bool verificationsPassed = false;

            for (int i = 0; i < batteryCount; ++i)
            {
                string verificationsFile         = args[i + 1];
                string verificationsFileContents = File.ReadAllText(verificationsFile);
                JArray verifications             = JArray.Parse(verificationsFileContents);

                try
                {
                    verificationsPassed = RunVerifications(verifications, host.FileSystem, outputPath);
                }
                catch (Exception ex)
                {
                    verificationsPassed = false;
                    Console.Error.WriteLine(ex.ToString());
                }
            }

            Console.Error.WriteLine(" ");
            Console.Error.WriteLine("Output Files:");
            foreach (string fileName in host.FileSystem.EnumerateFiles(outputPath, "*", SearchOption.AllDirectories))
            {
                Console.Error.WriteLine(fileName.Substring(outputPath.Length));
            }

            return(result != 0 ? result : batteryCount == 0 ? 0 : verificationsPassed ? 0 : 1);
        }
コード例 #30
0
ファイル: UpdateTests.cs プロジェクト: dotnet/templating
        public void CommandExampleCanShowParentCommandsBeyondNew()
        {
            ITemplateEngineHost host        = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand   = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());
            Command             rootCommand = new Command("dotnet")
            {
                myCommand
            };

            var parseResult = rootCommand.Parse("dotnet new update");

            Assert.Equal("dotnet new update", Example.For <NewCommand>(parseResult).WithSubcommand <UpdateCommand>());
        }