public void MultipleTemplatesInGroupHavingSingularStartMatchesOnDifferentParams_HighPrecedenceIsChosen() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add(new MockTemplateInfo("foo", name: "Foo template", identity: "foo.test_1", groupIdentity: "foo.test.template", precedence: 100) .WithTag("MyChoice", "value_1", "other_value") .WithTag("OtherChoice", "foo_")); templatesToSearch.Add(new MockTemplateInfo("foo", name: "Foo template", identity: "foo.test_2", groupIdentity: "foo.test.template", precedence: 200) .WithTag("MyChoice", "value_") .WithTag("OtherChoice", "foo_", "bar_1")); INewCommandInput userInputs = new MockNewCommandInput("foo").WithTemplateOption("MyChoice", "value_").WithTemplateOption("OtherChoice", "foo_"); IHostSpecificDataLoader hostSpecificDataLoader = new MockHostSpecificDataLoader(); TemplateResolutionResult matchResult = TemplateResolver.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 Status resultStatus)); Assert.Equal(Status.SingleMatch, resultStatus); Assert.Equal("foo.test_2", singularInvokableMatch.Info.Identity); }
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); }
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); }
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", 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", 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.PerformCoreTemplateQuery(templatesToSearch, hostSpecificDataLoader, userInputs, null); Assert.Equal(2, matchResult.MatchedTemplatesWithSecondaryMatchInfo.Count); Assert.Equal(2, matchResult.UnambiguousTemplateGroupToUse.Count); Assert.Equal(2, matchResult.CoreMatchedTemplates.Count); Assert.True(matchResult.UnambiguousTemplateGroupToUse[0].MatchDisposition.Any(x => x.Kind == MatchKind.InvalidParameterValue)); Assert.True(matchResult.UnambiguousTemplateGroupToUse[1].MatchDisposition.Any(x => x.Kind == MatchKind.InvalidParameterValue)); }
public void NupkgReinstallDoesntRemoveTemplates() { const string nupkgToInstallName = "TestNupkgInstallTemplate.0.0.1.nupkg"; const string checkTemplateName = "nupkginstall"; // this is the short name of the template in the nupkg that gets installed. ITemplateEngineHost host = CreateHostWithVirtualizedHive(HostIdentifier, HostVersion); Assert.NotNull(host); ITelemetryLogger telemetryLogger = new TelemetryLogger(null, false); int initializeResult = New3Command.Run(CommandName, host, telemetryLogger, null, new string[] { }); Assert.Equal(0, initializeResult); string codebase = typeof(NupkgInstallTests).GetTypeInfo().Assembly.CodeBase; Uri cb = new Uri(codebase); string asmPath = cb.LocalPath; string dir = Path.GetDirectoryName(asmPath); string pathToInstall = Path.Combine(dir, "TemplateInstallTests", "TestTemplates", nupkgToInstallName); Assert.True(File.Exists(pathToInstall), $"directory didnt exist: {pathToInstall}"); string[] installArgs = new[] { "--install", pathToInstall }; // install the test pack int firstInstallResult = New3Command.Run(CommandName, host, telemetryLogger, null, installArgs); Assert.Equal(0, firstInstallResult); EngineEnvironmentSettings environemnt = new EngineEnvironmentSettings(host, x => new SettingsLoader(x)); SettingsLoader settingsLoader = (SettingsLoader)environemnt.SettingsLoader; IHostSpecificDataLoader hostDataLoader = new MockHostSpecificDataLoader(); // check that the template was installed from the first install. IReadOnlyCollection <ITemplateMatchInfo> allTemplates = TemplateListResolver.PerformAllTemplatesQuery(settingsLoader.UserTemplateCache.TemplateInfo, hostDataLoader); Assert.Contains(checkTemplateName, allTemplates.Select(t => t.Info.ShortName)); // install the same test pack again int secondInstallResult = New3Command.Run(CommandName, host, telemetryLogger, null, installArgs); Assert.Equal(0, secondInstallResult); settingsLoader.Reload(); // check that the template is still installed after the second install. IReadOnlyCollection <ITemplateMatchInfo> allTemplatesAfterSecondInstall = TemplateListResolver.PerformAllTemplatesQuery(settingsLoader.UserTemplateCache.TemplateInfo, hostDataLoader); Assert.Contains(checkTemplateName, allTemplatesAfterSecondInstall.Select(t => t.Info.ShortName)); }
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.PerformCoreTemplateQuery(templatesToSearch, hostSpecificDataLoader, userInputs, null); Assert.Equal(null, matchResult.MatchedTemplatesWithSecondaryMatchInfo); Assert.Equal(1, matchResult.UnambiguousTemplateGroupToUse.Count); // TODO: // These 2 lines are the analogues of what happens in New3Command.EnterSingularTemplateManipulationFlowAsync() // as a final verification for the template. // This is really a shortcoming of the resolver, this check should get factored into it. // But we'll need to add a new match category so we know that the unambiguous template "matched", except the extra user parameters. HostSpecificTemplateData hostTemplateData = hostSpecificDataLoader.ReadHostSpecificTemplateData(matchResult.UnambiguousTemplateGroupToUse[0].Info); userInputs.ReparseForTemplate(matchResult.UnambiguousTemplateGroupToUse[0].Info, hostTemplateData); Assert.False(TemplateListResolver.ValidateRemainingParameters(userInputs, out IReadOnlyList <string> invalidParams)); Assert.Equal(1, invalidParams.Count); Assert.Equal("baz", invalidParams[0]); }
public void TestPerformCoreTemplateQuery_UnknownParameterNameInvalidatesMatch() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add(new MockTemplateInfo("foo", name: "Foo template", identity: "foo.test", groupIdentity: "foo.test.template", precedence: 100).WithParameters("bar")); INewCommandInput userInputs = new MockNewCommandInput("foo").WithTemplateOption("baz"); IHostSpecificDataLoader hostSpecificDataLoader = new MockHostSpecificDataLoader(); TemplateResolutionResult matchResult = TemplateResolver.GetTemplateResolutionResult(templatesToSearch, hostSpecificDataLoader, userInputs, null); Assert.True(matchResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousGroup)); Assert.Equal(1, unambiguousGroup.Count); Assert.False(TemplateResolver.ValidateRemainingParameters(unambiguousGroup[0], out IReadOnlyList <string> invalidParams)); Assert.Equal(1, invalidParams.Count); Assert.Equal("baz", invalidParams[0]); }
public void TestPerformCoreTemplateQuery_InvalidChoiceValueInvalidatesMatch() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add(new MockTemplateInfo("foo", name: "Foo template", identity: "foo.test.1x", groupIdentity: "foo.test.template", precedence: 100).WithTag("framework", "netcoreapp1.0", "netcoreapp1.1")); templatesToSearch.Add(new MockTemplateInfo("foo", name: "Foo template", identity: "foo.test.2x", groupIdentity: "foo.test.template", precedence: 200).WithTag("framework", "netcoreapp2.0")); INewCommandInput userInputs = new MockNewCommandInput("foo").WithTemplateOption("framework", "netcoreapp3.0"); IHostSpecificDataLoader hostSpecificDataLoader = new MockHostSpecificDataLoader(); TemplateResolutionResult matchResult = TemplateResolver.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); }
public void TestPerformAllTemplatesInContextQuery() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add(new MockTemplateInfo("Template1", name: "Template1", identity: "Template1") .WithTag("type", "project")); templatesToSearch.Add(new MockTemplateInfo("Template2", name: "Template2", identity: "Template2") .WithTag("type", "item")); templatesToSearch.Add(new MockTemplateInfo("Template3", name: "Template3", identity: "Template3") .WithTag("type", "myType")); templatesToSearch.Add(new MockTemplateInfo("Template4", name: "Template4", identity: "Template4") .WithTag("type", "project")); templatesToSearch.Add(new MockTemplateInfo("Template5", name: "Template5", identity: "Template5") .WithTag("type", "project")); IHostSpecificDataLoader hostDataLoader = new MockHostSpecificDataLoader(); IReadOnlyCollection <ITemplateMatchInfo> projectTemplates = TemplateResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "project"); Assert.Equal(3, projectTemplates.Count); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template1", StringComparison.Ordinal)).Any()); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template4", StringComparison.Ordinal)).Any()); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template5", StringComparison.Ordinal)).Any()); IReadOnlyCollection <ITemplateMatchInfo> itemTemplates = TemplateResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "item"); Assert.Equal(1, itemTemplates.Count); Assert.True(itemTemplates.Where(x => string.Equals(x.Info.Identity, "Template2", StringComparison.Ordinal)).Any()); //Visual Studio only supports "project" and "item", so using other types is no longer allowed, therefore "other" handling is removed. //support of match on custom type still remains IReadOnlyCollection <ITemplateMatchInfo> otherTemplates = TemplateResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "other"); Assert.Equal(0, otherTemplates.Count); Assert.False(otherTemplates.Where(x => string.Equals(x.Info.Identity, "Template3", StringComparison.Ordinal)).Any()); IReadOnlyCollection <ITemplateMatchInfo> customTypeTemplates = TemplateResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "myType"); Assert.Equal(1, customTypeTemplates.Count); Assert.True(customTypeTemplates.Where(x => string.Equals(x.Info.Identity, "Template3", StringComparison.Ordinal)).Any()); }
public void GivenOneInvokableTemplateWithNonDefaultLanguage_ItIsChosen() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add(new MockTemplateInfo("foo", name: "Foo template", identity: "foo.test_1", groupIdentity: "foo.test.template", precedence: 100) .WithTag("language", "F#")); INewCommandInput userInputs = new MockNewCommandInput("foo"); IHostSpecificDataLoader hostSpecificDataLoader = new MockHostSpecificDataLoader(); TemplateResolutionResult matchResult = TemplateResolver.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(1, unambiguousGroup.Count); Assert.Equal(1, matchResult.GetBestTemplateMatchList().Count); Assert.True(matchResult.TryGetSingularInvokableMatch(out ITemplateMatchInfo singularInvokableMatch, out Status resultStatus)); Assert.Equal(Status.SingleMatch, resultStatus); Assert.Equal("foo.test_1", singularInvokableMatch.Info.Identity); }
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]); }
public void TestPerformAllTemplatesInContextQuery() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add(new TemplateInfo() { Name = "Template1", Identity = "Template1", CacheParameters = new Dictionary <string, ICacheParameter>(), Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("project") } }, }); templatesToSearch.Add(new TemplateInfo() { Name = "Template2", Identity = "Template2", CacheParameters = new Dictionary <string, ICacheParameter>(), Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("item") } } }); templatesToSearch.Add(new TemplateInfo() { Name = "Template3", Identity = "Template3", CacheParameters = new Dictionary <string, ICacheParameter>(), Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("myType") } } }); templatesToSearch.Add(new TemplateInfo() { Name = "Template4", Identity = "Template4", CacheParameters = new Dictionary <string, ICacheParameter>(), Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("project") } } }); templatesToSearch.Add(new TemplateInfo() { Name = "Template5", Identity = "Template5", CacheParameters = new Dictionary <string, ICacheParameter>(), Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("project") } } }); IHostSpecificDataLoader hostDataLoader = new MockHostSpecificDataLoader(); IReadOnlyCollection <ITemplateMatchInfo> projectTemplates = TemplateListResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "project"); Assert.Equal(3, projectTemplates.Count); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template1", StringComparison.Ordinal)).Any()); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template4", StringComparison.Ordinal)).Any()); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template5", StringComparison.Ordinal)).Any()); IReadOnlyCollection <ITemplateMatchInfo> itemTemplates = TemplateListResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "item"); Assert.Equal(1, itemTemplates.Count); Assert.True(itemTemplates.Where(x => string.Equals(x.Info.Identity, "Template2", StringComparison.Ordinal)).Any()); //Visual Studio only supports "project" and "item", so using other types is no longer allowed, therefore "other" handling is removed. //support of match on custom type still remains IReadOnlyCollection <ITemplateMatchInfo> otherTemplates = TemplateListResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "other"); Assert.Equal(0, otherTemplates.Count); Assert.False(otherTemplates.Where(x => string.Equals(x.Info.Identity, "Template3", StringComparison.Ordinal)).Any()); IReadOnlyCollection <ITemplateMatchInfo> customTypeTemplates = TemplateListResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "myType"); Assert.Equal(1, customTypeTemplates.Count); Assert.True(customTypeTemplates.Where(x => string.Equals(x.Info.Identity, "Template3", StringComparison.Ordinal)).Any()); }
public void TestPerformAllTemplatesInContextQuery() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add(new TemplateInfo() { Name = "Template1", Identity = "Template1", Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("project") } } }); templatesToSearch.Add(new TemplateInfo() { Name = "Template2", Identity = "Template2", Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("item") } } }); templatesToSearch.Add(new TemplateInfo() { Name = "Template3", Identity = "Template3", Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("myType") } } }); templatesToSearch.Add(new TemplateInfo() { Name = "Template4", Identity = "Template4", Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("project") } } }); templatesToSearch.Add(new TemplateInfo() { Name = "Template5", Identity = "Template5", Tags = new Dictionary <string, ICacheTag>(StringComparer.OrdinalIgnoreCase) { { "type", ResolutionTestHelper.CreateTestCacheTag("project") } } }); IHostSpecificDataLoader hostDataLoader = new MockHostSpecificDataLoader(); IReadOnlyCollection <ITemplateMatchInfo> projectTemplates = TemplateListResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "project"); Assert.Equal(3, projectTemplates.Count); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template1", StringComparison.Ordinal)).Any()); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template4", StringComparison.Ordinal)).Any()); Assert.True(projectTemplates.Where(x => string.Equals(x.Info.Identity, "Template5", StringComparison.Ordinal)).Any()); IReadOnlyCollection <ITemplateMatchInfo> itemTemplates = TemplateListResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "item"); Assert.Equal(1, itemTemplates.Count); Assert.True(itemTemplates.Where(x => string.Equals(x.Info.Identity, "Template2", StringComparison.Ordinal)).Any()); IReadOnlyCollection <ITemplateMatchInfo> otherTemplates = TemplateListResolver.PerformAllTemplatesInContextQuery(templatesToSearch, hostDataLoader, "other"); Assert.Equal(1, otherTemplates.Count); Assert.True(otherTemplates.Where(x => string.Equals(x.Info.Identity, "Template3", StringComparison.Ordinal)).Any()); }