Beispiel #1
0
 protected CssHttpHandlerBase(
     Cache cache,
     IVirtualFileSystemWrapper virtualFileSystemWrapper,
     AssetHandlerSettings assetHandlerConfig)
     : base(cache, virtualFileSystemWrapper, assetHandlerConfig)
 {
 }
Beispiel #2
0
 /// <summary>
 /// Constructs a instance of Asset
 /// </summary>
 /// <param name="virtualPath">Virtual path to asset file</param>
 /// <param name="bundleFile">Bundle file</param>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 public Asset(string virtualPath, BundleFile bundleFile,
              IVirtualFileSystemWrapper virtualFileSystemWrapper)
     : this(virtualPath, bundleFile, virtualFileSystemWrapper,
            BundleTransformerContext.Current.Styles.FileExtensionMappings,
            BundleTransformerContext.Current.Scripts.FileExtensionMappings)
 {
 }
        /// <summary>
        /// Constructs a instance of JS file extensions filter
        /// </summary>
        /// <param name="jsFilesWithMsStyleExtensions">JS files with Microsoft-style extensions list</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        public JsFileExtensionsFilter(string[] jsFilesWithMsStyleExtensions,
                                      IVirtualFileSystemWrapper virtualFileSystemWrapper) : base(virtualFileSystemWrapper)
        {
            var jsFileRegExps = new List <Regex>();

            if (jsFilesWithMsStyleExtensions.Length > 0)
            {
                string versionNumberPlaceholder = VERSION_NUMBER_PLACEHOLDER.Replace("$", @"\$");

                foreach (var jsFileName in jsFilesWithMsStyleExtensions)
                {
                    if (!string.IsNullOrWhiteSpace(jsFileName))
                    {
                        string jsFileNamePattern = Regex.Escape(jsFileName.Trim());

                        if (jsFileNamePattern.IndexOf(versionNumberPlaceholder,
                                                      StringComparison.OrdinalIgnoreCase) != -1)
                        {
                            jsFileNamePattern = jsFileNamePattern.Replace(versionNumberPlaceholder,
                                                                          @"(?:\d+\.)*\d+(?:(?:alpha|beta|rc)\d{0,1})?");
                        }
                        jsFileNamePattern = "^" + jsFileNamePattern + "$";

                        jsFileRegExps.Add(new Regex(jsFileNamePattern, RegexOptions.IgnoreCase));
                    }
                }
            }

            _jsFilesWithMsStyleExtensionsRegExps = jsFileRegExps;
        }
		/// <summary>
		/// Constructs a instance of JS-file extensions filter
		/// </summary>
		/// <param name="jsFilesWithMsStyleExtensions">JS-files with Microsoft-style extensions list</param>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		public JsFileExtensionsFilter(string[] jsFilesWithMsStyleExtensions,
			IVirtualFileSystemWrapper virtualFileSystemWrapper) : base(virtualFileSystemWrapper)
		{
			var jsFileRegExps = new List<Regex>();
			if (jsFilesWithMsStyleExtensions.Length > 0)
			{
				string versionNumberPlaceholder = VERSION_NUMBER_PLACEHOLDER.Replace("$", @"\$");

				foreach (var jsFileName in jsFilesWithMsStyleExtensions)
				{
					if (!string.IsNullOrWhiteSpace(jsFileName))
					{
						string jsFileNamePattern = Regex.Escape(jsFileName.Trim());

						if (jsFileNamePattern.IndexOf(versionNumberPlaceholder,
							StringComparison.OrdinalIgnoreCase) != -1)
						{
							jsFileNamePattern = jsFileNamePattern.Replace(versionNumberPlaceholder,
								@"(?:\d+\.)*\d+(?:(?:alpha|beta|rc)\d{0,1})?");
						}
						jsFileNamePattern = "^" + jsFileNamePattern + "$";

						jsFileRegExps.Add(new Regex(jsFileNamePattern, RegexOptions.IgnoreCase));
					}
				}
			}

			_jsFilesWithMsStyleExtensionsRegExps = jsFileRegExps;
		}
 /// <summary>
 /// Constructs a instance of the debugging CSS HTTP handler
 /// </summary>
 /// <param name="cache">Server cache</param>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 /// <param name="assetHandlerConfig">Configuration settings of the debugging HTTP handler</param>
 public CssAssetHandler(
     Cache cache,
     IVirtualFileSystemWrapper virtualFileSystemWrapper,
     AssetHandlerSettings assetHandlerConfig)
     : base(cache, virtualFileSystemWrapper, assetHandlerConfig)
 {
 }
Beispiel #6
0
        /// <summary>
        /// Constructs a instance of Asset
        /// </summary>
        /// <param name="virtualPath">Virtual path to asset file</param>
        /// <param name="bundleFile">Bundle file</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="styleFileExtensionMappings">Style file extension mappings</param>
        /// <param name="scriptFileExtensionMappings">Script file extension mappings</param>
        public Asset(string virtualPath, BundleFile bundleFile,
                     IVirtualFileSystemWrapper virtualFileSystemWrapper,
                     FileExtensionMappingCollection styleFileExtensionMappings,
                     FileExtensionMappingCollection scriptFileExtensionMappings)
        {
            _virtualFileSystemWrapper    = virtualFileSystemWrapper;
            _styleFileExtensionMappings  = styleFileExtensionMappings;
            _scriptFileExtensionMappings = scriptFileExtensionMappings;
            if (bundleFile != null)
            {
                _includedVirtualPath = bundleFile.IncludedVirtualPath;
                _transforms          = bundleFile.Transforms;
            }
            else
            {
                _includedVirtualPath = string.Empty;
                _transforms          = new List <IItemTransform>();
            }
            _assetTypeCode = Constants.AssetTypeCode.Unknown;
            _isStylesheet  = false;
            _isScript      = false;
            _content       = null;

            VirtualPath             = virtualPath;
            VirtualPathDependencies = new List <string>();
            OriginalAssets          = new List <IAsset>();
            Combined = false;
            Minified = false;
            RelativePathsResolved = false;
        }
Beispiel #7
0
        /// <summary>Constructs a instance of JS file extensions filter</summary>
        /// <param name="jsFilesWithMsStyleExtensions">JS files with Microsoft-style extensions list</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        public JsFileExtensionsFilter(
            string[] jsFilesWithMsStyleExtensions,
            IVirtualFileSystemWrapper virtualFileSystemWrapper)
            : base(virtualFileSystemWrapper)
        {
            List <Regex> regexList = new List <Regex>();

            if (jsFilesWithMsStyleExtensions.Length != 0)
            {
                string oldValue = "$version$".Replace("$", "\\$");
                foreach (string msStyleExtension in jsFilesWithMsStyleExtensions)
                {
                    if (!string.IsNullOrWhiteSpace(msStyleExtension))
                    {
                        string str = Regex.Escape(msStyleExtension.Trim());
                        if (str.IndexOf(oldValue, StringComparison.OrdinalIgnoreCase) != -1)
                        {
                            str = str.Replace(oldValue, "(?:\\d+\\.)*\\d+(?:(?:alpha|beta|rc)\\d{0,1})?");
                        }
                        string pattern = "^" + str + "$";
                        regexList.Add(new Regex(pattern, RegexOptions.IgnoreCase));
                    }
                }
            }
            this._jsFilesWithMsStyleExtensionsRegExps = regexList;
        }
        public LessCssHttpHandler(
            Cache cache,
            IVirtualFileSystemWrapper virtualFileSystemWrapper,
            AssetHandlerSettings assetHandlerConfig)
            : base(cache, virtualFileSystemWrapper, assetHandlerConfig)
        {
		}
Beispiel #9
0
 public LessCssHttpHandler(
     Cache cache,
     IVirtualFileSystemWrapper virtualFileSystemWrapper,
     AssetHandlerSettings assetHandlerConfig)
     : base(cache, virtualFileSystemWrapper, assetHandlerConfig)
 {
     var session = HttpContext.Current.Session;
 }
Beispiel #10
0
 /// <summary>
 /// Constructs a instance of the debugging HTTP handler
 /// </summary>
 /// <param name="cache">Server cache</param>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 /// <param name="assetHandlerConfig">Configuration settings of the debugging HTTP handler</param>
 protected AssetHandlerBase(Cache cache,
                            IVirtualFileSystemWrapper virtualFileSystemWrapper,
                            AssetHandlerSettings assetHandlerConfig)
 {
     _cache = cache;
     _virtualFileSystemWrapper = virtualFileSystemWrapper;
     _assetHandlerConfig       = assetHandlerConfig;
 }
