/// <summary>
        /// Removes a unnecessary script assets
        /// </summary>
        /// <param name="assets">Set of script assets</param>
        /// <returns>Set of necessary script assets</returns>
        protected override IList <IAsset> RemoveUnnecessaryAssets(IList <IAsset> assets)
        {
            var            scriptUnnecessaryAssetsFilter = new ScriptUnnecessaryAssetsFilter(_ignorePatterns);
            IList <IAsset> processedAssets = scriptUnnecessaryAssetsFilter.Transform(assets);

            return(processedAssets);
        }
Exemplo n.º 2
0
        public void UnneededScriptAssetsRemovedIsCorrect()
        {
            // Arrange
            var virtualFileSystemWrapper = (new Mock <IVirtualFileSystemWrapper>()).Object;

            var ajaxLoginAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                              "AjaxLogin.js"), virtualFileSystemWrapper);
            var jqueryMinAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                              "jquery-1.6.2.min.js"), virtualFileSystemWrapper);
            var jqueryVsDocAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                "jquery-1.6.2-vsdoc.js"), virtualFileSystemWrapper);
            var jqueryValidateVsDocMinAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                           "jquery.validate-vsdoc.min.js"), virtualFileSystemWrapper);
            var microsoftAjaxDebugAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                       "MicrosoftAjax.debug.js"), virtualFileSystemWrapper);
            var telerikAllMinAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                  "telerik.all.min.js"), virtualFileSystemWrapper);
            var knockoutAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                             "knockout-2.0.0.js"), virtualFileSystemWrapper);
            var modernizrAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                              "modernizr-2.0.6-development-only.js"), virtualFileSystemWrapper);
            var referencesAsset = new Asset(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                               "_references.js"), virtualFileSystemWrapper);

            var assets = new List <IAsset>
            {
                ajaxLoginAsset,
                jqueryMinAsset,
                jqueryVsDocAsset,
                jqueryValidateVsDocMinAsset,
                microsoftAjaxDebugAsset,
                telerikAllMinAsset,
                knockoutAsset,
                modernizrAsset,
                referencesAsset
            };

            var scriptUnnecessaryAssetsFilter = new ScriptUnnecessaryAssetsFilter(
                new[] { "*-vsdoc.js", "*.all.js", "_references.js" });

            // Act
            IList <IAsset> processedAssets = scriptUnnecessaryAssetsFilter.Transform(assets).ToList();

            // Assert
            Assert.Equal(5, processedAssets.Count);
            Assert.Equal(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH, "AjaxLogin.js"),
                         processedAssets[0].VirtualPath);
            Assert.Equal(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH, "jquery-1.6.2.min.js"),
                         processedAssets[1].VirtualPath);
            Assert.Equal(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH, "MicrosoftAjax.debug.js"),
                         processedAssets[2].VirtualPath);
            Assert.Equal(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH, "knockout-2.0.0.js"),
                         processedAssets[3].VirtualPath);
            Assert.Equal(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                            "modernizr-2.0.6-development-only.js"), processedAssets[4].VirtualPath);
        }
Exemplo n.º 3
0
        public void FirstInvalidIgnorePatternProcessedIsCorrect()
        {
            // Arrange
            Exception currentException = null;

            // Act
            try
            {
                var scriptUnnecessaryAssetsFilter = new ScriptUnnecessaryAssetsFilter(new[] { "*", "_references.js" });
            }
            catch (Exception ex)
            {
                currentException = ex;
            }

            // Assert
            Assert.NotNull(currentException);
            Assert.IsType <ArgumentException>(currentException);
            Assert.Equal("ignorePatterns", ((ArgumentException)currentException).ParamName);
        }
        public void SecondInvalidIgnorePatternProcessedIsCorrect()
        {
            // Arrange
            Exception currentException = null;

            // Act
            try
            {
                var scriptUnnecessaryAssetsFilter = new ScriptUnnecessaryAssetsFilter(new[] { "*-vsdoc.js", "*.*", "*.all.js" });
            }
            catch (Exception ex)
            {
                currentException = ex;
            }

            // Assert
            Assert.NotNull(currentException);
            Assert.IsType <ArgumentException>(currentException);
            Assert.Equal(((ArgumentException)currentException).ParamName, "ignorePatterns");
        }
		/// <summary>
		/// Removes a unnecessary script assets
		/// </summary>
		/// <param name="assets">Set of script assets</param>
		/// <returns>Set of necessary script assets</returns>
		protected override IList<IAsset> RemoveUnnecessaryAssets(IList<IAsset> assets)
		{
			var scriptUnnecessaryAssetsFilter = new ScriptUnnecessaryAssetsFilter(_ignorePatterns);
			IList<IAsset> processedAssets = scriptUnnecessaryAssetsFilter.Transform(assets);

			return processedAssets;
		}