public void TestWhamMasterTemplate() { WhamEngine wham = new WhamEngine(); wham.AddSchema(Schemas.AddressBaseSchema, true); wham.AddSchema(Schemas.ShippingAddressSchema, true); wham.AddSchema(Schemas.AddressCollectionSchema, true); var namedStream = SetupFakeOutput(); var masterResult = wham.Liquidize(BuiltInTemplates.WhamMasterTemplate); var errors = ("" + string.Join("\r\n", wham.Context.Errors.Select(e => e.ToString()))).Trim(); Assert.AreEqual(string.Empty, errors); Assert.IsNotEmpty(masterResult); masterResult = masterResult.Trim(); Assert.AreEqual(string.Empty, masterResult.ToLower()); Assert.IsTrue(namedStream.Items.Count >= 4); Console.WriteLine(string.Join("\r\n", namedStream.Items.Select(i => i.Name))); Assert.IsNotNull(namedStream.Items.First().Name); Assert.IsTrue(namedStream.Items.First().Name.ToLower().EndsWith("address.cs")); Assert.IsNotNull(namedStream.Items.First().WrittenContents); Assert.IsTrue(namedStream.Items.First().WrittenContents.StartsWith("using")); Assert.IsNotNull(namedStream.Items.Any(s => s.Name.ToLower().EndsWith(".csproj"))); Assert.AreEqual(2, namedStream.Items.Count(s => s.Name.ToLower().EndsWith(".config"))); Assert.AreEqual(5, namedStream.Items.Count(s => s.WrittenContents.StartsWith("<?xml"))); }
public void TestWhamMasterTemplateWithFileOutput() { WhamEngine wham = new WhamEngine(); wham.AddSchema(Schemas.AddressBaseSchema, true); wham.AddSchema(Schemas.ShippingAddressSchema, true); wham.AddSchema(Schemas.AddressCollectionSchema, true); var masterResult = wham.Liquidize(BuiltInTemplates.WhamMasterTemplate); Console.WriteLine(masterResult.Trim()); var errors = ("" + string.Join("\r\n", wham.Context.Errors.Select(e => e.ToString()))).Trim(); Console.WriteLine(errors); Assert.AreEqual(string.Empty, errors); }
public void TestShippingAddressToCS_ClassTemplate() { WhamEngine wham = new WhamEngine(); wham.AddSchema(Schemas.AddressBaseSchema); wham.AddSchema(Schemas.ShippingAddressSchema, true); var cs = wham.Liquidize(BuiltInTemplates.CS_ClassTemplate); Assert.IsNotNull(wham.Context.Strainer); Assert.IsNotNull(cs); Assert.IsTrue(cs.IndexOf("Wham.Base") > 0); Assert.IsTrue(cs.IndexOf("Liquid error:") < 0); Assert.IsEmpty(wham.Context.Errors); Assert.IsTrue(cs.IndexOf("public enum TypesEnum {") > 0); Console.WriteLine(cs); }
public void TestAddressToCS_ClassTemplateProperties() { WhamEngine wham = new WhamEngine(); wham.AddSchema(Schemas.AddressBaseSchema, true); var cs = wham.Liquidize(BuiltInTemplates.CS_ClassTemplate); Assert.IsNotNull(cs); Assert.IsTrue(cs.IndexOf("Wham.Base") > 0); Assert.IsTrue(cs.IndexOf("Liquid error:") < 0); Assert.IsEmpty(wham.Context.Errors); Console.WriteLine(cs); }
public void TestAddressToCS_ClassTemplate() { WhamEngine wham = new WhamEngine(); wham.AddSchema(Schemas.AddressBaseSchema, true); var cs = wham.Liquidize(BuiltInTemplates.CS_ClassTemplate); Assert.IsNotNull(wham.Context.Strainer); Assert.IsTrue(wham.Context.Strainer.RespondTo("Namespace")); Assert.IsNotNull(cs); Assert.IsTrue(cs.IndexOf("Wham.Base") > 0); Assert.IsTrue(cs.IndexOf("Liquid error:") < 0); Assert.IsEmpty(wham.Context.Errors); }
public void TestMasterCSTemplate() { WhamEngine wham = new WhamEngine(); wham.AddSchema(Schemas.AddressBaseSchema, true); var namedStream = SetupFakeOutput(); var masterResult = wham.Liquidize(MasterTemplate); Assert.IsTrue(wham.Context.Errors == null || wham.Context.Errors.Count == 0); Assert.IsNotEmpty(masterResult); masterResult = masterResult.Trim(); Assert.AreEqual("address.cs", masterResult.ToLower()); Assert.IsNotNull(namedStream.Name); Assert.IsTrue(namedStream.Name.ToLower().EndsWith("address.cs")); Assert.IsNotNull(namedStream.WrittenContents); Assert.IsTrue(namedStream.WrittenContents.StartsWith("using")); }
// $ mono whamrun.exe /Users/Sten/Documents/Projects/Wham/JsonSchemas public static void Main(string[] args) { AppDomain.CurrentDomain.FirstChanceException += (sender, e) => { if (e.Exception is TargetInvocationException) { Console.WriteLine("[TGIAODIFQWR] Target Invocation Exception: " + e.Exception.Message); } else { Console.WriteLine("[ATIOAEIRJQW] Exception: " + e.Exception); } }; if (args == null || !args.Any()) { Console.WriteLine("Usage: WhamRun inputFolder [outputFolder]\r\n inputFolder must contain JSON Schema files"); } else { if (Directory.Exists(args[0])) { Directory.SetCurrentDirectory(args[0]); var files = Directory.GetFiles(args[0]); var schemas = files .Select(f => new Tuple <string, string>(f, File.ReadAllText(f))) .Where(ft => ft.Item2.Contains("\"title\"")) .Select(t => new SchemaItem { FileName = t.Item1, Content = t.Item2 }) .ToList(); WhamEngine engine = new WhamEngine(); while (schemas.Any()) { var added = schemas .Where(s => string.IsNullOrEmpty(s.Uri)) .Where(s => { try { var uri = engine.AddSchema(s.Content); s.Uri = uri.AbsolutePath; return(!string.IsNullOrEmpty(s.Uri)); } catch (Exception sx) { s.Error = sx; } return(false); }) .ToList(); if (!added.Any()) { break; } } if (schemas.Any(s => string.IsNullOrEmpty(s.Uri))) { Console.WriteLine("Not all schemas can be added"); Console.WriteLine(String.Join("\r\n", schemas.Where(s => string.IsNullOrEmpty(s.Uri)) .Select(s => " File: " + s.FileName + " ERROR: " + s.Error))); } else { Console.WriteLine("All schemas loaded."); var outPath = args.Skip(1).FirstOrDefault() ?? Path.Combine(args.First(), "WhAM"); if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } Directory.SetCurrentDirectory(outPath); Console.WriteLine("Wham output to: " + outPath); var result = ("" + engine.Liquidize(BuiltInTemplates.WhamMasterTemplate)).Trim(); Console.WriteLine(result); if (engine.Context.Errors != null && engine.Context.Errors.Any()) { Console.WriteLine("dotLIQUID ERRORS:"); Console.WriteLine(string.Join(System.Environment.NewLine, engine.Context.Errors.Select(e => " - Error: " + e.Message + " " + e.InnerException))); } Console.WriteLine("Done."); } } else { Console.WriteLine("input folder must exist"); } } }