Beispiel #11
0
 /// <summary>
 /// Constructs a instance of CSS autoprefixer
 /// </summary>
 /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 /// <param name="options">Autoprefixing options</param>
 public CssAutoprefixer(Func <IJsEngine> createJsEngineInstance,
                        IVirtualFileSystemWrapper virtualFileSystemWrapper,
                        AutoprefixingOptions options)
 {
     _jsEngine = createJsEngineInstance();
     _virtualFileSystemWrapper = virtualFileSystemWrapper;
     _options       = options ?? new AutoprefixingOptions();
     _optionsString = ConvertAutoprefixingOptionsToJson(_options).ToString();
 }
		/// <summary>
		/// Constructs a instance of Closure Remote JS-minifier
		/// </summary>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		/// <param name="closureConfig">Configuration settings of Closure Minifier</param>
		public ClosureRemoteJsMinifier(IVirtualFileSystemWrapper virtualFileSystemWrapper,
			ClosureSettings closureConfig)
			: base(virtualFileSystemWrapper, closureConfig)
		{
			RemoteJsMinifierSettings remoteJsMinifierConfig = closureConfig.Js.Remote;
			MapCommonSettings(this, remoteJsMinifierConfig);
			ClosureCompilerServiceApiUrl = remoteJsMinifierConfig.ClosureCompilerServiceApiUrl;
			ExcludeDefaultExterns = remoteJsMinifierConfig.ExcludeDefaultExterns;
			Language = remoteJsMinifierConfig.Language;
		}
Beispiel #13
0
        /// <summary>
        /// Constructs a instance of Closure Local JS minifier
        /// </summary>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="closureConfig">Configuration settings of Closure Minifier</param>
        /// <param name="tempFilesDirectoryPath">Absolute path to directory that contains temporary files</param>
        public ClosureLocalJsMinifier(IVirtualFileSystemWrapper virtualFileSystemWrapper,
                                      ClosureSettings closureConfig,
                                      string tempFilesDirectoryPath)
            : base(virtualFileSystemWrapper, closureConfig)
        {
            _tempFilesDirectoryPath = tempFilesDirectoryPath;

            LocalJsMinifierSettings localJsMinifierConfig = closureConfig.Js.Local;

            MapCommonSettings(this, localJsMinifierConfig);
            AcceptConstKeyword             = localJsMinifierConfig.AcceptConstKeyword;
            AllowEs6Output                 = localJsMinifierConfig.AllowEs6Output;
            AngularPass                    = localJsMinifierConfig.AngularPass;
            ClosureCompilerApplicationPath = localJsMinifierConfig.ClosureCompilerApplicationPath;
            DefinitionList                 = localJsMinifierConfig.DefinitionList;
            ErrorList = localJsMinifierConfig.ErrorList;
            ExportLocalPropertyDefinitions = localJsMinifierConfig.ExportLocalPropertyDefinitions;
            ExtraAnnotationNameList        = localJsMinifierConfig.ExtraAnnotationNameList;
            GenerateExports          = localJsMinifierConfig.GenerateExports;
            JavaVirtualMachinePath   = localJsMinifierConfig.JavaVirtualMachinePath;
            LanguageInput            = localJsMinifierConfig.LanguageInput;
            LanguageOutput           = localJsMinifierConfig.LanguageOutput;
            ProcessClosurePrimitives = localJsMinifierConfig.ProcessClosurePrimitives;
            ProcessJqueryPrimitives  = localJsMinifierConfig.ProcessJqueryPrimitives;
            SingleQuotes             = localJsMinifierConfig.SingleQuotes;
            ThirdParty              = localJsMinifierConfig.ThirdParty;
            TranspileOnly           = localJsMinifierConfig.TranspileOnly;
            TurnOffWarningClassList = localJsMinifierConfig.TurnOffWarningClassList;
            UseOnlyCustomExterns    = localJsMinifierConfig.UseOnlyCustomExterns;
            WarningList             = localJsMinifierConfig.WarningList;

            string javaVirtualMachinePath = JavaVirtualMachinePath;

            if (string.IsNullOrWhiteSpace(javaVirtualMachinePath))
            {
                throw new EmptyValueException(Strings.Minifiers_JavaVirtualMachinePathNotSpecified);
            }
            if (!File.Exists(javaVirtualMachinePath))
            {
                throw new FileNotFoundException(
                          string.Format(Strings.Minifiers_JavaVirtualMachineNotFound, javaVirtualMachinePath));
            }

            string closureCompilerApplicationPath = ClosureCompilerApplicationPath;

            if (string.IsNullOrWhiteSpace(closureCompilerApplicationPath))
            {
                throw new EmptyValueException(Strings.Minifiers_ClosureCompilerApplicationPathNotSpecified);
            }
            if (!File.Exists(closureCompilerApplicationPath))
            {
                throw new FileNotFoundException(
                          string.Format(Strings.Minifiers_ClosureCompilerApplicationNotFound, closureCompilerApplicationPath));
            }
        }
        /// <summary>
        /// Constructs a instance of Closure Remote JS minifier
        /// </summary>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="closureConfig">Configuration settings of Closure Minifier</param>
        public ClosureRemoteJsMinifier(IVirtualFileSystemWrapper virtualFileSystemWrapper,
                                       ClosureSettings closureConfig)
            : base(virtualFileSystemWrapper, closureConfig)
        {
            RemoteJsMinifierSettings remoteJsMinifierConfig = closureConfig.Js.Remote;

            MapCommonSettings(this, remoteJsMinifierConfig);
            ClosureCompilerServiceApiUrl = remoteJsMinifierConfig.ClosureCompilerServiceApiUrl;
            ExcludeDefaultExterns        = remoteJsMinifierConfig.ExcludeDefaultExterns;
            Language = remoteJsMinifierConfig.Language;
        }
        /// <summary>
        /// Constructs a instance of Sass- and SCSS-translator
        /// </summary>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="sassAndScssConfig">Configuration settings of Sass- and SCSS-translator</param>
        public SassAndScssTranslator(IVirtualFileSystemWrapper virtualFileSystemWrapper,
            SassAndScssSettings sassAndScssConfig)
        {
            _fileManager = new SassFileManager(virtualFileSystemWrapper);

            UseNativeMinification = sassAndScssConfig.UseNativeMinification;
            IndentType = sassAndScssConfig.IndentType;
            IndentWidth = sassAndScssConfig.IndentWidth;
            LineFeedType = sassAndScssConfig.LineFeedType;
            Precision = sassAndScssConfig.Precision;
            SourceComments = sassAndScssConfig.SourceComments;
        }
Beispiel #16
0
        /// <summary>
        /// Destroys object
        /// </summary>
        public void Dispose()
        {
            if (_disposedFlag.Set())
            {
                if (_jsEngine != null)
                {
                    _jsEngine.RemoveVariable(COUNTRY_STATISTICS_SERVICE_VARIABLE_NAME);

                    _jsEngine.Dispose();
                    _jsEngine = null;
                }

                _virtualFileSystemWrapper = null;
            }
        }
