public static IEnumerable <Exception> Test_DoesNotContainMarkupExpressions(LoveTemplate template, IViewViewModelPair viewViewModelPair) { foreach (var n in template.Flatten()) { if (n is LoveMarkupExpression) { yield return(new LoveTestFail(n, "is Markup Expression")); } } }
//public static IEnumerable<Exception> Test_DoesNotContainViewModelReferencesInMarkup(LoveTemplate template, IViewViewModelPair viewViewModelPair) //{ // var model = viewViewModelPair.Model; // var propertyMappings = GetPropertyMappings(model.GetType()); // var propertyNames = propertyMappings.SelectMany(p => p.Split('.')); // var propertyLookups = propertyNames.Select(p=> "." + p); // foreach (var n in template.Flatten()) // { // if (n is LoveMarkup) // { // var nMarkup = n as LoveMarkup; // if (propertyLookups.Any(p => nMarkup.Content.Contains(p))) // { // yield return new LoveTestFail(n, "has View Model Reference in Markup"); // } // } // } //} public static IEnumerable <Exception> Test_DoesNotContainViewModelValueInMarkup(LoveTemplate template, IViewViewModelPair viewViewModelPair) { var model = viewViewModelPair.ModelUntyped; var values = GetPropertyValues(model) .Where(v => v.Length != 1 || v.ToInt() > 1) .Where(v => v != "True" && v != "False") .ToList(); foreach (var n in template.Flatten()) { if (n is LoveMarkup) { var nMarkup = n as LoveMarkup; if (values.Any(v => nMarkup.Content.Contains(v))) { yield return(new LoveTestFail(n, "has View Model Value in Markup")); } } } }
public static IEnumerable <Exception> Test_AllBindingsMapToViewModel(LoveTemplate template, IViewViewModelPair viewViewModelPair) { var model = viewViewModelPair.ModelUntyped; var propertyMappings = GetPropertyMappings(model.GetType()).ToList(); var scopes = new string[] { "Model" }.ToDictionary(s => s, s => new HashSet <string>(propertyMappings.Select(p => s + "." + p))); foreach (var n in template.Flatten()) { if (n is LoveBinding) { var exp = (n as LoveBinding).Content; var validScopes = new List <string>() { "Model" }; // Create Scopes foreach (var lScope in n.GetScopes()) { var lName = lScope.Name.Content; if (scopes.ContainsKey(lName)) { validScopes.Add(lName); continue; } var lExp = lScope.Expression.Content; if (lScope.ScopeType == LoveScopeType.Foreach) { lExp = lExp + ".Item"; } else { throw new NotImplementedException(); //mappingsInScope.Add(lName + m.Substring(lExp.Length)); } var mappingsInScope = new HashSet <string>(); foreach (var s in validScopes) { foreach (var m in scopes[s]) { if (m.StartsWith(lExp)) { mappingsInScope.Add(lName + m.Substring(lExp.Length)); } } } if (mappingsInScope.Count > 0) { validScopes.Add(lName); scopes.Add(lName, mappingsInScope); } } // Find mapping in scope var foundMapping = false; foreach (var s in validScopes) { if (scopes[s].Contains(exp)) { foundMapping = true; break; } } if (!foundMapping) { yield return(new LoveTestFail(n, "does Not Map to View Model")); } } } }