public void CloneableFacilityWriterWithRefs() { var model = PersistentModel.Compile(@" class a prototype=dbtable cloneable class b prototype=dbtable cloneable ref a reverse "); var code = new CloneFacilityWriter(model) { WithHeader = false }.ToString().Replace("\"", "\"\""); Console.WriteLine(code); Assert.AreEqual(@" using System; using System.Collections.Generic; using System.Linq; namespace Orm{ ///<summary>Extensions for cloning model objects</summary> public static partial class CloneFacility { ///<summary>Clones a</summary> public static a Clone(this a target, CloneOptions options = null) { if(null==target)return null; options = options ?? CloneOptions.Default; var result = new a(); result.Id = target.Id; if(options.abs) { result.bs = target.bs.Select(_=>_.Clone(options)).ToList(); }else{ result.bs = target.bs; } return result; } ///<summary>Clones b</summary> public static b Clone(this b target, CloneOptions options = null) { if(null==target)return null; options = options ?? CloneOptions.Default; var result = new b(); result.Id = target.Id; if(options.ba)result.a = result.a.Clone(); else result.a = target.a; return result; } } } ".Trim(), code.Trim()); }
public void EmptyCloneableFacilityWriter() { var model = PersistentModel.Compile(@" class a prototype=dbtable "); var code = new CloneFacilityWriter(model) { WithHeader = false }.ToString().Replace("\"", "\"\""); Console.WriteLine(code); Assert.AreEqual(@" using System; using System.Collections.Generic; using System.Linq; namespace Orm{ ///<summary>Extensions for cloning model objects</summary> public static partial class CloneFacility { } } ".Trim(), code.Trim()); }