public void Render_JavascriptAssetType_RendersOnlyCorrectAssetType()
        {
            // given mixed assets, a render of AssetType.Javascript only returns Javascript assets
            var cssAsset = new CssAsset(_context, _settings)
            {
                Path = "test-path"
            };

            _assetManager.Add(cssAsset, null);
            var jsAsset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path2"
            };

            _assetManager.Add(jsAsset, null);
            _assetManager.Render(AssetType.Javascript, null);
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            var call = _buildHtmlCalls.First();

            Assert.That(call.Assets.Count(), Is.EqualTo(1));
            var asset = call.Assets.First();

            Assert.IsInstanceOf <JavascriptAsset>(asset);
            Assert.That(asset.Path, Is.EqualTo("test-path2"));
        }
        public void Add_DuplicateJavascriptAsset_DifferentGroups_AddsTwoAssets()
        {
            var newAsset1 = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path"
            };
            var newAsset2 = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path"
            };

            _assetManager.Add(newAsset1, "test-group1");
            _assetManager.Add(newAsset2, "test-group2");
            _assetManager.Render(AssetType.Javascript, "test-group1");
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            var call = _buildHtmlCalls.First();

            Assert.That(call.Assets.Count(), Is.EqualTo(1));
            var asset = call.Assets.First();

            Assert.IsInstanceOf <JavascriptAsset>(asset);
            Assert.That(asset.Path, Is.EqualTo("test-path"));
            _buildHtmlCalls.Clear();
            _assetManager.Render(AssetType.Javascript, "test-group2");
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            call = _buildHtmlCalls.First();
            Assert.That(call.Assets.Count(), Is.EqualTo(1));
            asset = call.Assets.First();
            Assert.IsInstanceOf <JavascriptAsset>(asset);
            Assert.That(asset.Path, Is.EqualTo("test-path"));
        }
        public void JavascriptAsset_GetKey_GetsCorrectExternalFlag()
        {
            var asset = new JavascriptAsset(_context, _notExternalAltSettings)
            {
                Path = "valid-path"
            };

            asset.AlternatePaths.Add("notExternal", "/relative-path.css");
            asset.AlternatePaths.Add("external", "http://www.fullpath.com/file.css");

            var notExternalKey = asset.Key;

            Assert.That(notExternalKey, Is.Not.Null);
            Assert.That(notExternalKey.IsExternal, Is.False);

            asset = new JavascriptAsset(_context, _externalAltSettings)
            {
                Path = "valid-path"
            };
            asset.AlternatePaths.Add("notExternal", "/relative-path.css");
            asset.AlternatePaths.Add("external", "http://www.fullpath.com/file.css");

            var externalKey = asset.Key;

            Assert.That(externalKey, Is.Not.Null);
            Assert.That(externalKey.IsExternal, Is.True);
        }
Exemple #4
0
        public void NotEqualsOperator_Nulls_AreNotEqual()
        {
            var asset = new JavascriptAsset(_context, _settings);

            Assert.IsTrue(null != asset);
            Assert.IsTrue(asset != null);
        }
        public void JavascriptAsset_GetKey_ReturnsCssAssetKey()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "valid-path"
            };

            Assert.That(asset.Key as JavascriptAssetKey, Is.Not.Null);
        }
        public void JavascriptAsset_GetKey_ThrowsNoErrors()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "valid-path"
            };

            Assert.That(asset.Key, Is.Not.Null);
        }
        public void JavascriptAsset_GetKey_NonExistantAlternateName_ThrowsNoErrors()
        {
            var asset = new JavascriptAsset(_context, _notExternalAltSettings)
            {
                Path = "valid-path"
            };
            var key = asset.Key;

            Assert.That(key, Is.Not.Null);
        }
Exemple #8
0
        public void CurrentFilePath_RelativePath_CallsMapPath()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "original-path"
            };

            Assert.That(asset.CurrentPath, Is.EqualTo("original-path"));
            Assert.That(asset.CurrentFilePath.StartsWith(@"c:\full\path\"));
        }
Exemple #9
0
        public void CurrentFilePath_ExternalPath_ReturnsUnmodifiedPath()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "http://original-path"
            };

            Assert.That(asset.CurrentPath, Is.EqualTo("http://original-path"));
            Assert.That(asset.CurrentFilePath, Is.EqualTo(null));
        }
Exemple #10
0
        public void CurrentPath_WithoutAlternatePath_ReturnsCorrectPath()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "original-path"
            };

            Assert.That(asset.CurrentAlternateName, Is.EqualTo("test-alt-name"));
            Assert.That(asset.CurrentPath, Is.EqualTo("original-path"));
        }
Exemple #11
0
        public void CurrentPathIsExternal_RelativePath_ReturnsFalse()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "original-path"
            };

            Assert.That(asset.CurrentPath, Is.EqualTo("original-path"));
            Assert.That(asset.CurrentPathIsExternal, Is.False);
        }
