コード例 #1
0
        public void TestPerformCoreTemplateQuery_UniqueNameMatchesCorrectly()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "Template1",
                Name            = "Long name of Template1",
                Identity        = "Template1",
                CacheParameters = new Dictionary <string, ICacheParameter>(),
                Tags            = new Dictionary <string, ICacheTag>()
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "Template2",
                Name            = "Long name of Template2",
                Identity        = "Template2",
                CacheParameters = new Dictionary <string, ICacheParameter>(),
                Tags            = new Dictionary <string, ICacheTag>()
            });

            INewCommandInput userInputs = new MockNewCommandInput()
            {
                TemplateName = "Template2"
            };

            TemplateListResolutionResult matchResult = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, new MockHostSpecificDataLoader(), userInputs, null);

            Assert.Equal(1, matchResult.GetBestTemplateMatchList().Count);
            Assert.Equal("Template2", matchResult.GetBestTemplateMatchList()[0].Info.Identity);
            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(1, unambiguousGroup.Count);
            Assert.Equal("Template2", unambiguousGroup[0].Info.Identity);
        }
コード例 #2
0
        public void MultipleTemplatesInGroupParamPartiaMatch_TheOneHavingSingleStartsWithIsTheSingularInvokableMatch()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template",
                Identity      = "foo.test_1",
                GroupIdentity = "foo.test.template",
                Precedence    = 100,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "MyChoice", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "value_1"
                        }) }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>(),
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template",
                Identity      = "foo.test_2",
                GroupIdentity = "foo.test.template",
                Precedence    = 200,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "MyChoice", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "value_2", "value_3"
                        }) }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>(),
            });

            INewCommandInput userInputs = new MockNewCommandInput(
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "MyChoice", "value_" }
            }
                )
            {
                TemplateName = "foo"
            };

            IHostSpecificDataLoader      hostSpecificDataLoader = new MockHostSpecificDataLoader();
            TemplateListResolutionResult matchResult            = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, hostSpecificDataLoader, userInputs, null);

            // make sure there's an unambiguous group, otherwise the singular match check is meaningless
            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(2, unambiguousGroup.Count);
            Assert.Equal(2, matchResult.GetBestTemplateMatchList().Count);

            Assert.True(matchResult.TryGetSingularInvokableMatch(out ITemplateMatchInfo singularInvokableMatch, out SingularInvokableMatchCheckStatus resultStatus));
            Assert.Equal(SingularInvokableMatchCheckStatus.SingleMatch, resultStatus);
            Assert.Equal("foo.test_1", singularInvokableMatch.Info.Identity);
        }
コード例 #3
0
        public void GivenTwoInvokableTemplatesNonDefaultLanguage_HighPrecedenceIsChosen()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template",
                Identity      = "foo.test_1.FSharp",
                GroupIdentity = "foo.test.template",
                Precedence    = 100,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "language", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "F#"
                        }) },
                },
                CacheParameters = new Dictionary <string, ICacheParameter>(),
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template",
                Identity      = "foo.test_1.VB",
                GroupIdentity = "foo.test.template",
                Precedence    = 200,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "language", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "VB"
                        }) },
                },
                CacheParameters = new Dictionary <string, ICacheParameter>(),
            });

            INewCommandInput userInputs = new MockNewCommandInput(
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
            }
                )
            {
                TemplateName = "foo"
            };


            IHostSpecificDataLoader      hostSpecificDataLoader = new MockHostSpecificDataLoader();
            TemplateListResolutionResult matchResult            = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, hostSpecificDataLoader, userInputs, null);

            // make sure there's an unambiguous group, otherwise the singular match check is meaningless
            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(2, unambiguousGroup.Count);
            Assert.Equal(2, matchResult.GetBestTemplateMatchList().Count);

            Assert.True(matchResult.TryGetSingularInvokableMatch(out ITemplateMatchInfo singularInvokableMatch, out SingularInvokableMatchCheckStatus resultStatus));
            Assert.Equal(SingularInvokableMatchCheckStatus.SingleMatch, resultStatus);
            Assert.Equal("foo.test_1.VB", singularInvokableMatch.Info.Identity);
        }
