public void Will_throw_argument_out_of_range_exception_if_trying_to_generate_unregistered_template() { var testable = new RazorTemplateGenerator(); testable.RegisterTemplate <test1>("this is a test for @Model.Param1"); testable.CompileTemplates(); testable.GenerateOutput(new test1() { Param1 = "p1" }); var ex = Record.Exception(() => testable.GenerateOutput(new test2() { Param1 = "p2" })); Assert.IsTrue(ex is ArgumentOutOfRangeException); }
public void Will_Compile_multiple_Template_String_with_same_model() { var testable = new RazorTemplateGenerator(); testable.RegisterTemplate <test1>("this is a test for @Model.Param1"); testable.RegisterTemplate <test1>("namedTemplate", "this is another test for @Model.Param1"); testable.CompileTemplates(); var result1 = testable.GenerateOutput(new test1() { Param1 = "p1" }); var result2 = testable.GenerateOutput(new test1() { Param1 = "p2" }, "namedTemplate"); Assert.AreEqual("this is a test for p1", result1); Assert.AreEqual("this is another test for p2", result2); }
public void Will_Compile_multiple_Template_String_registered() { var testable = new RazorTemplateGenerator(); testable.RegisterTemplate <TestModel1>("this is a test for @Model.Param1"); testable.RegisterTemplate <TestModel2>("this is another test for @Model.Param1"); testable.CompileTemplates(); var result1 = testable.GenerateOutput(new TestModel1() { Param1 = "p1" }); var result2 = testable.GenerateOutput(new TestModel2() { Param1 = "p2" }); Assert.Equal("this is a test for p1", result1); Assert.Equal("this is another test for p2", result2); }
public void Will_throw_NullArgumentException_if_attempt_to_compile_template_with_null_name() { var testable = new RazorTemplateGenerator(); testable.RegisterTemplate <test1>("this is a test for @Model.Param1"); testable.CompileTemplates(); var ex = Record.Exception(() => testable.GenerateOutput(new test1(), null)); Assert.IsTrue(ex is ArgumentNullException); Assert.AreEqual("templateName", (ex as ArgumentNullException).ParamName); }
public void Will_throw_InvalidOperationException_if_attempt_to_generate_without_compiling() { var testable = new RazorTemplateGenerator(); testable.RegisterTemplate <test1>("this is a test for @Model.Param1"); var ex = Record.Exception(() => testable.GenerateOutput(new test1() { Param1 = "p1" })); Assert.IsTrue(ex is InvalidOperationException); }
public void Will_Compile_single_Template_String_registered() { var testable = new RazorTemplateGenerator(); testable.RegisterTemplate <test1>("this is a test for @Model.Param1"); testable.CompileTemplates(); var result = testable.GenerateOutput(new test1() { Param1 = "p1" }); Assert.AreEqual("this is a test for p1", result); }
public void Will_overwrite_existing_Template() { var testable = new RazorTemplateGenerator(); testable.RegisterTemplate <test1>("this is a test for @Model.Param1"); testable.RegisterTemplate <test1>("this is another test for @Model.Param1"); testable.CompileTemplates(); var result1 = testable.GenerateOutput(new test1() { Param1 = "p1" }); Assert.AreEqual("this is another test for p1", result1); }
public void Test() { IRazorTemplateGenerator generator = new RazorTemplateGenerator(); generator.RegisterTemplate <SampleModel>(SampleTemplateStrings.Sample1); generator.CompileTemplates(); var output = generator.GenerateOutput(new SampleModel() { Prop1 = "p1", Prop2 = "p2", Prop3 = new List <string> { "pe1", "pe2", "pe3" } }); Console.WriteLine(output); Console.ReadLine(); }
static void Main(string[] args) { IRazorTemplateGenerator generator = new RazorTemplateGenerator(); generator.RegisterTemplate <SampleModel>(SampleTemplateStrings.Sample1); generator.CompileTemplates(); var output = generator.GenerateOutput(new SampleModel() { Prop1 = "p1", Prop2 = "p2", Prop3 = new List <string> { "pe1", "pe2", "pe3" } }); System.Console.Out.WriteLine(output); System.Console.In.ReadLine(); }
public void Test() { IRazorTemplateGenerator generator = new RazorTemplateGenerator(); var p = new policy { policyholders = new PolicyHolders { primarypolicyholder = new PolicyHolder { firstname = "jane", lastname = "doe" } } }; generator.RegisterTemplate <policy>(ResourceHelper.TestView); generator.CompileTemplates(); var output = generator.GenerateOutput(p); string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); if (output.StartsWith(byteOrderMarkUtf8)) { output = output.Remove(0, byteOrderMarkUtf8.Length); } output = output.Replace(Environment.NewLine, string.Empty); var xmldoc = XDocument.Parse(output); //Console.Out.WriteLine(output2); string formattedXml = XElement.Parse(output).ToString(); Console.WriteLine(formattedXml); Console.In.ReadLine(); }
public override void RunOnce() { Trace.WriteLine("Mailer started.", "EML"); Program.LogSafe("BtRetryService: Mailer started.", EventLogEntryType.Information); List <Task> emailTasks = new List <Task>(); try { if (!Force) { Thread.CurrentThread.WaitUntil(StartAt); } TransferDbEntities transferDb = new TransferDbEntities(); var emails = from em in transferDb.EmailLists where em.el_active == true select em; if (emails.Count() == 0) { Trace.WriteLine("No email addresses found", "EML"); Program.LogSafe("BtRetryService: No email addresses found.", EventLogEntryType.Warning); return; } var generator = new RazorTemplateGenerator(); //em.el_body_template -> " //<table> // <tr><th>iso</th><th>date</th><th>description</th><th>created by</th></tr> //@foreach (var i in Model.Results) // {<tr> // <td>@i.vt_v_country_iso_id</td><td>@i.vt_last_modification_date</td><td>@i.vt_status_description</td><td>@i.vt_created_by</td> // </tr>} //</table>" foreach (var em in emails) { generator.RegisterTemplate <Data>("__" + em.el_id, em.el_body_template); } generator.CompileTemplates(); var date = Force ? ForceDate : DateTime.Now.Yesterday(); foreach (var em in emails) { if (!em.IsValid()) { Trace.WriteLine("Invalid emailList entry: ".concat(em.ToString()), "EML"); Program.LogSafe("BtRetryService: Invalid emailList entry: ".concat(em.ToString()), EventLogEntryType.Warning); continue; } int iso = em.el_iso_id; int em_id = em.el_id; TransferDBDataAccess.RetailersTable = Hashtable.Synchronized(PTFDbDataAccess.GetAllRetailers(iso)); Data data = new Data(); data.Db = transferDb; foreach (var filter in em.el_filter.Split(';')) { var voucherTransfers = from vt in transferDb.VoucherTransfers where vt.vt_v_country_iso_id == iso && //select yesterday's transfers only vt.vt_last_modification_date >= date select vt; CString str = "vt_status_description != null && (" + filter + ")"; var voucherTransfers2 = voucherTransfers.Where(str); data.Results.AddRange(voucherTransfers2); } if (!data.IsEmpty) { //em.el_list - > [email protected],[email protected],[email protected] //em.el_subject -> Error in voucher import var emd = new EmailData { AddrList = (EmailMe ? Strings.ROSENRUSEV : em.el_list), Subject = em.el_subject }; string str = generator.GenerateOutput(data, "__" + em.el_id); emd.Body = str.Replace("SHOW_BEGIN", "<a href='http://192.168.53.117/VoucherTransferXmls/XmlDataHandler.ashx?id=").Replace("SHOW_END", "'>Show</a>"); Trace.WriteLine("emailing:".concat(em.el_list), "EML"); var task = Task.Factory.StartNew <bool>((o) => { var ed = (EmailData)o; Program.LogSafe("Email : ".concat(ed.AddrList.FirstOf(35), "..."), EventLogEntryType.Information); EmailSender.SendSafe(ed.AddrList, "", ed.Subject, ed.Body, true); return(true); }, emd); emailTasks.Add(task); } thread.Yield(); } } catch (Exception ex) { Trace.WriteLine(ex, "EML"); Program.LogSafe(ex.ToString(), EventLogEntryType.Error); } finally { Task.WaitAll(emailTasks.ToArray()); Trace.WriteLine("Mailer stopped.", "EML"); Program.LogSafe("Mailer stopped.", EventLogEntryType.Information); } }