Beispiel #17
0
        /// <summary>
        /// Sets a virtual file system wrapper
        /// </summary>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        public static void SetVirtualFileSystemWrapper(IVirtualFileSystemWrapper virtualFileSystemWrapper)
        {
            if (virtualFileSystemWrapper == null)
            {
                throw new ArgumentNullException("virtualFileSystemWrapper",
                                                string.Format(CoreStrings.Common_ArgumentIsNull, "virtualFileSystemWrapper"));
            }

            IFileManager virtualFileManager = new VirtualFileManager(virtualFileSystemWrapper);

            lock (_initializationSynchronizer)
            {
                SassCompiler.FileManager = virtualFileManager;
                _initialized             = true;
            }
        }
        /// <summary>
        /// Initializes a Sass compiler
        /// </summary>
        private static void Initialize()
        {
            if (!_initialized)
            {
                lock (_initializationSynchronizer)
                {
                    if (!_initialized)
                    {
                        IVirtualFileSystemWrapper virtualFileSystemWrapper =
                            BundleTransformerContext.Current.FileSystem.GetVirtualFileSystemWrapper();
                        IFileManager virtualFileManager = new VirtualFileManager(virtualFileSystemWrapper);

                        SassCompiler.FileManager = virtualFileManager;
                        _initialized             = true;
                    }
                }
            }
        }
        /// <summary>
        /// Constructs a instance of LESS translator
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="lessConfig">Configuration settings of LESS translator</param>
        public LessTranslator(Func <IJsEngine> createJsEngineInstance,
                              IVirtualFileSystemWrapper virtualFileSystemWrapper,
                              LessSettings lessConfig)
        {
            _virtualFileManager = new VirtualFileManager(virtualFileSystemWrapper);

            UseNativeMinification = lessConfig.UseNativeMinification;
            IncludePaths          = lessConfig.IncludePaths
                                    .Cast <IncludedPathRegistration>()
                                    .Select(p => p.Path)
                                    .ToList()
            ;
            IeCompat          = lessConfig.IeCompat;
            Math              = lessConfig.Math;
            StrictUnits       = lessConfig.StrictUnits;
            DumpLineNumbers   = lessConfig.DumpLineNumbers;
            JavascriptEnabled = lessConfig.JavascriptEnabled;
            GlobalVariables   = lessConfig.GlobalVariables;
            ModifyVariables   = lessConfig.ModifyVariables;
            Severity          = lessConfig.Severity;

            if (createJsEngineInstance == null)
            {
                string jsEngineName = lessConfig.JsEngine.Name;
                if (string.IsNullOrWhiteSpace(jsEngineName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
                                            "less",
                                            @"
  * JavaScriptEngineSwitcher.Msie
  * JavaScriptEngineSwitcher.V8
  * JavaScriptEngineSwitcher.ChakraCore",
                                            "MsieJsEngine")
                              );
                }

                createJsEngineInstance = () => JsEngineSwitcher.Current.CreateEngine(jsEngineName);
            }
            _createJsEngineInstance = createJsEngineInstance;
        }
        /// <summary>
        /// Constructs a instance of Closure JS minifier
        /// </summary>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="closureConfig">Configuration settings of Closure Minifier</param>
        protected ClosureJsMinifierBase(IVirtualFileSystemWrapper virtualFileSystemWrapper,
                                        ClosureSettings closureConfig)
        {
            _virtualFileSystemWrapper = virtualFileSystemWrapper;

            CommonExternsFilePaths = closureConfig.Js.CommonExternsFiles
                                     .Cast <CommonJsExternsFileRegistration>()
                                     .Select(f => f.ExternsFilePath)
                                     .ToList()
            ;
            ExternsFileMappings = closureConfig.Js.ExternMappings
                                  .Cast <JsExternsFileMappingRegistration>()
                                  .Select(m =>
                                          new JsExternsFileMapping(m.ScriptFilePath,
                                                                   Utils.ConvertToStringCollection(m.ExternsFilePaths, ',',
                                                                                                   trimItemValues: true, removeEmptyItems: true).ToList()
                                                                   )
                                          )
                                  .ToList()
            ;
        }
        /// <summary>
        /// Constructs a instance of Andrey Sitnik's Autoprefix CSS postprocessor
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="autoprefixerConfig">Configuration settings of Andrey Sitnik's Autoprefix CSS postprocessor</param>
        public AutoprefixCssPostProcessor(Func <IJsEngine> createJsEngineInstance,
                                          IVirtualFileSystemWrapper virtualFileSystemWrapper,
                                          AutoprefixerSettings autoprefixerConfig)
        {
            _virtualFileSystemWrapper = virtualFileSystemWrapper;

            Browsers = autoprefixerConfig.Browsers
                       .Cast <BrowserConditionalExpression>()
                       .Select(b => b.ConditionalExpression)
                       .ToList()
            ;
            Cascade  = autoprefixerConfig.Cascade;
            Add      = autoprefixerConfig.Add;
            Remove   = autoprefixerConfig.Remove;
            Supports = autoprefixerConfig.Supports;
            Flexbox  = autoprefixerConfig.Flexbox;
            Grid     = autoprefixerConfig.Grid;
            IgnoreUnknownVersions = autoprefixerConfig.IgnoreUnknownVersions;
            Stats = autoprefixerConfig.Stats;

            if (createJsEngineInstance == null)
            {
                string jsEngineName = autoprefixerConfig.JsEngine.Name;
                if (string.IsNullOrWhiteSpace(jsEngineName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
                                            "autoprefixer",
                                            @"
  * JavaScriptEngineSwitcher.Msie (only in the Chakra JsRT modes)
  * JavaScriptEngineSwitcher.V8
  * JavaScriptEngineSwitcher.ChakraCore (while it is recommended to use version 3.1.1)",
                                            "MsieJsEngine")
                              );
                }

                createJsEngineInstance = () => JsEngineSwitcher.Current.CreateEngine(jsEngineName);
            }
            _createJsEngineInstance = createJsEngineInstance;
        }
        public CssFileExtensionsFilterTests()
        {
            var virtualFileSystemMock = new Mock <IVirtualFileSystemWrapper>();

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "Site.css")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "Site.min.css")))
            .Returns(false)
            ;

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                          @"themes\base\jquery.ui.accordion.css")))
            .Returns(false)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                          @"themes\base\jquery.ui.accordion.min.css")))
            .Returns(true)
            ;

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(ALTERNATIVE_STYLES_DIRECTORY_VIRTUAL_PATH,
                                                          @"css\TestCssComponentsPaths.css")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(ALTERNATIVE_STYLES_DIRECTORY_VIRTUAL_PATH,
                                                          @"css\TestCssComponentsPaths.min.css")))
            .Returns(true)
            ;

            _virtualFileSystemWrapper = virtualFileSystemMock.Object;
        }
        public void FillingOfDependenciesIsCorrect()
        {
            // Arrange
            var virtualFileSystemMock = new Mock <IVirtualFileSystemWrapper>();

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath("~/"))
            .Returns("/")
            ;


            string testTypeScriptTsAssetVirtualPath = UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                         "TestTypeScript.ts");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(testTypeScriptTsAssetVirtualPath))
            .Returns(testTypeScriptTsAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(testTypeScriptTsAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(testTypeScriptTsAssetVirtualPath))
            .Returns(@"/// <reference path=""ColoredTranslatorBadge.ts"" />

module TranslatorBadges {
	var TS_BADGE_TEXT: string = ""TypeScript"";
	var TS_BADGE_COLOR: string = ""#0074C1"";

	export function createTsTranslatorBadge() {
		var tsBadge: IColoredTranslatorBadge = new ColoredTranslatorBadge(""ts"");
		tsBadge.setText(TS_BADGE_TEXT);
		tsBadge.setTextColor(TS_BADGE_COLOR);
		tsBadge.setBorderColor(TS_BADGE_COLOR);
		tsBadge.show();
	}
}

TranslatorBadges.createTsTranslatorBadge();")
            ;


            string jqueryTsAssetVirtualPath = UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                 "jquery.d.ts");

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(jqueryTsAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(jqueryTsAssetVirtualPath))
            .Returns(Utils.GetResourceAsString("BundleTransformer.Tests.Resources.jquery.d.ts", GetType().Assembly))
            ;


            string iTranslatorBadgeTsAssetVirtualPath = UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                           "ITranslatorBadge.d.ts");

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(iTranslatorBadgeTsAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(iTranslatorBadgeTsAssetVirtualPath))
            .Returns(@"interface ITranslatorBadge {
	getText(): string;
	setText(text: string): void;
	show(): void;
	hide(): void;
	isVisible(): boolean;
}")
            ;


            string translatorBadgeTsAssetVirtualPath = UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                          "TranslatorBadge.ts");

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(translatorBadgeTsAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(translatorBadgeTsAssetVirtualPath))
            .Returns(@"/// <reference path=""jquery.d.ts"" />
/// <reference path=""ITranslatorBadge.d.ts"" />

module TranslatorBadges {
	export class TranslatorBadge implements ITranslatorBadge {
		$badgeElem: JQuery;
		$linkElem: JQuery;

		constructor (public elementId: string) {
			this.$badgeElem = jQuery(""#"" + elementId);
			this.$linkElem = this.$badgeElem.find(""A:first"");
		}

		public getText(): string {
			return this.$linkElem.text();
		}

		public setText(text: string): void {
			this.$linkElem.text(text);
		}

		public show(): void {
			this.$badgeElem.show(0);
		}

		public hide(): void {
			this.$badgeElem.hide(0);
		}

		public isVisible() : boolean {
			return this.$badgeElem.is("":visible"");
		}
	}
}")
            ;


            string iColoredTranslatorBadgeTsAssetVirtualPath = UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                                  "IColoredTranslatorBadge.d.ts");

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(iColoredTranslatorBadgeTsAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(iColoredTranslatorBadgeTsAssetVirtualPath))
            .Returns(@"/// <reference path=""ITranslatorBadge.d.ts"" />

interface IColoredTranslatorBadge extends ITranslatorBadge {
	getTextColor(): string;
	setTextColor(color: string): void;
	getBorderColor(): string;
	setBorderColor(color: string): void;
}")
            ;


            string coloredTranslatorBadgeTsAssetVirtualPath = UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                                                 "ColoredTranslatorBadge.ts");

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(coloredTranslatorBadgeTsAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(coloredTranslatorBadgeTsAssetVirtualPath))
            .Returns(@"/// <reference path=""jquery.d.ts"" />
/// <reference path=""./IColoredTranslatorBadge.d.ts"" />
/// <reference path=""TranslatorBadge.ts"" />

module TranslatorBadges {
	export class ColoredTranslatorBadge
		extends TranslatorBadge
	{
		public getTextColor(): string {
			return this.$linkElem.css(""color"");
		}

		public setTextColor(color: string): void {
			this.$linkElem.css(""color"", color);
		}

		public getBorderColor(): string {
			return this.$badgeElem.css(""border-color"");
		}

		public setBorderColor(color: string): void {
			this.$badgeElem.css(""border-color"", color);
		}
	}
}")
            ;

            Func <IJsEngine> createJsEngineInstance =
                () => JsEngineSwitcher.Current.CreateDefaultEngine();
            IVirtualFileSystemWrapper virtualFileSystemWrapper = virtualFileSystemMock.Object;
            var tsConfig = new TypeScriptSettings();

            var tsTranslator = new TypeScriptTranslator(createJsEngineInstance, virtualFileSystemWrapper,
                                                        tsConfig);
            IAsset asset = new Asset(testTypeScriptTsAssetVirtualPath, virtualFileSystemWrapper);

            // Act
            asset = tsTranslator.Translate(asset);
            IList <string> dependencies = asset.VirtualPathDependencies;

            // Assert
            Assert.Equal(5, dependencies.Count);

            Assert.Equal(coloredTranslatorBadgeTsAssetVirtualPath, dependencies[0]);
            Assert.Equal(jqueryTsAssetVirtualPath, dependencies[1]);
            Assert.Equal(iColoredTranslatorBadgeTsAssetVirtualPath, dependencies[2]);
            Assert.Equal(iTranslatorBadgeTsAssetVirtualPath, dependencies[3]);
            Assert.Equal(translatorBadgeTsAssetVirtualPath, dependencies[4]);
        }
        public void SetUp()
        {
            var virtualFileSystemMock = new Mock<IVirtualFileSystemWrapper>();
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "jquery-1.6.2.debug.js")))
                .Returns(false)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "jquery-1.6.2.js")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "jquery-1.6.2.min.js")))
                .Returns(true)
                ;

            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "jquery-ui-1.8.11.debug.js")))
                .Returns(false)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "jquery-ui-1.8.11.js")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "jquery-ui-1.8.11.min.js")))
                .Returns(true)
                ;

            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "MicrosoftAjax.debug.js")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "MicrosoftAjax.js")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "MicrosoftAjax.min.js")))
                .Returns(false)
                ;

            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "knockout-2.1.0beta.debug.js")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "knockout-2.1.0beta.js")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "knockout-2.1.0beta.min.js")))
                .Returns(false)
                ;

            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "modernizr-2.0.6-development-only.debug.js")))
                .Returns(false)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "modernizr-2.0.6-development-only.js")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                    "modernizr-2.0.6-development-only.min.js")))
                .Returns(false)
                ;

            _virtualFileSystemWrapper = virtualFileSystemMock.Object;
        }
