コード例 #1
0
        public void BreakUpMixedRazorBlocks()
        {
            var obj = new JsBlockContentEvaluator();

            var data = new[]
            {
                "<html>",
                "<head>",
                "</head>",
                "<body>",
                "<script type='text/javascript'>",
                "   $(function(){",
                "       alert('I am a script without any at variables);",
                "   });",
                "</script>",
                "<script type='text/javascript'>",
                "   $(function(){",
                "       alert('I am a script with an @Viewmodel.Variable);",
                "   });",
                "</script>",
                "</body>",
                "</html>",
            };
            var result = obj.Evaluate(data, JsPageEvaluationMode.RazorOnly);

            Assert.AreEqual(1, result.Length);
            Assert.AreEqual(5, result[0].Lines.Count);
        }
コード例 #2
0
        public void EnsureJsPageEvaluatorRespectsMode()
        {
            var obj = new JsBlockContentEvaluator();

            var data = new[]
            {
                "<html>",
                "<head>",
                "</head>",
                "<body>",
                "<script type='text/javascript'>",
                "   $(function(){",
                "       alert('I am a script without any at variables);",
                "   });",
                "</script>",
                "<!-- some text-->", //TODO: Consider how to treat "joined" blocks.
                "<script type='text/javascript'>",
                "   $(function(){",
                "       alert('I am a script with an @Viewmodel.Variable);",
                "   });",
                "</script>",
                "</body>",
                "</html>",
            };

            var result = obj.Evaluate(data, JsPageEvaluationMode.RazorOnly);

            Assert.AreEqual(1, result.Length);
        }
コード例 #3
0
        public JavaScriptEvaluationResult Evaluate(string filename, string[] contents, List <string> attributes, bool mergeBlocks)
        {
            var joinedString = string.Join("", contents);

            if ((!joinedString.Contains("script", StringComparison.OrdinalIgnoreCase) && attributes.Any(x => joinedString.Contains(x, StringComparison.OrdinalIgnoreCase))))
            {
                return(null);
            }

            var pageLevel  = JsBlockContentEvaluator.Evaluate(contents, PageEvaluationMode.Any, mergeBlocks);
            var references = JsReferencesEvaluator.Evaluate(joinedString);
            var block      = JsBlockEvaluator.Evaluate(joinedString, attributes);
            var razor      = JsRazorEvaluator.Evaluate(joinedString, attributes);

            if (pageLevel.Any() || references > 0 || block.Any() || razor.Any())
            {
                return(new JavaScriptEvaluationResult
                {
                    FileName = filename,
                    PageInstances = pageLevel,
                    References = references,
                    Block = block,
                    Razor = razor,
                });
            }

            return(null);
        }
コード例 #4
0
        public void Page()
        {
            var raw = AssetRetriever.GetFileAndContent(AvailableTestingResources.TestingResource);

            var evaluator = new JsBlockContentEvaluator(new RemediatedBlockJsRemover());

            var result = evaluator.Evaluate(raw.Contents, PageEvaluationMode.Any, true);

            Assert.AreEqual(2, result.Length);
        }