Esempio n. 1
0
        public void Should_expand_partial_inside_each_section_with_current_as_model()
        {
            const string input = @"<html><head></head><body>@Each;@Partial['testing', @Current];@EndEach</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi @Model ";
            var model = new List<string>() { "foo", "bar" };

            var result = viewEngine.Render(input, model, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Hi foo Hi bar </body></html>", result);
        }
Esempio n. 2
0
        public void Should_expand_multiple_partials_inside_each_section()
        {
            const string input = @"<html><head></head><body>@Each;@Partial['greeting'], @Partial['name'];@EndEach</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) =>
            {
                return (s.Equals("greeting")) ? "Hi" : "Nancy";
            };
            var model = new List<string>() { "foo", "bar" };

            var result = viewEngine.Render(input, model, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Hi, NancyHi, Nancy</body></html>", result);
        }
Esempio n. 3
0
        public void Should_expand_partial_inside_each_section_with_parameter_of_current_as_model()
        {
            const string input = @"<html><head></head><body>@Each;@Partial['testing', @Current.Name];@EndEach</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi @Model ";

            dynamic foo = new ExpandoObject();
            foo.Name = "foo";

            dynamic bar = new ExpandoObject();
            bar.Name = "bar";

            var model = new List<ExpandoObject>() { foo, bar };

            var result = viewEngine.Render(input, model, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Hi foo Hi bar </body></html>", result);
        }
        public void Should_handle_master_page_hierarchies()
        {
            const string input = "@Master['middle']\r\n@Section['MiddleContent']Middle@EndSection";
            const string middle = "@Master['top']\r\n@Section['TopContent']Top\r\n@Section['MiddleContent']@EndSection";
            const string top = "Top! @Section['TopContent']";

            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => s == "middle" ? middle : top;
            var viewEngine = new SuperSimpleViewEngine();

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal("Top! Top\r\nMiddle", result);
        }
        public void Should_expand_partial_content_with_specified_model_property_if_specified()
        {
            const string input = @"<html><head></head><body>@Partial['testing', Model.User];</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hello @Model.Name";
            dynamic model = new ExpandoObject();
            dynamic subModel = new ExpandoObject();
            model.Name = "Jim";
            subModel.Name = "Bob";
            model.User = subModel;
            var viewEngine = new SuperSimpleViewEngine();

            var result = viewEngine.Render(input, model, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Hello Bob</body></html>", result);
        }
        public void Should_expand_partial_content_even_with_no_model()
        {
            const string input = @"<html><head></head><body>@Partial['testing'];</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => "Test partial content";
            var viewEngine = new SuperSimpleViewEngine();

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Test partial content</body></html>", result);
        }
        public void Should_expand_anti_forgery_tokens()
        {
            const string input = "<html><body><form>@AntiForgeryToken</form><body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            var viewEngine = new SuperSimpleViewEngine();

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal("<html><body><form>CSRF</form><body></html>", result);
        }
        public void Should_call_to_expand_paths()
        {
            const string input = @"<script src='@Path['~/scripts/test.js']'></script>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.ExpandPathCallBack = s => s.Replace("~/", "/BasePath/");
            var viewEngine = new SuperSimpleViewEngine();

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal("<script src='/BasePath/scripts/test.js'></script>", result);
        }
        public void Should_also_expand_master_page_with_same_model()
        {
            const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
            const string master = @"Hello @Model.Name!<div id='header'>@Section['Header'];</div><div id='footer'>@Section['Footer'];</div>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => master;
            var viewEngine = new SuperSimpleViewEngine();

            var result = viewEngine.Render(input, new { Name = "Bob" }, fakeViewEngineHost);

            Assert.Equal("Hello Bob!<div id='header'>\r\nHeader\r\n</div><div id='footer'>\r\nFooter\r\n</div>", result);
        }
Esempio n. 10
0
        public void Should_expand_multiple_partial_inside_each_section_with_different_parameter_of_current_as_model()
        {
            const string input = @"<html><head></head><body>@Each;@Partial['first', @Current.First];-@Partial['second', @Current.Last];@EndEach</body></html>";

            var fakeViewEngineHost = new FakeViewEngineHost
            {
                GetTemplateCallback = (s, m) =>
                {
                    return (s.Equals("first")) ?
                        "Hi @Model" :
                        "Hello @Model";
                }
            };

            dynamic foo = new ExpandoObject();
            foo.First = "foo";
            foo.Last = "bar";

            dynamic bar = new ExpandoObject();
            bar.First = "baz";
            bar.Last = "bin";

            var model = new List<ExpandoObject>() { foo, bar };

            var result = viewEngine.Render(input, model, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Hi foo-Hello barHi baz-Hello bin</body></html>", result);
        }
Esempio n. 11
0
        public void Should_expand_basic_partials()
        {
            const string input = @"<html><head></head><body>@Partial['testing'];</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => "Test partial content";

            var result = viewEngine.Render(input, new object(), fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Test partial content</body></html>", result);
        }
Esempio n. 12
0
        public void Should_also_expand_master_page_with_same_context()
        {
            const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
            const string master = @"Hello @Context.Name!<div id='header'>@Section['Header'];</div><div id='footer'>@Section['Footer'];</div>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => master;

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal("Hello Frank!<div id='header'>\r\nHeader\r\n</div><div id='footer'>\r\nFooter\r\n</div>", result);
        }
Esempio n. 13
0
        public void Should_expand_partial_inside_each_section_with_property_parameter_of_current_as_model()
        {
            const string input = @"<html><head></head><body>@Each;@Partial['testing', @Current.FirstName];@EndEach</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hi @Model ";

            var clark  = new PersonWithAgeField()
            {
                FirstName = "Clark",
            };

            var lois = new PersonWithAgeField()
            {
                FirstName = "Lois",
            };

            var model = new List<PersonWithAgeField>() { clark, lois };

            var result = viewEngine.Render(input, model, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Hi Clark Hi Lois </body></html>", result);
        }
        public void Should_replace_sections_in_master_page()
        {
            const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
            const string master = @"<div id='header'>@Section['Header'];</div><div id='footer'>@Section['Footer'];</div>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => master;
            var viewEngine = new SuperSimpleViewEngine();

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal("<div id='header'>\r\nHeader\r\n</div><div id='footer'>\r\nFooter\r\n</div>", result);
        }
Esempio n. 15
0
        public void Should_expand_partial_content_with_context()
        {
            const string input = @"<html><head></head><body>@Partial['testing'];</body></html>";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) => "Hello @Context.Name";

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal(@"<html><head></head><body>Hello Frank</body></html>", result);
        }
        public void Should_try_to_locate_master_page_if_one_specified()
        {
            const string input = "@Master['myMaster']\r\n@Section['Header'];\r\nHeader\r\n@EndSection\r\n@Section['Footer']\r\nFooter\r\n@EndSection";
            var called = false;
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.GetTemplateCallback = (s, m) =>
            {
                called = (s == "myMaster");
                return "";
            };
            var viewEngine = new SuperSimpleViewEngine();

            viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.True(called);
        }
        public void Should_expand_paths_in_attribute_values()
        {
            const string input = @"<script src='~/scripts/test.js'></script> <link href=""~/stylesheets/style.css"" />";
            var fakeViewEngineHost = new FakeViewEngineHost();
            fakeViewEngineHost.ExpandPathCallBack = s => s.Replace("~/", "/BasePath/");

            var result = viewEngine.Render(input, null, fakeViewEngineHost);

            Assert.Equal(@"<script src='/BasePath/scripts/test.js'></script> <link href=""/BasePath/stylesheets/style.css"" />", result);
        }