Example #1
0
        public void RegisterTest()
        {
            var keeperHelper = new MockHelper();
            var scriptKeeper = new ScriptKeeper(keeperHelper);

            scriptKeeper.Register("jQuery");
            var rendered = "<script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\"></script>";

            Assert.AreEqual(rendered, scriptKeeper.Remote.Render());
        }
Example #2
0
        public void ConstructorTest2()
        {
            var keeperHelper = new MockHelper();
            var scriptKeeper = new ScriptKeeper(keeperHelper);

            Assert.IsNotNull(scriptKeeper);
            Assert.IsNotNull(scriptKeeper.Local);
            Assert.IsNotNull(scriptKeeper.Remote);
            Assert.IsNotNull(scriptKeeper.Inline);

            Assert.AreEqual(scriptKeeper.Local.Name, "Local");
            Assert.AreEqual(scriptKeeper.Remote.Name, "Remote");
            Assert.AreEqual(scriptKeeper.Inline.Name, "Inline");

            Assert.IsTrue(object.ReferenceEquals(keeperHelper, scriptKeeper.Helper));
        }
Example #3
0
        public void ConstructorTest()
        {
            var scriptKeeper = default(ScriptKeeper);

            try
            {
                scriptKeeper = new ScriptKeeper(null);
            }
            catch (ArgumentNullException)
            {
                Assert.IsNull(scriptKeeper);
                return;
            }
            catch (Exception)
            {
                Assert.Fail("Wrong exception thrown.");
            }

            Assert.Fail("No exception thrown.");
        }
        /// <summary>
        /// Returns an instance of <c>ScriptKeeper</c> that can be used to register
        /// script files in the current context.
        /// </summary>
        /// <returns>
        /// The instance of <c>ScriptKeeper</c>.
        /// </returns>
        /// <param name='html'>
        /// The instance of <c>HtmlHelper</c> that will return a <c>ScriptKeeper</c>.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Thrown if <paramref name="html"/> is <see langword="null" /> .
        /// </exception>
        public static ScriptKeeper ScriptKeeper(this HtmlHelper html)
        {
            if (html == null)
            {
                throw new ArgumentNullException("html");
            }

            var viewContext  = html.ViewContext;
            var httpContext  = viewContext.HttpContext;
            var scriptKeeper = httpContext.Items[ScriptKeeperKey] as ScriptKeeper;

            if (scriptKeeper == null)
            {
                var keeperHelper = new RequestContextHelper(viewContext.RequestContext);

                httpContext.Items[ScriptKeeperKey] = scriptKeeper = new ScriptKeeper(keeperHelper);
            }

            return(scriptKeeper);
        }