Beispiel #25
0
		/// <summary>
		/// Constructs a instance of Asset
		/// </summary>
		/// <param name="virtualPath">Virtual path to asset file</param>
		/// <param name="bundleFile">Bundle file</param>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		/// <param name="styleFileExtensionMappings">Style file extension mappings</param>
		/// <param name="scriptFileExtensionMappings">Script file extension mappings</param>
		public Asset(string virtualPath, BundleFile bundleFile,
			IVirtualFileSystemWrapper virtualFileSystemWrapper,
			FileExtensionMappingCollection styleFileExtensionMappings,
			FileExtensionMappingCollection scriptFileExtensionMappings)
		{
			_virtualFileSystemWrapper = virtualFileSystemWrapper;
			_styleFileExtensionMappings = styleFileExtensionMappings;
			_scriptFileExtensionMappings = scriptFileExtensionMappings;
			if (bundleFile != null)
			{
				_includedVirtualPath = bundleFile.IncludedVirtualPath;
				_transforms = bundleFile.Transforms;
			}
			else
			{
				_includedVirtualPath = string.Empty;
				_transforms = new List<IItemTransform>();
			}
			_assetTypeCode = Constants.AssetTypeCode.Unknown;
			_isStylesheet = false;
			_isScript = false;
			_content = null;

			VirtualPath = virtualPath;
			VirtualPathDependencies = new List<string>();
			OriginalAssets = new List<IAsset>();
			Combined = false;
			Minified = false;
			RelativePathsResolved = false;
		}
Beispiel #26
0
        public JsFileExtensionsFilterTests()
        {
            var virtualFileSystemMock = new Mock <IVirtualFileSystemWrapper>();

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "jquery-1.6.2.debug.js")))
            .Returns(false)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "jquery-1.6.2.js")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "jquery-1.6.2.min.js")))
            .Returns(true)
            ;

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "jquery-ui-1.8.11.debug.js")))
            .Returns(false)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "jquery-ui-1.8.11.js")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "jquery-ui-1.8.11.min.js")))
            .Returns(true)
            ;

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "MicrosoftAjax.debug.js")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "MicrosoftAjax.js")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "MicrosoftAjax.min.js")))
            .Returns(false)
            ;

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "knockout-2.1.0beta.debug.js")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "knockout-2.1.0beta.js")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "knockout-2.1.0beta.min.js")))
            .Returns(false)
            ;

            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "modernizr-2.0.6-development-only.debug.js")))
            .Returns(false)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "modernizr-2.0.6-development-only.js")))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(UrlHelpers.Combine(SCRIPTS_DIRECTORY_VIRTUAL_PATH,
                                                          "modernizr-2.0.6-development-only.min.js")))
            .Returns(false)
            ;

            _virtualFileSystemWrapper = virtualFileSystemMock.Object;
        }