Exemple #12
0
        public void CurrentPathIsExternal_ExternalPath_ReturnsTrue()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "http://original-path"
            };

            Assert.That(asset.CurrentPath, Is.EqualTo("http://original-path"));
            Assert.That(asset.CurrentPathIsExternal, Is.True);
        }
        public void JavascriptAsset_GetKey_GetsCorrectBrowser()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "valid-path",
                ConditionalBrowser = IE.Version.IE7
            };
            var key = asset.Key;

            Assert.That(key, Is.Not.Null);
            Assert.That(key.Browser, Is.EqualTo(IE.Version.IE7));
        }
        public void JavascriptAsset_GetKey_GetsCorrectEquality()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "valid-path",
                ConditionalEquality = IE.Equality.GreaterThan
            };
            var key = asset.Key;

            Assert.That(key, Is.Not.Null);
            Assert.That(key.Equality, Is.EqualTo(IE.Equality.GreaterThan));
        }
Exemple #15
0
        public void JavascriptAsset_DoesNotProcess() {
            var reader = GetReader("body { background: url(a/url.png); }");
            var asset = new JavascriptAsset(_context, _settings) { Path = "", IgnoreProcessing = true, Reader = reader };

            var processer = new CssRelativePathProcessor(_urlManager.Object);

            var results = processer.Process(new[] { asset });

            _urlManager.Verify(manager => manager.GetAbsoluteUrl(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
            Assert.That(ReferenceEquals(results.Single().Reader, reader));
            Assert.That(asset.Reader.Content, Is.Not.ContainsSubstring(_fakeAbsoluteUrlPrefix));
        }
Exemple #16
0
        public void Equals_AssetWithDifferentBrowser_IsNotEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                ConditionalBrowser = IE.Version.IE5
            };
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                ConditionalBrowser = IE.Version.IE6
            };

            Assert.IsFalse(asset.Equals(equalAsset));
        }
Exemple #17
0
        public void Equals_AssetWithSameBrowser_IsEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                ConditionalBrowser = IE.Version.IE5
            };
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                ConditionalBrowser = IE.Version.IE5
            };

            Assert.IsTrue(asset.Equals(equalAsset));
        }
Exemple #18
0
        public void Equals_AssetWithDifferentEquality_IsNotEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                ConditionalEquality = IE.Equality.LessThan
            };
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                ConditionalEquality = IE.Equality.GreaterThan
            };

            Assert.IsFalse(asset.Equals(equalAsset));
        }
Exemple #19
0
        public void Equals_AssetWithDifferentPath_IsNotEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path"
            };
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path2"
            };

            Assert.IsFalse(asset.Equals(equalAsset));
        }
Exemple #20
0
        public void Equals_AssetWithSamePath_IsEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path"
            };
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path"
            };

            Assert.IsTrue(asset.Equals(equalAsset));
        }
Exemple #21
0
        public void Equals_AssetWithSameEquality_IsEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                ConditionalEquality = IE.Equality.GreaterThan
            };
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                ConditionalEquality = IE.Equality.GreaterThan
            };

            Assert.IsTrue(asset.Equals(equalAsset));
        }
        public void Add_MultipleJavascriptAssets_DifferentGroups_CorrectlyAddsAssets()
        {
            // subtly different
            var newAsset1 = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path1"
            };
            var newAsset2 = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path2"
            };
            var newAsset3 = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path3"
            };
            var newAsset4 = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path4"
            };

            _assetManager.Add(newAsset1, "test-group2");
            _assetManager.Add(newAsset2, "test-group3");
            _assetManager.Add(newAsset3, "test-group3");
            _assetManager.Add(newAsset4, "test-group1");
            _assetManager.Render(AssetType.Javascript, "test-group1");
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            var call = _buildHtmlCalls.First();

            Assert.That(call.Assets.Count(), Is.EqualTo(1));
            Assert.That(call.Assets.Count(a => a.Path == "test-path4"), Is.EqualTo(1));
            Assert.IsInstanceOf <JavascriptAsset>(call.Assets.Single(a => a.Path == "test-path4"));

            _buildHtmlCalls.Clear();
            _assetManager.Render(AssetType.Javascript, "test-group2");
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            call = _buildHtmlCalls.First();
            Assert.That(call.Assets.Count(), Is.EqualTo(1));
            Assert.That(call.Assets.Count(a => a.Path == "test-path1"), Is.EqualTo(1));
            Assert.IsInstanceOf <JavascriptAsset>(call.Assets.Single(a => a.Path == "test-path1"));

            _buildHtmlCalls.Clear();
            _assetManager.Render(AssetType.Javascript, "test-group3");
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            call = _buildHtmlCalls.First();
            Assert.That(call.Assets.Count(), Is.EqualTo(2));
            Assert.That(call.Assets.Count(a => a.Path == "test-path2"), Is.EqualTo(1));
            Assert.IsInstanceOf <JavascriptAsset>(call.Assets.Single(a => a.Path == "test-path2"));
            Assert.That(call.Assets.Count(a => a.Path == "test-path3"), Is.EqualTo(1));
            Assert.IsInstanceOf <JavascriptAsset>(call.Assets.Single(a => a.Path == "test-path3"));
        }
        public void Render_NoAlternateName_RendersAlternateFromSettings()
        {
            // if no alternate path name is passed, the path from settings is used.
            Assert.Inconclusive("Not Yet Implemented - Must Mock Settings");
            var newAsset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path"
            };

            _assetManager.Add(newAsset, "test-group");
            _assetManager.Render(AssetType.Javascript, "test-group");
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            var call = _buildHtmlCalls.First();
            //Assert.That(call.AlternateName, Is.EqualTo("an-alt-path"));
        }
