コード例 #1
0
ファイル: BundleConfig.cs プロジェクト: kenlinj/Easymish
        static void AddBundle(BundleCollection bundles, string bundlePath, string scriptPath)
        {
            bool isJavascript = scriptPath.EndsWith(".js");
            var resolver = new BundleResolver(bundles);

            if (bundles.Any(b => b.Path == bundlePath))
            {
                var bundle = bundles.First(b => b.Path == bundlePath);
                var contents = resolver.GetBundleContents(bundle.Path);

                if (!contents.Any(s => s == scriptPath))
                {
                    //if bundle already exists, include the script path
                    bundle.Include(scriptPath);
                }
            }
            else
            {
                //if bundle not exists, create the bundle and include the script path
                if (isJavascript)
                {
                    bundles.Add(new ScriptBundle(bundlePath).Include(scriptPath));
                }
                else
                {
                    bundles.Add(new StyleBundle(bundlePath).Include(scriptPath, new CssRewriteUrlTransform()));
                }
            }
        }
コード例 #2
0
        public void GivenAssetExists_WhenProcessRequest_ThenResponseContentTypeIsBundleContentType()
        {
            bundles.Add(new TestableBundle("~/test")
            {
                ContentType = "CONTENT/TYPE"
            });
            var asset = new Mock <IAsset>();

            asset.Setup(a => a.Accept(It.IsAny <IBundleVisitor>()))
            .Callback <IBundleVisitor>(v => v.Visit(asset.Object));
            asset.SetupGet(a => a.Path)
            .Returns("~/test/asset.js");
            asset.Setup(a => a.OpenStream())
            .Returns(Stream.Null);
            bundles.First().Assets.Add(asset.Object);

            using (outputStream = new MemoryStream())
            {
                handler.ProcessRequest("~/test/asset.js");
            }

            response.VerifySet(r => r.ContentType = "CONTENT/TYPE");
        }
コード例 #3
0
        public void GivenAssetExists_WhenProcessRequest_ThenMaxAgeIsSetToAYear()
        {
            bundles.Add(new TestableBundle("~/test")
            {
                ContentType = "CONTENT/TYPE"
            });
            var asset = new Mock <IAsset>();

            asset.Setup(a => a.Accept(It.IsAny <IBundleVisitor>()))
            .Callback <IBundleVisitor>(v => v.Visit(asset.Object));
            asset.SetupGet(a => a.Path)
            .Returns("~/test/asset.js");
            asset.Setup(a => a.OpenStream())
            .Returns(Stream.Null);
            bundles.First().Assets.Add(asset.Object);

            using (outputStream = new MemoryStream())
            {
                handler.ProcessRequest("~/test/asset.js");
            }

            cache.Verify(c => c.SetCacheability(HttpCacheability.Public));
            cache.Verify(c => c.SetMaxAge(It.Is <TimeSpan>(t => t.Days == 365)));
        }
コード例 #4
0
ファイル: BundleConfig.cs プロジェクト: kenlinj/Easymish
        static void AddBundle(BundleCollection bundles, string bundlePath, string scriptPath)
        {
            bool isJavascript = scriptPath.EndsWith(".js");

            if (bundles.Any(b => b.Path == bundlePath))
            {
                bundles.First(b => b.Path == bundlePath).Include(scriptPath);
            }
            else
            {
                if (isJavascript)
                {
                    bundles.Add(new ScriptBundle(bundlePath).Include(scriptPath));
                }
                else
                {
                    bundles.Add(new StyleBundle(bundlePath).Include(scriptPath, new CssRewriteUrlTransform()));
                }
            }
        }