Beispiel #27
0
 public StyleDuplicateAssetsFilterTests()
 {
     _virtualFileSystemWrapper = new Mock <IVirtualFileSystemWrapper>().Object;
 }
 /// <summary>
 /// Constructs a instance of the file extensions filter
 /// </summary>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 protected FileExtensionsFilterBase(IVirtualFileSystemWrapper virtualFileSystemWrapper)
 {
     _virtualFileSystemWrapper = virtualFileSystemWrapper;
 }
 public ScriptAssetTypesValidatorTests()
 {
     _virtualFileSystemWrapper = new MockVirtualFileSystemWrapper("/");
 }
 /// <summary>
 /// Constructs a instance of the debugging TypeScript HTTP-handler
 /// </summary>
 /// <param name="cache">Server cache</param>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 /// <param name="assetHandlerConfig">Configuration settings of the debugging HTTP-handler</param>
 public TypeScriptAssetHandler(Cache cache,
     IVirtualFileSystemWrapper virtualFileSystemWrapper,
     AssetHandlerSettings assetHandlerConfig)
     : base(cache, virtualFileSystemWrapper, assetHandlerConfig)
 {
 }
        /// <summary>
        /// Constructs a instance of TypeScript translator
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="tsConfig">Configuration settings of TypeScript translator</param>
        public TypeScriptTranslator(Func <IJsEngine> createJsEngineInstance,
                                    IVirtualFileSystemWrapper virtualFileSystemWrapper,
                                    TypeScriptSettings tsConfig)
        {
            _virtualFileManager = new VirtualFileManager(virtualFileSystemWrapper);

            AllowUnreachableCode             = tsConfig.AllowUnreachableCode;
            AllowUnusedLabels                = tsConfig.AllowUnusedLabels;
            AlwaysStrict                     = tsConfig.AlwaysStrict;
            DownlevelIteration               = tsConfig.DownlevelIteration;
            ExactOptionalPropertyTypes       = tsConfig.ExactOptionalPropertyTypes;
            ForceConsistentCasingInFileNames = tsConfig.ForceConsistentCasingInFileNames;
            KeyofStringsOnly                 = tsConfig.KeyofStringsOnly;
            Libs = tsConfig.Libs
                   .Cast <LibraryFileRegistration>()
                   .Select(l => l.LibraryFileName)
                   .ToList()
            ;
            NewLine                    = tsConfig.NewLine;
            NoEmit                     = tsConfig.NoEmit;
            NoEmitHelpers              = tsConfig.NoEmitHelpers;
            NoEmitOnError              = tsConfig.NoEmitOnError;
            NoErrorTruncation          = tsConfig.NoErrorTruncation;
            NoFallthroughCasesInSwitch = tsConfig.NoFallthroughCasesInSwitch;
            NoImplicitAny              = tsConfig.NoImplicitAny;
            NoImplicitOverride         = tsConfig.NoImplicitOverride;
            NoImplicitReturns          = tsConfig.NoImplicitReturns;
            NoImplicitThis             = tsConfig.NoImplicitThis;
            NoLib = tsConfig.NoLib;
            NoPropertyAccessFromIndexSignature = tsConfig.NoPropertyAccessFromIndexSignature;
            NoResolve                      = tsConfig.NoResolve;
            NoStrictGenericChecks          = tsConfig.NoStrictGenericChecks;
            NoUncheckedIndexedAccess       = tsConfig.NoUncheckedIndexedAccess;
            NoUnusedLocals                 = tsConfig.NoUnusedLocals;
            NoUnusedParameters             = tsConfig.NoUnusedParameters;
            PreserveConstEnums             = tsConfig.PreserveConstEnums;
            RemoveComments                 = tsConfig.RemoveComments;
            SkipDefaultLibCheck            = tsConfig.SkipDefaultLibCheck;
            SkipLibCheck                   = tsConfig.SkipLibCheck;
            StrictBindCallApply            = tsConfig.StrictBindCallApply;
            StrictNullChecks               = tsConfig.StrictNullChecks;
            StrictFunctionTypes            = tsConfig.StrictFunctionTypes;
            StrictPropertyInitialization   = tsConfig.StrictPropertyInitialization;
            StripInternal                  = tsConfig.StripInternal;
            SuppressExcessPropertyErrors   = tsConfig.SuppressExcessPropertyErrors;
            SuppressImplicitAnyIndexErrors = tsConfig.SuppressImplicitAnyIndexErrors;
            SuppressTypeCheckingErrors     = tsConfig.SuppressTypeCheckingErrors;
            Target                     = tsConfig.Target;
            TranspileOnly              = tsConfig.TranspileOnly;
            UseDefineForClassFields    = tsConfig.UseDefineForClassFields;
            UseUnknownInCatchVariables = tsConfig.UseUnknownInCatchVariables;

            if (createJsEngineInstance == null)
            {
                string jsEngineName = tsConfig.JsEngine.Name;
                if (string.IsNullOrWhiteSpace(jsEngineName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
                                            "typeScript",
                                            @"
  * JavaScriptEngineSwitcher.Msie (only in the Chakra “Edge” JsRT mode)
  * JavaScriptEngineSwitcher.V8
  * JavaScriptEngineSwitcher.ChakraCore",
                                            "MsieJsEngine")
                              );
                }

                createJsEngineInstance = () => JsEngineSwitcher.Current.CreateEngine(jsEngineName);
            }
            _createJsEngineInstance = createJsEngineInstance;
        }
		/// <summary>
		/// Constructs a instance of the file extensions filter
		/// </summary>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		protected FileExtensionsFilterBase(IVirtualFileSystemWrapper virtualFileSystemWrapper)
		{
			_virtualFileSystemWrapper = virtualFileSystemWrapper;
		}
 public void SetUp()
 {
     _virtualFileSystemWrapper = new MockVirtualFileSystemWrapper(APPLICATION_ROOT_URL);
 }
        /// <summary>
        /// Constructs a instance of TypeScript-translator
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JavaScript engine</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="relativePathResolver">Relative path resolver</param>
        /// <param name="tsConfig">Configuration settings of TypeScript-translator</param>
        public TypeScriptTranslator(Func<IJsEngine> createJsEngineInstance,
            IVirtualFileSystemWrapper virtualFileSystemWrapper,
            IRelativePathResolver relativePathResolver, TypeScriptSettings tsConfig)
        {
            _virtualFileSystemWrapper = virtualFileSystemWrapper;
            _relativePathResolver = relativePathResolver;
            _tsScriptCache = new Dictionary<string, TsScript>();

            ExperimentalAsyncFunctions = tsConfig.ExperimentalAsyncFunctions;
            NewLine = tsConfig.NewLine;
            NoEmit = tsConfig.NoEmit;
            NoEmitHelpers = tsConfig.NoEmitHelpers;
            NoEmitOnError = tsConfig.NoEmitOnError;
            NoImplicitAny = tsConfig.NoImplicitAny;
            NoLib = tsConfig.NoLib;
            PreserveConstEnums = tsConfig.PreserveConstEnums;
            RemoveComments = tsConfig.RemoveComments;
            SkipDefaultLibCheck = tsConfig.SkipDefaultLibCheck;
            StripInternal = tsConfig.StripInternal;
            SuppressExcessPropertyErrors = tsConfig.SuppressExcessPropertyErrors;
            SuppressImplicitAnyIndexErrors = tsConfig.SuppressImplicitAnyIndexErrors;
            Target = tsConfig.Target;

            if (createJsEngineInstance == null)
            {
                string jsEngineName = tsConfig.JsEngine.Name;
                if (string.IsNullOrWhiteSpace(jsEngineName))
                {
                    throw new ConfigurationErrorsException(
                        string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
                            "typeScript",
                            @"
              * JavaScriptEngineSwitcher.Msie
              * JavaScriptEngineSwitcher.V8",
                            "MsieJsEngine")
                    );
                }

                createJsEngineInstance = (() =>
                    JsEngineSwitcher.Current.CreateJsEngineInstance(jsEngineName));
            }
            _createJsEngineInstance = createJsEngineInstance;
        }
        public void SetUp()
        {
            var virtualFileSystemMock = new Mock<IVirtualFileSystemWrapper>();

            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "Site.css")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "Site.min.css")))
                .Returns(false)
                ;

            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                    @"themes\base\jquery.ui.accordion.css")))
                .Returns(false)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                    @"themes\base\jquery.ui.accordion.min.css")))
                .Returns(true)
                ;

            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(ALTERNATIVE_STYLES_DIRECTORY_VIRTUAL_PATH,
                    @"css\TestCssComponentsPaths.css")))
                .Returns(true)
                ;
            virtualFileSystemMock
                .Setup(fs => fs.FileExists(UrlHelpers.Combine(ALTERNATIVE_STYLES_DIRECTORY_VIRTUAL_PATH,
                    @"css\TestCssComponentsPaths.min.css")))
                .Returns(true)
                ;

            _virtualFileSystemWrapper = virtualFileSystemMock.Object;
        }
        public void FillingOfDependenciesIsCorrect()
        {
            // Arrange
            var virtualFileSystemMock = new Mock <IVirtualFileSystemWrapper>();

            string testLessLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "TestLess.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(testLessLessAssetVirtualPath))
            .Returns(testLessLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(testLessLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(testLessLessAssetVirtualPath))
            .Returns(@"@import (once) ""Mixins.less"";
@import (reference) ""Variables.less"";
@import (css) url(""data:text/css;base64,Ym9keSB7IGJhY2tncm91bmQtY29sb3I6IGxpbWUgIWltcG9ydGFudDsgfQ=="");

.translators #less
{
	float: left;
	.visible();
	padding: 0.2em 0.5em 0.2em 0.5em;
	background-color: @bg-color;
	color: @caption-color;
	font-weight: bold;
	border: 1px solid @bg-color;
	.border-radius(5px);
}

.icon-monitor
{
	display: inline;
	background-image: url(""@{icons-path}monitor.png"");
}

@import (once) ""TestLessImport.less"";")
            ;

            string mixinsLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "Mixins.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(mixinsLessAssetVirtualPath))
            .Returns(mixinsLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(mixinsLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(mixinsLessAssetVirtualPath))
            .Returns(@"// Border Radius
.border-radius(@radius) {
  -webkit-border-radius: @radius;
     -moz-border-radius: @radius;
          border-radius: @radius;
}

// Visible
.visible
{
	display: block;
}")
            ;

            string variablesLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "Variables.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(variablesLessAssetVirtualPath))
            .Returns(variablesLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(variablesLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(variablesLessAssetVirtualPath))
            .Returns(@"@bg-color: #7AC0DA;
@caption-color: #FFFFFF;
@stylesheets-path: ""/Content/"";
@icons-path: ""/Content/images/icons/"";")
            ;

            string testLessImportLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                           "TestLessImport.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(testLessImportLessAssetVirtualPath))
            .Returns(testLessImportLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(testLessImportLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(testLessImportLessAssetVirtualPath))
            .Returns(@"@alt-bg-color: #143352;

.translators #less
{
	background-color: @alt-bg-color;
}

.icon-headphone
{
	display: inline;
	background-image: data-uri('@{icons-path}headphone.gif');
}

.icon-google-plus
{
	display: inline;
	background-image: data-uri('google-plus.svg');
}

@import (multiple) url(		""TestLessImport.Sub1.less""	);
.singleline-comment { content: ""//"" } .triple-slash-directive { content: '///' } @import '@{stylesheets-path}TestLessImport.Sub2';
/*@import 'TestLessImport.Sub3.less';
@import 'TestLessImport.Sub4.less';*/
// @import ""TestLessImport.Sub5.less"";
// Obsolete import //@import ""TestLessImport.Sub6.less"";
.icon-bean { background-image: url(http://taritsyn.files.wordpress.com/2013/08/bean.png); } //@import ""TestLessImport.Sub7.less"";
// @import ""TestLessImport.Sub8.less""; @import ""TestLessImport.Sub9.less"";
")
            ;


            string headphoneGifAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "images/icons/headphone.gif");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(headphoneGifAssetVirtualPath))
            .Returns(headphoneGifAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(headphoneGifAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileBinaryContent(headphoneGifAssetVirtualPath))
            .Returns(new byte[0])
            ;


            string googlePlusSvgAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "google-plus.svg");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(googlePlusSvgAssetVirtualPath))
            .Returns(googlePlusSvgAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(googlePlusSvgAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(googlePlusSvgAssetVirtualPath))
            .Returns(string.Empty)
            ;


            string testLessImportSub1LessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                               "TestLessImport.Sub1.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(testLessImportSub1LessAssetVirtualPath))
            .Returns(testLessImportSub1LessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(testLessImportSub1LessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(testLessImportSub1LessAssetVirtualPath))
            .Returns(@"@import (css) url(http://fonts.googleapis.com/css?family=Limelight&subset=latin,latin-ext);

@border-color: #143352;

.translators #less
{
	border-color: @border-color;
}

.icon-network
{
	display: inline;
	background-image: data-uri('image/png;base64', ""@network.png"");
}

@import url(""TagIcon.css"");")
            ;


            string networkPngAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "@network.png");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(networkPngAssetVirtualPath))
            .Returns(networkPngAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(networkPngAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileBinaryContent(networkPngAssetVirtualPath))
            .Returns(new byte[0])
            ;


            string tagIconCssAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "TagIcon.css");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(tagIconCssAssetVirtualPath))
            .Returns(tagIconCssAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(tagIconCssAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(tagIconCssAssetVirtualPath))
            .Returns(@".icon-tag
{
	display: inline;
	background-image: url(tag.png) !important;
}")
            ;


            string testLessImportSub2LessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                               "TestLessImport.Sub2.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(testLessImportSub2LessAssetVirtualPath))
            .Returns(testLessImportSub2LessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(testLessImportSub2LessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(testLessImportSub2LessAssetVirtualPath))
            .Returns(@"@import (css) 'http://fonts.googleapis.com/css?family=Limelight&subset=latin,latin-ext';
@import (css) ""UsbFlashDriveIcon.css"";
@import (less) ""ValidationIcon.css"";
@import (inline) ""MicroformatsIcon.css"";
@import (inline, css) 'NodeIcon.less';
@import (css) ""OpenIdIcon.less"";
@import (optional) ""PrinterIcon.less"";
@import (optional) ""NonExistentIcon.less"";
@import ""~/Content/XfnIcon.less"";
@import ""~/Content/YahooIcon.css"";")
            ;


            string usbFlashDriveIconCssAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                             "UsbFlashDriveIcon.css");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(usbFlashDriveIconCssAssetVirtualPath))
            .Returns(usbFlashDriveIconCssAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(usbFlashDriveIconCssAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(usbFlashDriveIconCssAssetVirtualPath))
            .Returns(@".icon-usb-flash-drive
{
	display: inline;
	background-image: ""usb-flash-drive.png"" !important;
}")
            ;

            string validationIconCssAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                          "ValidationIcon.css");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(validationIconCssAssetVirtualPath))
            .Returns(validationIconCssAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(validationIconCssAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(validationIconCssAssetVirtualPath))
            .Returns(@".icon-validation
{
	display: inline;
	background-image: url('validation.png') !important;
}")
            ;

            string microformatsIconCssAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                            "MicroformatsIcon.css");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(microformatsIconCssAssetVirtualPath))
            .Returns(microformatsIconCssAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(microformatsIconCssAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(microformatsIconCssAssetVirtualPath))
            .Returns(@".icon-microformats
{
	display: inline;
	background-image: url(microformats.png) !important;
}")
            ;

            string nodeIconLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                     "NodeIcon.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(nodeIconLessAssetVirtualPath))
            .Returns(nodeIconLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(nodeIconLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(nodeIconLessAssetVirtualPath))
            .Returns(@".icon-node
{
	display: inline;
	background-image: url(node.png) !important;
}")
            ;

            string openIdIconLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                       "OpenIdIcon.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(openIdIconLessAssetVirtualPath))
            .Returns(openIdIconLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(openIdIconLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(openIdIconLessAssetVirtualPath))
            .Returns(@".icon-openid
{
	display: inline;
	background-image: url(openid.png) !important;
}")
            ;

            string printerIconLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                        "PrinterIcon.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(printerIconLessAssetVirtualPath))
            .Returns(printerIconLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(printerIconLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(printerIconLessAssetVirtualPath))
            .Returns(@".icon-printer
{
	display: inline;
	background-image: url(printer.png) !important;
}")
            ;

            string nonExistentIconLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                            "NonExistentIcon.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(nonExistentIconLessAssetVirtualPath))
            .Returns(nonExistentIconLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(nonExistentIconLessAssetVirtualPath))
            .Returns(false)
            ;

            string xfnIconLessAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                    "XfnIcon.less");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath("~" + xfnIconLessAssetVirtualPath))
            .Returns(xfnIconLessAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(xfnIconLessAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(xfnIconLessAssetVirtualPath))
            .Returns(@".icon-xfn
{
	display: inline;
	background-image: url(""~/Content/xfn.png"");
}")
            ;

            string xfnPngAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                               "xfn.png");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath("~" + xfnPngAssetVirtualPath))
            .Returns(xfnPngAssetVirtualPath)
            ;

            string yahooIconCssAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH,
                                                                     "YahooIcon.css");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath("~" + yahooIconCssAssetVirtualPath))
            .Returns(yahooIconCssAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(yahooIconCssAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(yahooIconCssAssetVirtualPath))
            .Returns(@".icon-yahoo
{
	display: inline;
	background-image: url(""/Content/yahoo.ico"") !important;
}")
            ;

            Func <IJsEngine> createJsEngineInstance =
                () => JsEngineSwitcher.Instance.CreateDefaultEngine();
            IVirtualFileSystemWrapper virtualFileSystemWrapper = virtualFileSystemMock.Object;
            var lessConfig = new LessSettings();

            var lessTranslator = new LessTranslator(createJsEngineInstance,
                                                    virtualFileSystemWrapper, lessConfig);
            IAsset asset = new Asset(testLessLessAssetVirtualPath, virtualFileSystemWrapper);

            // Act
            asset = lessTranslator.Translate(asset);
            IList <string> dependencies = asset.VirtualPathDependencies;

            // Assert
            Assert.Equal(14, dependencies.Count);
            Assert.Equal(mixinsLessAssetVirtualPath, dependencies[0]);
            Assert.Equal(variablesLessAssetVirtualPath, dependencies[1]);
            Assert.Equal(testLessImportLessAssetVirtualPath, dependencies[2]);
            Assert.Equal(testLessImportSub1LessAssetVirtualPath, dependencies[3]);
            Assert.Equal(testLessImportSub2LessAssetVirtualPath, dependencies[4]);
            Assert.Equal(validationIconCssAssetVirtualPath, dependencies[5]);
            Assert.Equal(microformatsIconCssAssetVirtualPath, dependencies[6]);
            Assert.Equal(nodeIconLessAssetVirtualPath, dependencies[7]);
            Assert.Equal(printerIconLessAssetVirtualPath, dependencies[8]);
            Assert.Equal(nonExistentIconLessAssetVirtualPath, dependencies[9]);
            Assert.Equal(xfnIconLessAssetVirtualPath, dependencies[10]);
            Assert.Equal(headphoneGifAssetVirtualPath, dependencies[11]);
            Assert.Equal(googlePlusSvgAssetVirtualPath, dependencies[12]);
            Assert.Equal(networkPngAssetVirtualPath, dependencies[13]);
        }
Beispiel #37
0
 /// <summary>
 /// Constructs a instance of CSS file extensions filter
 /// </summary>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 public CssFileExtensionsFilter(IVirtualFileSystemWrapper virtualFileSystemWrapper)
     : base(virtualFileSystemWrapper)
 {
 }
		/// <summary>
		/// Constructs a instance of Closure Local JS-minifier
		/// </summary>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		/// <param name="closureConfig">Configuration settings of Closure Minifier</param>
		/// <param name="tempFilesDirectoryPath">Absolute path to directory that contains temporary files</param>
		public ClosureLocalJsMinifier(IVirtualFileSystemWrapper virtualFileSystemWrapper,
			ClosureSettings closureConfig,
			string tempFilesDirectoryPath)
			: base(virtualFileSystemWrapper, closureConfig)
		{
			_tempFilesDirectoryPath = tempFilesDirectoryPath;

			LocalJsMinifierSettings localJsMinifierConfig = closureConfig.Js.Local;
			MapCommonSettings(this, localJsMinifierConfig);
			AcceptConstKeyword = localJsMinifierConfig.AcceptConstKeyword;
			AllowEs6Output = localJsMinifierConfig.AllowEs6Output;
			AngularPass = localJsMinifierConfig.AngularPass;
			ClosureCompilerApplicationPath = localJsMinifierConfig.ClosureCompilerApplicationPath;
			DefinitionList = localJsMinifierConfig.DefinitionList;
			ErrorList = localJsMinifierConfig.ErrorList;
			ExportLocalPropertyDefinitions = localJsMinifierConfig.ExportLocalPropertyDefinitions;
			ExtraAnnotationNameList = localJsMinifierConfig.ExtraAnnotationNameList;
			GenerateExports = localJsMinifierConfig.GenerateExports;
			JavaVirtualMachinePath = localJsMinifierConfig.JavaVirtualMachinePath;
			LanguageInput = localJsMinifierConfig.LanguageInput;
			LanguageOutput = localJsMinifierConfig.LanguageOutput;
			ProcessClosurePrimitives = localJsMinifierConfig.ProcessClosurePrimitives;
			ProcessJqueryPrimitives = localJsMinifierConfig.ProcessJqueryPrimitives;
			SingleQuotes = localJsMinifierConfig.SingleQuotes;
			ThirdParty = localJsMinifierConfig.ThirdParty;
			TranspileOnly = localJsMinifierConfig.TranspileOnly;
			TurnOffWarningClassList = localJsMinifierConfig.TurnOffWarningClassList;
			UseOnlyCustomExterns = localJsMinifierConfig.UseOnlyCustomExterns;
			WarningList = localJsMinifierConfig.WarningList;

			string javaVirtualMachinePath = JavaVirtualMachinePath;
			if (string.IsNullOrWhiteSpace(javaVirtualMachinePath))
			{
				throw new EmptyValueException(Strings.Minifiers_JavaVirtualMachinePathNotSpecified);
			}
			if (!File.Exists(javaVirtualMachinePath))
			{
				throw new FileNotFoundException(
					string.Format(Strings.Minifiers_JavaVirtualMachineNotFound, javaVirtualMachinePath));
			}

			string closureCompilerApplicationPath = ClosureCompilerApplicationPath;
			if (string.IsNullOrWhiteSpace(closureCompilerApplicationPath))
			{
				throw new EmptyValueException(Strings.Minifiers_ClosureCompilerApplicationPathNotSpecified);
			}
			if (!File.Exists(closureCompilerApplicationPath))
			{
				throw new FileNotFoundException(
					string.Format(Strings.Minifiers_ClosureCompilerApplicationNotFound, closureCompilerApplicationPath));
			}
		}
        public void FillingOfDependenciesIsCorrect()
        {
            // Arrange
            var virtualFileSystemMock = new Mock <IVirtualFileSystemWrapper>();

            string testCssAssetVirtualPath = UrlHelpers.Combine(STYLES_DIRECTORY_VIRTUAL_PATH, "Test.css");

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(testCssAssetVirtualPath))
            .Returns(testCssAssetVirtualPath)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(testCssAssetVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(testCssAssetVirtualPath))
            .Returns(@":fullscreen a
{
	display: flex
}")
            ;

            const string customStatisticsFileVirtualPath = "~/App_Data/BundleTransformer/stats.json";

            virtualFileSystemMock
            .Setup(fs => fs.ToAbsolutePath(customStatisticsFileVirtualPath))
            .Returns(customStatisticsFileVirtualPath.Replace("~/", "/"))
            ;
            virtualFileSystemMock
            .Setup(fs => fs.FileExists(customStatisticsFileVirtualPath))
            .Returns(true)
            ;
            virtualFileSystemMock
            .Setup(fs => fs.GetFileTextContent(customStatisticsFileVirtualPath))
            .Returns(@"{
	""name"": ""All data of website"",
	""id"": ""90598522|undefined"",
	""type"": ""custom"",
	""source"": ""google_analytics"",
	""dataByBrowser"": {},
	""meta"": {
		""start_date"": ""2015-12-20"",
		""end_date"": ""2016-01-19""
	},
	""uid"": ""custom.90598522|undefined""
}")
            ;

            Func <IJsEngine> createJsEngineInstance =
                () => JsEngineSwitcher.Instance.CreateDefaultEngine();
            IVirtualFileSystemWrapper virtualFileSystemWrapper = virtualFileSystemMock.Object;
            var autoprefixerConfig = new AutoprefixerSettings
            {
                Stats = customStatisticsFileVirtualPath
            };

            var autoprefixCssPostProcessor = new AutoprefixCssPostProcessor(createJsEngineInstance,
                                                                            virtualFileSystemWrapper, autoprefixerConfig);
            IAsset asset = new Asset(testCssAssetVirtualPath, virtualFileSystemWrapper);

            // Act
            asset = autoprefixCssPostProcessor.PostProcess(asset);
            IList <string> dependencies = asset.VirtualPathDependencies;

            // Assert
            Assert.Equal(1, dependencies.Count);
            Assert.Equal("/App_Data/BundleTransformer/stats.json", dependencies[0]);
        }
		/// <summary>
		/// Constructs a instance of CSS-file extensions filter
		/// </summary>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		public CssFileExtensionsFilter(IVirtualFileSystemWrapper virtualFileSystemWrapper)
			: base(virtualFileSystemWrapper)
		{ }
		/// <summary>
		/// Constructs a instance of common relative path resolver
		/// </summary>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		public CommonRelativePathResolver(IVirtualFileSystemWrapper virtualFileSystemWrapper)
		{
			_virtualFileSystemWrapper = virtualFileSystemWrapper;
		}
Beispiel #42
0
 /// <summary>
 /// Constructs a instance of common relative path resolver
 /// </summary>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 public CommonRelativePathResolver(IVirtualFileSystemWrapper virtualFileSystemWrapper)
 {
     _virtualFileSystemWrapper = virtualFileSystemWrapper;
 }
Beispiel #43
0
		/// <summary>
		/// Constructs a instance of Asset
		/// </summary>
		/// <param name="virtualPath">Virtual path to asset file</param>
		/// <param name="bundleFile">Bundle file</param>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		public Asset(string virtualPath, BundleFile bundleFile,
			IVirtualFileSystemWrapper virtualFileSystemWrapper)
			: this(virtualPath, bundleFile, virtualFileSystemWrapper,
				BundleTransformerContext.Current.Styles.FileExtensionMappings,
				BundleTransformerContext.Current.Scripts.FileExtensionMappings)
		{ }
        /// <summary>
        /// Constructs a instance of TypeScript translator
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
        /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
        /// <param name="tsConfig">Configuration settings of TypeScript translator</param>
        public TypeScriptTranslator(Func <IJsEngine> createJsEngineInstance,
                                    IVirtualFileSystemWrapper virtualFileSystemWrapper,
                                    TypeScriptSettings tsConfig)
        {
            _virtualFileManager = new VirtualFileManager(virtualFileSystemWrapper);

            AllowUnreachableCode             = tsConfig.AllowUnreachableCode;
            AllowUnusedLabels                = tsConfig.AllowUnusedLabels;
            AlwaysStrict                     = tsConfig.AlwaysStrict;
            DownlevelIteration               = tsConfig.DownlevelIteration;
            ForceConsistentCasingInFileNames = tsConfig.ForceConsistentCasingInFileNames;
            Libs = tsConfig.Libs
                   .Cast <LibraryFileRegistration>()
                   .Select(l => l.LibraryFileName)
                   .ToList()
            ;
            NewLine                    = tsConfig.NewLine;
            NoEmit                     = tsConfig.NoEmit;
            NoEmitHelpers              = tsConfig.NoEmitHelpers;
            NoEmitOnError              = tsConfig.NoEmitOnError;
            NoErrorTruncation          = tsConfig.NoErrorTruncation;
            NoFallthroughCasesInSwitch = tsConfig.NoFallthroughCasesInSwitch;
            NoImplicitAny              = tsConfig.NoImplicitAny;
            NoImplicitReturns          = tsConfig.NoImplicitReturns;
            NoImplicitThis             = tsConfig.NoImplicitThis;
            NoLib                          = tsConfig.NoLib;
            NoResolve                      = tsConfig.NoResolve;
            NoStrictGenericChecks          = tsConfig.NoStrictGenericChecks;
            NoUnusedLocals                 = tsConfig.NoUnusedLocals;
            NoUnusedParameters             = tsConfig.NoUnusedParameters;
            PreserveConstEnums             = tsConfig.PreserveConstEnums;
            RemoveComments                 = tsConfig.RemoveComments;
            SkipDefaultLibCheck            = tsConfig.SkipDefaultLibCheck;
            SkipLibCheck                   = tsConfig.SkipLibCheck;
            StrictNullChecks               = tsConfig.StrictNullChecks;
            StripInternal                  = tsConfig.StripInternal;
            SuppressExcessPropertyErrors   = tsConfig.SuppressExcessPropertyErrors;
            SuppressImplicitAnyIndexErrors = tsConfig.SuppressImplicitAnyIndexErrors;
            SuppressTypeCheckingErrors     = tsConfig.SuppressTypeCheckingErrors;
            Target                         = tsConfig.Target;
            TranspileOnly                  = tsConfig.TranspileOnly;

            if (createJsEngineInstance == null)
            {
                string jsEngineName = tsConfig.JsEngine.Name;
                if (string.IsNullOrWhiteSpace(jsEngineName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
                                            "typeScript",
                                            @"
  * JavaScriptEngineSwitcher.Msie
  * JavaScriptEngineSwitcher.V8
  * JavaScriptEngineSwitcher.ChakraCore",
                                            "MsieJsEngine")
                              );
                }

                createJsEngineInstance = () => JsEngineSwitcher.Instance.CreateEngine(jsEngineName);
            }
            _createJsEngineInstance = createJsEngineInstance;
        }
Beispiel #45
0
 /// <summary>
 /// Constructs a instance of virtual file manager
 /// </summary>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 public VirtualFileManager(IVirtualFileSystemWrapper virtualFileSystemWrapper)
 {
     _virtualFileSystemWrapper = virtualFileSystemWrapper;
 }
		/// <summary>
		/// Constructs a instance of Closure JS-minifier
		/// </summary>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		/// <param name="closureConfig">Configuration settings of Closure Minifier</param>
		protected ClosureJsMinifierBase(IVirtualFileSystemWrapper virtualFileSystemWrapper,
			ClosureSettings closureConfig)
		{
			_virtualFileSystemWrapper = virtualFileSystemWrapper;

			CommonExternsFilePaths = closureConfig.Js.CommonExternsFiles
				.Cast<CommonJsExternsFileRegistration>()
				.Select(f => f.ExternsFilePath)
				.ToList()
				;
			ExternsFileMappings = closureConfig.Js.ExternMappings
				.Cast<JsExternsFileMappingRegistration>()
				.Select(m =>
					new JsExternsFileMapping(m.ScriptFilePath,
						Utils.ConvertToStringCollection(m.ExternsFilePaths, ',',
							trimItemValues: true, removeEmptyItems: true).ToList()
						)
				)
				.ToList()
				;
		}
 public void SetUp()
 {
     _virtualFileSystemWrapper = new MockVirtualFileSystemWrapper("/");
 }
Beispiel #48
0
		/// <summary>
		/// Constructs a instance of Asset
		/// </summary>
		/// <param name="virtualPath">Virtual path to asset file</param>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		public Asset(string virtualPath, IVirtualFileSystemWrapper virtualFileSystemWrapper)
			: this(virtualPath, null, virtualFileSystemWrapper)
		{ }
 public void SetUp()
 {
     _virtualFileSystemWrapper = (new Mock<IVirtualFileSystemWrapper>()).Object;
 }
		/// <summary>
		/// Constructs a instance of LESS-translator
		/// </summary>
		/// <param name="createJsEngineInstance">Delegate that creates an instance of JavaScript engine</param>
		/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
		/// <param name="relativePathResolver">Relative path resolver</param>
		/// <param name="lessConfig">Configuration settings of LESS-translator</param>
		public LessTranslator(Func<IJsEngine> createJsEngineInstance,
			IVirtualFileSystemWrapper virtualFileSystemWrapper,
			IRelativePathResolver relativePathResolver,
			LessSettings lessConfig)
		{
			_virtualFileSystemWrapper = virtualFileSystemWrapper;
			_relativePathResolver = relativePathResolver;
			_lessStylesheetCache = new Dictionary<string, LessStylesheet>();

			UseNativeMinification = lessConfig.UseNativeMinification;
			IeCompat = lessConfig.IeCompat;
			StrictMath = lessConfig.StrictMath;
			StrictUnits = lessConfig.StrictUnits;
			DumpLineNumbers = lessConfig.DumpLineNumbers;
			JavascriptEnabled = lessConfig.JavascriptEnabled;
			GlobalVariables = lessConfig.GlobalVariables;
			ModifyVariables = lessConfig.ModifyVariables;

			if (createJsEngineInstance == null)
			{
				string jsEngineName = lessConfig.JsEngine.Name;
				if (string.IsNullOrWhiteSpace(jsEngineName))
				{
					throw new ConfigurationErrorsException(
						string.Format(CoreStrings.Configuration_JsEngineNotSpecified,
							"less",
							@"
  * JavaScriptEngineSwitcher.Msie
  * JavaScriptEngineSwitcher.V8",
							"MsieJsEngine")
					);
				}

				createJsEngineInstance = (() =>
					JsEngineSwitcher.Current.CreateJsEngineInstance(jsEngineName));
			}
			_createJsEngineInstance = createJsEngineInstance;
		}
 public void TearDown()
 {
     _virtualFileSystemWrapper = null;
 }
 /// <summary>
 /// Constructs a instance of Sass file manager
 /// </summary>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 public SassFileManager(IVirtualFileSystemWrapper virtualFileSystemWrapper)
 {
     _virtualFileSystemWrapper = virtualFileSystemWrapper;
     _defaultDirectoryName = GetDefaultDirectory();
     _currentDirectoryName = null;
 }
 /// <summary>
 /// Constructs a instance of the debugging Sass and SCSS HTTP-handler
 /// </summary>
 /// <param name="cache">Server cache</param>
 /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
 /// <param name="assetHandlerConfig">Configuration settings of the debugging HTTP-handler</param>
 public SassAndScssAssetHandler(Cache cache,
     IVirtualFileSystemWrapper virtualFileSystemWrapper,
     AssetHandlerSettings assetHandlerConfig)
     : base(cache, virtualFileSystemWrapper, assetHandlerConfig)
 {
 }