コード例 #4
0
        public void TestPerformCoreTemplateQuery_InvalidChoiceValueInvalidatesMatch()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template",
                Identity      = "foo.test.1x",
                GroupIdentity = "foo.test.template",
                Precedence    = 100,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "framework", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "netcoreapp1.0", "netcoreapp1.1"
                        }) }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>()
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template",
                Identity      = "foo.test.2x",
                GroupIdentity = "foo.test.template",
                Precedence    = 200,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "framework", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "netcoreapp2.0"
                        }) }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>()
            });

            INewCommandInput userInputs = new MockNewCommandInput(
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "framework", "netcoreapp3.0" }
            }
                )
            {
                TemplateName = "foo"
            };

            IHostSpecificDataLoader      hostSpecificDataLoader = new MockHostSpecificDataLoader();
            TemplateListResolutionResult matchResult            = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, hostSpecificDataLoader, userInputs, null);

            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(2, unambiguousGroup.Count);
            Assert.Equal(2, matchResult.GetBestTemplateMatchList().Count);

            Assert.Contains(unambiguousGroup[0].MatchDisposition, x => x.Kind == MatchKind.InvalidParameterValue);
            Assert.Contains(unambiguousGroup[1].MatchDisposition, x => x.Kind == MatchKind.InvalidParameterValue);
        }
コード例 #5
0
        private static CreationResultStatus DisplayHelpForUnambiguousTemplateGroup(TemplateListResolutionResult templateResolutionResult, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, IHostSpecificDataLoader hostDataLoader, TemplateCreator templateCreator, string defaultLanguage)
        {
            // filter on the default language if needed, the details display should be for a single language group
            if (!templateResolutionResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousTemplateGroupForDetailDisplay))
            {
                // this is really an error
                unambiguousTemplateGroupForDetailDisplay = new List <ITemplateMatchInfo>();
            }

            if (commandInput.IsListFlagSpecified)
            {
                // because the list flag is present, don't display help for the template group, even though an unambiguous group was resolved.
                if (!AreAllParamsValidForAnyTemplateInList(unambiguousTemplateGroupForDetailDisplay) &&
                    TemplateListResolver.FindHighestPrecedenceTemplateIfAllSameGroupIdentity(unambiguousTemplateGroupForDetailDisplay) != null)
                {
                    DisplayHelpForAcceptedParameters(commandInput.CommandName);
                    return(CreationResultStatus.InvalidParamValues);
                }

                // get the group without filtering on default language
                if (!templateResolutionResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousTemplateGroupForList, true))
                {
                    // this is really an error
                    unambiguousTemplateGroupForList = new List <ITemplateMatchInfo>();
                }

                if (templateResolutionResult.UsingPartialMatches)
                {
                    ShowNoTemplatesFoundMessage(commandInput.TemplateName, commandInput.Language, commandInput.TypeFilter);
                    return(CreationResultStatus.NotFound);
                }

                ShowTemplatesFoundMessage(commandInput.TemplateName, commandInput.Language, commandInput.TypeFilter);
                DisplayTemplateList(unambiguousTemplateGroupForList, environmentSettings, commandInput.Language, defaultLanguage);
                // list flag specified, so no usage examples or detailed help
                return(CreationResultStatus.Success);
            }
            else
            {
                // not in list context, but Unambiguous
                // this covers whether or not --help was input, they do the same thing in the unambiguous case
                return(TemplateDetailedHelpForSingularTemplateGroup(unambiguousTemplateGroupForDetailDisplay, environmentSettings, commandInput, hostDataLoader, templateCreator));
            }
        }
