public void BasicFolderHostWithModelSyntaxTest() { var host = new RazorFolderHostContainer(); host.TemplatePath = Path.GetFullPath(@"..\..\FileTemplates\"); host.BaseBinaryFolder = Environment.CurrentDirectory; // add model assembly - ie. this assembly host.AddAssemblyFromType(typeof(Person)); host.UseAppDomain = true; //host.Configuration.CompileToMemory = true; //host.Configuration.TempAssemblyPath = Environment.CurrentDirectory; host.Start(); Person person = new Person() { Name = "Rick", Company = "West Wind", Entered = DateTime.Now, Address = new Address() { Street = "32 Kaiea", City = "Paia" } }; string result = host.RenderTemplate("~/HelloWorldWithModelSyntax.cshtml", person); Console.WriteLine(result); Console.WriteLine("---"); Console.WriteLine(host.Engine.LastGeneratedCode); host.Stop(); if (result == null) { Assert.Fail(host.ErrorMessage); } Assert.IsTrue(result.Contains("West Wind")); }
public void FolderWithPartialAndLayoutTest() { var host = new RazorFolderHostContainer(); host.TemplatePath = Path.GetFullPath(@"..\..\FileTemplates\"); host.BaseBinaryFolder = Environment.CurrentDirectory; // add model assembly - ie. this assembly host.AddAssemblyFromType(typeof(Person)); host.UseAppDomain = true; //host.Configuration.CompileToMemory = true; //host.Configuration.TempAssemblyPath = Environment.CurrentDirectory; host.Start(); Person person = new Person() { Name = "John Doe", Company = "Doeboy Incorporated", Entered = DateTime.Now, Address = new Address() { Street = "32 Kaiea", City = "Paia" } }; string result = host.RenderTemplate("~/TestPartialAndLayout.cshtml", person); Console.WriteLine(result); Console.WriteLine("---"); Console.WriteLine(host.Engine.LastGeneratedCode); if (result == null) { Assert.Fail(host.ErrorMessage); } Assert.IsTrue(result.Contains("Rendering a header Partial")); Assert.IsTrue(result.Contains("</footer>")); host.Stop(); }
public void RuntimeErrorTest() { var host = new RazorFolderHostContainer(); host.TemplatePath = Path.GetFullPath(@"..\..\FileTemplates\"); host.BaseBinaryFolder = Environment.CurrentDirectory; // add model assembly - ie. this assembly host.AddAssemblyFromType(typeof(Person)); host.UseAppDomain = false; // these are implicitly set host.Configuration.CompileToMemory = false; //host.Configuration.TempAssemblyPath = Environment.CurrentDirectory; host.Start(); Person person = new Person() { Name = "Rick", Company = "West Wind", Entered = DateTime.Now, Address = new Address() { Street = "32 Kaiea", City = "Paia" } }; string result = host.RenderTemplate("~/RuntimeError.cshtml", person); Console.WriteLine(result); Console.WriteLine("---"); Console.WriteLine(host.ErrorMessage); Console.WriteLine("---"); Console.WriteLine(host.Engine.LastGeneratedCode); host.Stop(); Assert.IsNull(result); Assert.IsTrue(!string.IsNullOrEmpty(host.ErrorMessage)); }
public void MissingTemplateTest() { var host = new RazorFolderHostContainer(); host.TemplatePath = Path.GetFullPath(@"..\..\FileTemplates\"); host.BaseBinaryFolder = Environment.CurrentDirectory; // add model assembly - ie. this assembly host.AddAssemblyFromType(typeof(Person)); host.UseAppDomain = true; //host.Configuration.CompileToMemory = true; //host.Configuration.TempAssemblyPath = Environment.CurrentDirectory; host.Start(); Person person = new Person() { Name = "Rick", Company = "West Wind", Entered = DateTime.Now, Address = new Address() { Street = "32 Kaiea", City = "Paia" } }; string result = host.RenderTemplate("~/NotThere.cshtml", person); Assert.IsTrue(host.ErrorMessage.Contains("Template File doesn't exist")); Assert.IsNotNull(host.LastException); Console.WriteLine(host.ErrorMessage); Console.WriteLine("template: " + host.LastException.ActiveTemplate); host.Stop(); }
public void BasicFolderTest() { var host = new RazorFolderHostContainer(); host.TemplatePath = Path.GetFullPath(@"..\..\FileTemplates\"); host.BaseBinaryFolder = Environment.CurrentDirectory; // add model assembly - ie. this assembly host.AddAssemblyFromType(typeof(Person)); host.UseAppDomain = true; //host.Configuration.CompileToMemory = true; //host.Configuration.TempAssemblyPath = Environment.CurrentDirectory; host.Start(); Person person = new Person() { Name = "Rick", Company = "West Wind", Entered = DateTime.Now, Address = new Address() { Street = "32 Kaiea", City = "Paia" } }; string result = host.RenderTemplate("~/HelloWorld.cshtml", person); Console.WriteLine(result); Console.WriteLine("---"); Console.WriteLine(host.Engine.LastGeneratedCode); host.Stop(); if (result == null) Assert.Fail(host.ErrorMessage); Assert.IsTrue(result.Contains("West Wind")); }