예제 #1
0
        public void AllTemplatesInGroupUseAllShortNamesForResolution()
        {
            IReadOnlyList <string> shortNamesForGroup = new List <string>()
            {
                "aaa", "bbb", "ccc", "ddd", "eee", "fff"
            };

            foreach (string testShortName in shortNamesForGroup)
            {
                INewCommandInput userInputs = new MockNewCommandInput()
                {
                    TemplateName = testShortName
                };

                TemplateListResolutionResult matchResult = TemplateListResolver.GetTemplateResolutionResult(MultiShortNameGroupTemplateInfo, new MockHostSpecificDataLoader(), userInputs, "C#");
                matchResult.TryGetCoreMatchedTemplatesWithDisposition(x => x.IsMatch, out IReadOnlyList <ITemplateMatchInfo> matchedTemplateList);
                Assert.Equal(3, matchedTemplateList.Count);

                foreach (ITemplateMatchInfo templateMatchInfo in matchedTemplateList)
                {
                    Assert.Equal("MultiName.Test", templateMatchInfo.Info.GroupIdentity);
                    Assert.Equal(1, templateMatchInfo.MatchDisposition.Count);
                    Assert.True(templateMatchInfo.MatchDisposition[0].Location == MatchLocation.ShortName && templateMatchInfo.MatchDisposition[0].Kind == MatchKind.Exact);
                }
            }
        }
        public static string DebugOutputForResolutionResult(TemplateListResolutionResult matchResult, Func <ITemplateMatchInfo, bool> filter)
        {
            if (!matchResult.TryGetCoreMatchedTemplatesWithDisposition(filter, out IReadOnlyList <ITemplateMatchInfo> matchingTemplates))
            {
                return("No templates matched the filter");
            }

            StringBuilder builder = new StringBuilder(512);

            foreach (ITemplateMatchInfo templateMatchInfo in matchingTemplates)
            {
                builder.AppendLine($"Identity: {templateMatchInfo.Info.Identity}");
                foreach (MatchInfo disposition in templateMatchInfo.MatchDisposition)
                {
                    builder.AppendLine($"\t{disposition.Location.ToString()} = {disposition.Kind.ToString()}");
                }

                builder.AppendLine();
            }

            return(builder.ToString());
        }