Exemple #24
0
        public void Equals_AssetWithUnselectedAltPath_IsEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                ConditionalBrowser = IE.Version.IE5
            };

            asset.AlternatePaths.Add("unselected-alt-name", "/other-path.css");
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                ConditionalBrowser = IE.Version.IE5
            };

            Assert.IsTrue(asset.Equals(equalAsset));
        }
        public void JavascriptAsset_NoCultureInfoSpecialChars_ShowsSpecialChars()
        {
            var          reader   = GetReader("var aäßáéíóú = 5;");
            const string expected = "var aäßáéíóú=5;";

            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "", Reader = reader
            };

            var processer = new YuiMinimizeProcessor();

            var results = processer.Process(new[] { asset });

            Assert.That(results.Single().Reader.Content, Is.EqualTo(expected));
        }
Exemple #26
0
        public void Equals_AssetWithDifferentProperties_IsNotEqual()
        {
            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path",
                ConditionalEquality = IE.Equality.LessThan,
                ConditionalBrowser  = IE.Version.IE5
            };
            var equalAsset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path",
                ConditionalEquality = IE.Equality.GreaterThan,
                ConditionalBrowser  = IE.Version.IE5
            };

            Assert.IsFalse(asset.Equals(equalAsset));
        }
        public void Add_JavascriptAsset_WithGroup_CorrectlyAddsAsset()
        {
            var newAsset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path"
            };

            _assetManager.Add(newAsset, "test-group");
            _assetManager.Render(AssetType.Javascript, "test-group");
            Assert.That(_buildHtmlCalls.Count, Is.EqualTo(1));
            var call = _buildHtmlCalls.First();

            Assert.That(call.Assets.Count(), Is.EqualTo(1));
            var asset = call.Assets.First();

            Assert.IsInstanceOf <JavascriptAsset>(asset);
            Assert.That(asset.Path, Is.EqualTo("test-path"));
        }
        public void JavascriptAsset_DefaultCultureInfo_RespectsCultureInfo()
        {
            var          reader   = GetReader("var stuff = {foo:0.9, faa:3};");
            const string expected = "var stuff={foo:0.9,faa:3};";

            var asset = new JavascriptAsset(_context, _settings)
            {
                Path = "", Reader = reader
            };

            var processer = new YuiMinimizeProcessor {
                CultureInfo = CultureInfo.CreateSpecificCulture("en-US")
            };

            var results = processer.Process(new[] { asset });

            Assert.That(results.Single().Reader.Content, Is.EqualTo(expected));
        }
 internal JavascriptAssetBuilder(HttpContextBase context, IAssetManagerSettings settings,
                                 string path, IAssetManager assetManager, string assetGroup, bool onLayoutPage)
 {
     if (string.IsNullOrWhiteSpace(path))
     {
         throw new ArgumentException("The param 'path' must be a non-empty string.");
     }
     if (assetManager == null)
     {
         throw new ArgumentNullException("assetManager");
     }
     Asset = new JavascriptAsset(context, settings)
     {
         Path = path, OnLayoutPage = onLayoutPage
     };
     Asset.Reader = new FileSystemAssetReader(Asset);
     AssetManager = assetManager;
     AssetGroup   = assetGroup;
 }
        public void FixtureInit()
        {
            var cssConfig = new Mock <AssetConfiguration>();

            cssConfig.Setup(c => c.AlternateName).Returns(String.Empty);
            var jsConfig = new Mock <AssetConfiguration>();

            jsConfig.Setup(c => c.AlternateName).Returns(String.Empty);

            var settings = new Mock <IAssetManagerSettings>();

            settings.Setup(s => s.Css).Returns(cssConfig.Object);
            settings.Setup(s => s.Javascript).Returns(jsConfig.Object);

            _settings = settings.Object;

            var request = new Mock <HttpRequestBase>();

            request.Setup(r => r.MapPath(It.IsAny <string>()))
            .Returns <string>(s => @"c:\full\path\" + s);
            var context = new Mock <HttpContextBase>();

            context.Setup(c => c.Request).Returns(request.Object);

            _context = context.Object;

            _builder          = new JavascriptHtmlBuilder();
            _conditionalAsset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path.css",
                ConditionalBrowser  = IE.Version.IE7,
                ConditionalEquality = IE.Equality.LessThan
            };
            _asset = new JavascriptAsset(_context, _settings)
            {
                Path = "test-path2.css",
            };
        }