public void ResolveOrderUsed() { var model = PersistentModel.Compile(@" class a prototype=dbtable resolve string Tag resolve=20 string Tag2 resolve=10 string Tag3 resolve=30 "); var code = new ResolveTagFacilityWriter(model) { WithHeader = false }.ToString(); Console.WriteLine(code.Replace("\"", "\"\"")); Assert.AreEqual(@" using System; using System.Collections.Generic; using System.Linq; using Qorpent.Utils.Extensions; namespace Orm{ ///<summary>Extensions for resolvetag model objects</summary> public static partial class ResolveTagFacility { ///<summary>Resolves all tags for a</summary> public static string ResolveTag(this a target, string name, ResolveTagOptions options = null) { if(null==target)return """"; if(string.IsNullOrWhiteSpace(name))return """"; options = options ?? ResolveTagOptions.Default; var result = string.Empty; if (options.aTag2){ result = target.Tag2.SmartSplit().Contains(name)?name:""""; if (!string.IsNullOrWhiteSpace(result))return result; } if (options.aTag){ result = TagHelper.Value ( target.Tag, name); if (!string.IsNullOrWhiteSpace(result))return result; } if (options.aTag3){ result = target.Tag3.SmartSplit().Contains(name)?name:""""; if (!string.IsNullOrWhiteSpace(result))return result; } return result??""""; } } } ".Trim(), code.Trim()); }
public void ReferencedTableResolution() { var model = PersistentModel.Compile(@" class a prototype=dbtable resolve string Tag resolve=10 a b prototype=dbtable resolve ref a resolve string Marks resolve b c prototype=dbtable resolve ref b resolve "); Assert.AreEqual(99999, model["b"]["a"].ResolvePriority); Assert.True(model["c"]["b"].Resolve); Assert.True(model["c"]["Tag"].Resolve); Assert.True(model["c"]["Marks"].Resolve); Assert.True(model["c"]["a"].Resolve); var code = new ResolveTagFacilityWriter(model) { WithHeader = false }.ToString(); Console.WriteLine(code.Replace("\"", "\"\"")); Assert.AreEqual(@" using System; using System.Collections.Generic; using System.Linq; using Qorpent.Utils.Extensions; namespace Orm{ ///<summary>Extensions for resolvetag model objects</summary> public static partial class ResolveTagFacility { ///<summary>Resolves all tags for a</summary> public static string ResolveTag(this a target, string name, ResolveTagOptions options = null) { if(null==target)return """"; if(string.IsNullOrWhiteSpace(name))return """"; options = options ?? ResolveTagOptions.Default; var result = string.Empty; if (options.aTag){ result = TagHelper.Value ( target.Tag, name); if (!string.IsNullOrWhiteSpace(result))return result; } return result??""""; } ///<summary>Resolves all tags for b</summary> public static string ResolveTag(this b target, string name, ResolveTagOptions options = null) { if(null==target)return """"; if(string.IsNullOrWhiteSpace(name))return """"; options = options ?? ResolveTagOptions.Default; var result = string.Empty; if (options.bTag){ result = TagHelper.Value ( target.Tag, name); if (!string.IsNullOrWhiteSpace(result))return result; } if (options.bMarks){ result = target.Marks.SmartSplit().Contains(name)?name:""""; if (!string.IsNullOrWhiteSpace(result))return result; } if (options.ba){ result = target.a.ResolveTag(name); if (!string.IsNullOrWhiteSpace(result))return result; } return result??""""; } ///<summary>Resolves all tags for c</summary> public static string ResolveTag(this c target, string name, ResolveTagOptions options = null) { if(null==target)return """"; if(string.IsNullOrWhiteSpace(name))return """"; options = options ?? ResolveTagOptions.Default; var result = string.Empty; if (options.cTag){ result = TagHelper.Value ( target.Tag, name); if (!string.IsNullOrWhiteSpace(result))return result; } if (options.cMarks){ result = target.Marks.SmartSplit().Contains(name)?name:""""; if (!string.IsNullOrWhiteSpace(result))return result; } if (options.ca){ result = target.a.ResolveTag(name); if (!string.IsNullOrWhiteSpace(result))return result; } if (options.cb){ result = target.b.ResolveTag(name); if (!string.IsNullOrWhiteSpace(result))return result; } return result??""""; } } } ".Trim(), code.Trim()); }