コード例 #6
0
        public void TestPerformCoreTemplateQuery_ParameterValueDisambiguates()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template old",
                Identity      = "foo.test.old",
                GroupIdentity = "foo.test.template",
                Precedence    = 100,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "framework", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "netcoreapp1.0", "netcoreapp1.1"
                        }) }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>()
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Foo template new",
                Identity      = "foo.test.new",
                GroupIdentity = "foo.test.template",
                Precedence    = 200,
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "framework", ResolutionTestHelper.CreateTestCacheTag(new List <string>()
                        {
                            "netcoreapp2.0"
                        }) }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>()
            });

            INewCommandInput userInputs = new MockNewCommandInput(
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "framework", "netcoreapp1.0" }
            }
                )
            {
                TemplateName = "foo"
            };

            TemplateListResolutionResult matchResult = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, new MockHostSpecificDataLoader(), userInputs, null);

            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(1, unambiguousGroup.Count);
            Assert.Equal("foo.test.old", unambiguousGroup[0].Info.Identity);
        }
コード例 #7
0
 public static CreationResultStatus CoordinateHelpAndUsageDisplay(TemplateListResolutionResult templateResolutionResult, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, IHostSpecificDataLoader hostDataLoader, ITelemetryLogger telemeteryLogger, TemplateCreator templateCreator, string defaultLanguage)
 {
     // this is just checking if there is an unambiguous group.
     // the called methods decide whether to get the default language filtered lists, based on what they're doing.
     if (templateResolutionResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousTemplateGroup) &&
         TemplateListResolver.AreAllTemplatesSameLanguage(unambiguousTemplateGroup))
     {
         // This will often show detailed help on the template group, which only makes sense if they're all the same language.
         return(DisplayHelpForUnambiguousTemplateGroup(templateResolutionResult, environmentSettings, commandInput, hostDataLoader, templateCreator, defaultLanguage));
     }
     else
     {
         return(DisplayHelpForAmbiguousTemplateGroup(templateResolutionResult, environmentSettings, commandInput, hostDataLoader, telemeteryLogger, defaultLanguage));
     }
 }
コード例 #8
0
        public void TestPerformCoreTemplateQuery_GroupIsFound()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "foo",
                Name            = "Foo template old",
                Identity        = "foo.test.old",
                GroupIdentity   = "foo.test.template",
                Precedence      = 100,
                CacheParameters = new Dictionary <string, ICacheParameter>(),
                Tags            = new Dictionary <string, ICacheTag>()
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "foo",
                Name            = "Foo template new",
                Identity        = "foo.test.new",
                GroupIdentity   = "foo.test.template",
                Precedence      = 200,
                CacheParameters = new Dictionary <string, ICacheParameter>(),
                Tags            = new Dictionary <string, ICacheTag>()
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "bar",
                Name            = "Bar template",
                Identity        = "bar.test",
                GroupIdentity   = "bar.test.template",
                Precedence      = 100,
                CacheParameters = new Dictionary <string, ICacheParameter>(),
                Tags            = new Dictionary <string, ICacheTag>()
            });

            INewCommandInput userInputs = new MockNewCommandInput()
            {
                TemplateName = "foo"
            };

            TemplateListResolutionResult matchResult = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, new MockHostSpecificDataLoader(), userInputs, null);

            Assert.Equal(2, matchResult.GetBestTemplateMatchList().Count);
            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(2, unambiguousGroup.Count);
            Assert.Contains(unambiguousGroup, x => string.Equals(x.Info.Identity, "foo.test.old"));
            Assert.Contains(unambiguousGroup, x => string.Equals(x.Info.Identity, "foo.test.new"));
        }
コード例 #9
0
        public void TestPerformCoreTemplateQuery_ParameterNameDisambiguates()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "foo",
                Name            = "Foo template",
                Identity        = "foo.test.old",
                GroupIdentity   = "foo.test.template",
                Tags            = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase),
                CacheParameters = new Dictionary <string, ICacheParameter>(StringComparer.OrdinalIgnoreCase)
                {
                    { "bar", new CacheParameter() },
                }
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "foo",
                Name            = "Foo template",
                Identity        = "foo.test.new",
                GroupIdentity   = "foo.test.template",
                Tags            = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase),
                CacheParameters = new Dictionary <string, ICacheParameter>(StringComparer.OrdinalIgnoreCase)
                {
                    { "baz", new CacheParameter() },
                }
            });

            INewCommandInput userInputs = new MockNewCommandInput(
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "baz", "whatever" }
            }
                )
            {
                TemplateName = "foo"
            };

            TemplateListResolutionResult matchResult = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, new MockHostSpecificDataLoader(), userInputs, null);

            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(1, unambiguousGroup.Count);
            Assert.Equal("foo.test.new", unambiguousGroup[0].Info.Identity);
        }
