public void GetParametersInvalidForTemplatesInList_NoneForAllTest() { List <ITemplateMatchInfo> matchInfo = new List <ITemplateMatchInfo>(); // template one List <MatchInfo> templateOneDispositions = new List <MatchInfo>(); templateOneDispositions.Add(new MatchInfo() { Location = MatchLocation.OtherParameter, Kind = MatchKind.InvalidParameterName, InputParameterName = "foo" }); templateOneDispositions.Add(new MatchInfo() { Location = MatchLocation.OtherParameter, Kind = MatchKind.InvalidParameterName, InputParameterName = "bar" }); ITemplateMatchInfo templateOneMatchInfo = new TemplateMatchInfo(new TemplateInfo(), templateOneDispositions); matchInfo.Add(templateOneMatchInfo); // template two List <MatchInfo> templateTwoDispositions = new List <MatchInfo>(); ITemplateMatchInfo templateTwoMatchInfo = new TemplateMatchInfo(new TemplateInfo(), templateTwoDispositions); matchInfo.Add(templateTwoMatchInfo); HelpForTemplateResolution.GetParametersInvalidForTemplatesInList(matchInfo, out IReadOnlyList <string> invalidForAllTemplates, out IReadOnlyList <string> invalidForSomeTemplates); Assert.Equal(0, invalidForAllTemplates.Count); Assert.Equal(2, invalidForSomeTemplates.Count); Assert.Contains("foo", invalidForSomeTemplates); Assert.Contains("bar", invalidForSomeTemplates); }
public static IReadOnlyCollection <ITemplateMatchInfo> GetTemplateMatchInfo(IReadOnlyList <ITemplateInfo> templateList, Func <ITemplateMatchInfo, bool> matchFilter, params Func <ITemplateInfo, MatchInfo?>[] filters) { HashSet <ITemplateMatchInfo> matchingTemplates = new HashSet <ITemplateMatchInfo>(TemplateMatchInfoEqualityComparer.Default); foreach (ITemplateInfo template in templateList) { List <MatchInfo> matchInformation = new List <MatchInfo>(); foreach (Func <ITemplateInfo, MatchInfo?> filter in filters) { MatchInfo?result = filter(template); if (result.HasValue) { matchInformation.Add(result.Value); } } ITemplateMatchInfo info = new TemplateMatchInfo(template, matchInformation); if (matchFilter(info)) { matchingTemplates.Add(info); } } #if !NETFULL return(matchingTemplates); #else return(matchingTemplates.ToList()); #endif }
public void TestHasClassificationMatchAndNameMismatch_NameMismatchClassificationPartialOtherStartsWith() { List <MatchInfo> testDisposiions = new List <MatchInfo>(); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.Name, Kind = MatchKind.Mismatch }); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.Classification, Kind = MatchKind.Partial }); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.OtherParameter, Kind = MatchKind.SingleStartsWith }); ITemplateMatchInfo testTemplate = new TemplateMatchInfo(new TemplateInfo() { Name = "Template1", Identity = "Template1", GroupIdentity = "TestGroup" }, testDisposiions); Assert.True(testTemplate.HasClassificationMatchAndNameMismatch()); }
public void TestHasClassificationMatchAndNameMismatch_NameMismatchClassificationPartialLanguageMismatch() { List <MatchInfo> testDisposiions = new List <MatchInfo>(); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.Name, Kind = MatchKind.Mismatch }); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.Classification, Kind = MatchKind.Partial }); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.Language, Kind = MatchKind.Mismatch }); ITemplateMatchInfo testTemplate = new TemplateMatchInfo(new TemplateInfo() { Name = "Template1", Identity = "Template1", GroupIdentity = "TestGroup" }, testDisposiions); Assert.False(testTemplate.HasClassificationMatchAndNameMismatch()); }
public void GetParametersInvalidForTemplatesInList_NoneForSomeTest() { List <ITemplateMatchInfo> matchInfo = new List <ITemplateMatchInfo>(); // template one List <MatchInfo> templateOneDispositions = new List <MatchInfo>(); templateOneDispositions.Add(new ParameterMatchInfo("foo", "test", MatchKind.InvalidName)); ITemplateMatchInfo templateOneMatchInfo = new TemplateMatchInfo(new MockTemplateInfo(), templateOneDispositions); matchInfo.Add(templateOneMatchInfo); // template two List <MatchInfo> templateTwoDispositions = new List <MatchInfo>(); templateTwoDispositions.Add(new ParameterMatchInfo("foo", "test", MatchKind.InvalidName)); ITemplateMatchInfo templateTwoMatchInfo = new TemplateMatchInfo(new MockTemplateInfo(), templateTwoDispositions); matchInfo.Add(templateTwoMatchInfo); HelpForTemplateResolution.GetParametersInvalidForTemplatesInList(matchInfo, out IReadOnlyList <string> invalidForAllTemplates, out IReadOnlyList <string> invalidForSomeTemplates); Assert.Equal(1, invalidForAllTemplates.Count); Assert.Contains("foo", invalidForAllTemplates); Assert.Equal(0, invalidForSomeTemplates.Count); }
public void TypeMismatch_ReportsCorrectly() { ITemplateInfo templateInfo = new MockTemplateInfo(); ITemplateMatchInfo templateMatchInfo = new TemplateMatchInfo(templateInfo); templateMatchInfo.AddMatchDisposition(new MatchInfo(MatchInfo.BuiltIn.Type, "test", MatchKind.Mismatch)); Assert.False(WellKnownSearchFilters.MatchesAllCriteria(templateMatchInfo)); Assert.False(WellKnownSearchFilters.MatchesAtLeastOneCriteria(templateMatchInfo)); }
public void NamePartialMatch_ReportsCorrectly() { ITemplateInfo templateInfo = new MockTemplateInfo(); ITemplateMatchInfo templateMatchInfo = new TemplateMatchInfo(templateInfo); templateMatchInfo.AddMatchDisposition(new MatchInfo(MatchInfo.BuiltIn.Name, "test", MatchKind.Partial)); Assert.True(WellKnownSearchFilters.MatchesAllCriteria(templateMatchInfo)); Assert.True(WellKnownSearchFilters.MatchesAtLeastOneCriteria(templateMatchInfo)); }
public void EmptyMatchDisposition_ReportsCorrectly() { ITemplateInfo templateInfo = new MockTemplateInfo(); ITemplateMatchInfo templateMatchInfo = new TemplateMatchInfo(templateInfo); Assert.False(WellKnownSearchFilters.MatchesAllCriteria(templateMatchInfo)); Assert.False(WellKnownSearchFilters.MatchesAtLeastOneCriteria(templateMatchInfo)); Assert.Empty(templateMatchInfo.GetInvalidParameterNames()); Assert.Equal(0, templateMatchInfo.GetValidTemplateParameters().Count); }
public void TypeMatch_ReportsCorrectly() { ITemplateInfo templateInfo = new MockTemplateInfo(); ITemplateMatchInfo templateMatchInfo = new TemplateMatchInfo(templateInfo); templateMatchInfo.AddMatchDisposition(new MatchInfo(MatchInfo.BuiltIn.Type, "test", MatchKind.Exact)); Assert.True(WellKnownSearchFilters.MatchesAllCriteria(templateMatchInfo)); Assert.True(WellKnownSearchFilters.MatchesAtLeastOneCriteria(templateMatchInfo)); Assert.True(templateMatchInfo.IsInvokableMatch()); Assert.False(templateMatchInfo.HasAmbiguousParameterValueMatch()); }
public void Update(TemplateMatchInfo info) { var updateParms = new IDataParameter[] { GetParameter(ParmChannelTemplateId, DataType.Integer, info.ChannelTemplateId), GetParameter(ParmContentTemplateId, DataType.Integer, info.ContentTemplateId), GetParameter(ParmFilepath, DataType.VarChar, 200, info.FilePath), GetParameter(ParmChannelFilepathRule, DataType.VarChar, 200, info.ChannelFilePathRule), GetParameter(ParmContentFilepathRule, DataType.VarChar, 200, info.ContentFilePathRule), GetParameter(ParmChannelId, DataType.Integer, info.ChannelId) }; ExecuteNonQuery(SqlUpdate, updateParms); }
public void Insert(TemplateMatchInfo info) { var insertParms = new IDataParameter[] { GetParameter(ParmNodeId, EDataType.Integer, info.NodeId), GetParameter(ParmPublishmentSystemId, EDataType.Integer, info.PublishmentSystemId), GetParameter(ParmChannelTemplateId, EDataType.Integer, info.ChannelTemplateId), GetParameter(ParmContentTemplateId, EDataType.Integer, info.ContentTemplateId), GetParameter(ParmFilepath, EDataType.VarChar, 200, info.FilePath), GetParameter(ParmChannelFilepathRule, EDataType.VarChar, 200, info.ChannelFilePathRule), GetParameter(ParmContentFilepathRule, EDataType.VarChar, 200, info.ContentFilePathRule) }; ExecuteNonQuery(SqlInsert, insertParms); }
public void EmptyMatchDisposition_ReportsCorrectly() { ITemplateInfo templateInfo = new TemplateInfo(); ITemplateMatchInfo TemplateMatchInfo = new TemplateMatchInfo(templateInfo); Assert.False(TemplateMatchInfo.IsMatch); Assert.False(TemplateMatchInfo.IsMatchExceptContext()); Assert.False(TemplateMatchInfo.IsPartialMatch); Assert.False(TemplateMatchInfo.IsPartialMatchExceptContext()); Assert.False(TemplateMatchInfo.IsInvokableMatch()); Assert.False(TemplateMatchInfo.HasAmbiguousParameterValueMatch()); Assert.False(TemplateMatchInfo.HasParameterMismatch()); Assert.False(TemplateMatchInfo.HasParseError()); Assert.Equal(0, TemplateMatchInfo.GetInvalidParameterNames().Count); Assert.Equal(0, TemplateMatchInfo.GetValidTemplateParameters().Count); }
public void ContextMatch_ReportsCorrectly() { ITemplateInfo templateInfo = new TemplateInfo(); ITemplateMatchInfo TemplateMatchInfo = new TemplateMatchInfo(templateInfo); TemplateMatchInfo.AddDisposition(new MatchInfo { Location = MatchLocation.Context, Kind = MatchKind.Exact }); Assert.True(TemplateMatchInfo.IsMatch); Assert.False(TemplateMatchInfo.IsMatchExceptContext()); Assert.True(TemplateMatchInfo.IsPartialMatch); Assert.False(TemplateMatchInfo.IsPartialMatchExceptContext()); Assert.True(TemplateMatchInfo.IsInvokableMatch()); Assert.False(TemplateMatchInfo.HasAmbiguousParameterValueMatch()); Assert.False(TemplateMatchInfo.HasParameterMismatch()); Assert.False(TemplateMatchInfo.HasParseError()); }
public void TestHasClassificationMatchAndNameMismatch_ShortNameExactAndClassificationPartial() { List <MatchInfo> testDispositions = new List <MatchInfo>(); testDispositions.Add(new MatchInfo() { Location = MatchLocation.ShortName, Kind = MatchKind.Exact }); testDispositions.Add(new MatchInfo() { Location = MatchLocation.Classification, Kind = MatchKind.Partial }); ITemplateMatchInfo testTemplate = new TemplateMatchInfo(new MockTemplateInfo("Template1", groupIdentity: "TestGroup"), testDispositions); Assert.False(testTemplate.HasClassificationMatchAndNameMismatch()); }
public TemplateMatchInfo GetTemplateMatchInfo(int channelId) { TemplateMatchInfo info = null; var parms = new IDataParameter[] { GetParameter(ParmChannelId, DataType.Integer, channelId) }; using (var rdr = ExecuteReader(SqlSelect, parms)) { if (rdr.Read()) { var i = 0; info = new TemplateMatchInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetInt(rdr, i++), GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), GetString(rdr, i)); } rdr.Close(); } return(info); }
public void TestHasClassificationMatchAndNameMismatch_ShortNameMismatchAndClassificationExact() { List <MatchInfo> testDisposiions = new List <MatchInfo>(); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.ShortName, Kind = MatchKind.Mismatch }); testDisposiions.Add(new MatchInfo() { Location = MatchLocation.Classification, Kind = MatchKind.Exact }); ITemplateMatchInfo testTemplate = new TemplateMatchInfo(new TemplateInfo() { Name = "Template1", Identity = "Template1", GroupIdentity = "TestGroup" }, testDisposiions); Assert.True(testTemplate.HasClassificationMatchAndNameMismatch()); }