public void LayoutRendererTests() { var host = new MemoryHost(); //create a view engine var viewEngine = new ParrotViewEngine(host); host.DependencyResolver.Register(typeof(IViewEngine), () => viewEngine); var layout = "html > body > content"; var testFile = "layout(\"layout\") { div > \"testing\" }"; var pathResolver = new Mock<IPathResolver>(); pathResolver.Setup(p => p.OpenFile("index.parrot")).Returns(new MemoryStream(Encoding.Default.GetBytes(testFile))); pathResolver.Setup(p => p.OpenFile("~/Views/Shared/layout.parrot")).Returns(new MemoryStream(Encoding.Default.GetBytes(layout))); pathResolver.Setup(p => p.FileExists(It.IsAny<string>())).Returns(false); pathResolver.Setup(p => p.FileExists("~/Views/Shared/layout.parrot")).Returns(true); pathResolver.Setup(p => p.VirtualFilePath("~/Views/Shared/layout.parrot")).Returns("~/Views/Shared/layout.parrot"); host.DependencyResolver.Register(typeof(IPathResolver), () => pathResolver.Object); ////TODO: Figure this out later... var view = new ParrotView(host, "index.parrot"); StringBuilder sb = new StringBuilder(); view.Render(null, new StringWriter(sb)); Assert.AreEqual("<html><body><div>testing</div></body></html>", sb.ToString()); }
public void InputWithoutAnythingSpecialReturnsBasicInputElement() { var host = new MemoryHost(); string block = "input"; var nodes = Parse(block, host); IRendererFactory factory = new RendererFactory(host); factory.RegisterFactory("input", new InputRenderer(host)); var renderer = factory.GetRenderer(nodes.Children.First().Name); var result = renderer.Render(nodes.Children.First(), null); Assert.AreEqual("<input />", result); }
public void InputWithAttributsReturnsElementWithAttributes() { var host = new MemoryHost(); string block = "input[attr=\"value\"]"; var nodes = Parse(block, host); IRendererFactory factory = new RendererFactory(host); factory.RegisterFactory("input", new InputRenderer(host)); var renderer = factory.GetRenderer(nodes.Children.First().Name); var result = renderer.Render(nodes.Children.First(), null); Assert.AreEqual("<input attr=\"value\" />", result); }
public void StandardSingleFileSimpleRenderingLayout() { var host = new MemoryHost(); //create a view engine and register it var viewEngine = new ParrotViewEngine(host); host.DependencyResolver.Register(typeof(IViewEngine), () => viewEngine); var testFile = "div > \"testing\""; var pathResolver = new Mock<IPathResolver>(); pathResolver.Setup(p => p.OpenFile("index.parrot")).Returns(new MemoryStream(Encoding.Default.GetBytes(testFile))); //register the path resolver with the dependency resolver host.DependencyResolver.Register(typeof(IPathResolver), () => pathResolver.Object); ////TODO: Figure this out later... var view = new ParrotView(host, "index.parrot"); StringBuilder sb = new StringBuilder(); view.Render(null, new StringWriter(sb)); Assert.AreEqual("<div>testing</div>", sb.ToString()); }