Пример #1
0
        public void ProcessScriptBlocksVBTest()
        {
            var pageType = new CodeTypeDeclaration("MyControl");
            var snippet  = new CodeSnippetTypeMember("public foo as int");

            pageType.Members.Add(snippet);
            var renderMethod = new CodeMemberMethod();

            WebPageSurrogateControlBuilder.ProcessScriptBlocks(pageType, renderMethod, Language.VisualBasic);
            var snippets = renderMethod.Statements.OfType <CodeSnippetStatement>().ToList();

            Assert.AreEqual(1, snippets.Count);
            var snip = snippets[0];

            Assert.IsTrue(snip.Value.Contains("Public Module MyControlExtensions"));
            Assert.IsTrue(snip.Value.Contains("Public Function MyControl(htmlHelper As System.Web.Mvc.HtmlHelper, optional foo as int = Nothing) As HelperResult"));
            Assert.IsTrue(snip.Value.Contains("uc.foo = foo"));
        }
Пример #2
0
        public void ProcessScriptBlocksCSTest()
        {
            var pageType = new CodeTypeDeclaration("MyControl");
            var snippet  = new CodeSnippetTypeMember("public int foo;");

            pageType.Members.Add(snippet);
            var renderMethod = new CodeMemberMethod();

            WebPageSurrogateControlBuilder.ProcessScriptBlocks(pageType, renderMethod, Language.CSharp);
            var snippets = renderMethod.Statements.OfType <CodeSnippetStatement>().ToList();

            Assert.AreEqual(1, snippets.Count);
            var snip = snippets[0];

            Assert.IsTrue(snip.Value.Contains("public static class MyControlExtensions"));
            Assert.IsTrue(snip.Value.Contains("public static HelperResult MyControl(this System.Web.Mvc.HtmlHelper htmlHelper, int foo = default(int))"));
            Assert.IsTrue(snip.Value.Contains("uc.foo = foo;"));
        }