コード例 #10
0
 public static CreationResultStatus CoordinateHelpAndUsageDisplay(TemplateListResolutionResult templateResolutionResult, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, IHostSpecificDataLoader hostDataLoader, ITelemetryLogger telemeteryLogger, TemplateCreator templateCreator, string defaultLanguage)
 {
     // this is just checking if there is an unambiguous group.
     // the called methods decide whether to get the default language filtered lists, based on what they're doing.
     //
     // The empty TemplateName check is for when only 1 template (or group) is installed.
     // When that occurs, the group is considered partial matches. But the output should be the ambiguous case - list the templates, not help on the singular group.
     if (!string.IsNullOrEmpty(commandInput.TemplateName) &&
         templateResolutionResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousTemplateGroup) &&
         TemplateListResolver.AreAllTemplatesSameLanguage(unambiguousTemplateGroup))
     {
         // This will often show detailed help on the template group, which only makes sense if they're all the same language.
         return(DisplayHelpForUnambiguousTemplateGroup(templateResolutionResult, environmentSettings, commandInput, hostDataLoader, templateCreator, defaultLanguage));
     }
     else
     {
         return(DisplayHelpForAmbiguousTemplateGroup(templateResolutionResult, environmentSettings, commandInput, hostDataLoader, telemeteryLogger, defaultLanguage));
     }
 }
コード例 #11
0
        public void TestPerformCoreTemplateQuery_InputLanguageIsPreferredOverDefault()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Description of foo Perl template",
                Identity      = "foo.test.Perl",
                GroupIdentity = "foo.test.template",
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "language", ResolutionTestHelper.CreateTestCacheTag("Perl") }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>()
            });
            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName     = "foo",
                Name          = "Description of foo LISP template",
                Identity      = "foo.test.Lisp",
                GroupIdentity = "foo.test.template",
                Tags          = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase)
                {
                    { "language", ResolutionTestHelper.CreateTestCacheTag("LISP") }
                },
                CacheParameters = new Dictionary <string, ICacheParameter>()
            });

            INewCommandInput userInputs = new MockNewCommandInput()
            {
                TemplateName = "foo",
                Language     = "LISP"
            };

            TemplateListResolutionResult matchResult = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, new MockHostSpecificDataLoader(), userInputs, "Perl");

            Assert.Equal(1, matchResult.GetBestTemplateMatchList().Count);
            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(1, unambiguousGroup.Count);
            Assert.Equal("foo.test.Lisp", unambiguousGroup[0].Info.Identity);
        }
コード例 #12
0
        public void TestPerformCoreTemplateQuery_UnknownParameterNameInvalidatesMatch()
        {
            List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>();

            templatesToSearch.Add(new TemplateInfo()
            {
                ShortName       = "foo",
                Name            = "Foo template",
                Identity        = "foo.test",
                GroupIdentity   = "foo.test.template",
                Precedence      = 100,
                Tags            = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase),
                CacheParameters = new Dictionary <string, ICacheParameter>()
                {
                    { "bar", new CacheParameter() },
                }
            });

            INewCommandInput userInputs = new MockNewCommandInput(
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "baz", null }
            }
                )
            {
                TemplateName = "foo"
            };

            IHostSpecificDataLoader hostSpecificDataLoader = new MockHostSpecificDataLoader();

            TemplateListResolutionResult matchResult = TemplateListResolver.GetTemplateResolutionResult(templatesToSearch, hostSpecificDataLoader, userInputs, null);

            Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup));
            Assert.Equal(1, unambiguousGroup.Count);

            Assert.False(TemplateListResolver.ValidateRemainingParameters(unambiguousGroup[0], out IReadOnlyList <string> invalidParams));
            Assert.Equal(1, invalidParams.Count);
            Assert.Equal("baz", invalidParams[0]);
        }