예제 #1
0
        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());
        }
예제 #2
0
        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());
        }