private void CreateResources(params string[] paths) { foreach (var path in paths) { _allResources.Add(StubResource.WithPath("~/" + path)); } }
public void WhenGivenPathIsConsolidatedUrl_AllDependenciesOfChildrenThatAreNotInTheGivenGroupAreReturned() { var jquery = StubResource.WithPath("~/scripts/jquery.js"); var jquerypluginA = StubResource.WithPath("~/scripts/jquery-plugin-a.js"); var jquerypluginB = StubResource.WithPath("~/scripts/jquery-plugin-b.js"); var myscript = StubResource.WithPath("~/scripts/myscript.js"); var myotherscript = StubResource.WithPath("~/scripts/myotherscript.js"); _resourceFinder.AddResources(jquery, jquerypluginA, jquerypluginB, myscript, myotherscript); SetDependencies(jquerypluginB, jquery.VirtualPath, jquerypluginA.VirtualPath); SetDependencies(jquerypluginA, jquery.VirtualPath); SetDependencies(myscript, jquerypluginB.VirtualPath); SetDependencies(myotherscript, myscript.VirtualPath, jquery.VirtualPath); var coreGroup = new ResourceGroup("~/scripts/core.js", new[] { jquery, jquerypluginA, jquerypluginB }); _scriptGroups.Add(new StubResourceGroupTemplate(coreGroup)); var leafGroup = new ResourceGroup("~/scripts/leaf.js", new[] { myscript, myotherscript }); _scriptGroups.Add(new StubResourceGroupTemplate(leafGroup)); var dependencies = _dependencyManager.GetDependencies("~/scripts/leaf.js").ToList(); dependencies.CountShouldEqual(3); dependencies[0].ShouldEqual(jquery.VirtualPath); dependencies[1].ShouldEqual(jquerypluginA.VirtualPath); dependencies[2].ShouldEqual(jquerypluginB.VirtualPath); }
private IResource CreateResource(DateTime lastModified) { StubResource resource = new StubResource(String.Empty); resource.LastModified = lastModified; return(resource); }
public void ReferenceElementeWithNameButMissingAssemblyAttributeReturnsEmbeddedResourceVirtualPathForSystemWebExtensionsAssembly() { var resource = StubResource.WithContent(@"///<reference name=""MicrosoftAjax.js"" />"); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("assembly://System.Web.Extensions/MicrosoftAjax.js"); }
public void ReferenceElementWithNameAndAssemblyAttributeReturnsEmbeddedResourceVirtualPath() { var resource = StubResource.WithContent(@"///<reference name=""MyScript.js"" assembly=""MyAssembly"" />"); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("assembly://MyAssembly/MyScript.js"); }
public void TripleWackCommentReferenceElementWithPathAttributeIsParsedAsDependency() { var resource = StubResource.WithContent(@"///<reference path=""~/scripts/jquery.js"" />"); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("~/scripts/jquery.js"); }
public void WhenReferencePathPointsToVsDocFile_VsDocPartIsRemoved() { var resource = StubResource.WithContent(@"///<reference path=""~/scripts/jquery-1.4.4-vsdoc.js"" />"); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("~/scripts/jquery-1.4.4.js"); }
public void DependencyAttributeWithoutSemicolonAtTheEndIsStillParsed() { var resource = StubResource.WithContent(@"/* dependency:url(~/styles/mystylesheet.css) */"); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("~/styles/mystylesheet.css"); }
public void DependencyAttributeWithAppRelativeUrlIsParsedAsDependency() { var resource = StubResource.WithContent(@"/* dependency:url(~/styles/mystylesheet.css); */"); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("~/styles/mystylesheet.css"); }
private static IResource CreateResource(string content, DateTime lastModified) { StubResource resource1 = new StubResource(content); resource1.LastModified = lastModified; resource1.VirtualPath = "~/" + content + ".js"; return(resource1); }
public void ConsolidateGroupSortsResourcesByDependencies() { var dependencyLeaf1 = _context.CreateResource("~/dependency-leaf1.js").Resource; var dependencyLeaf2 = _context.CreateResource("~/dependency-leaf2.js").Resource; var dependencyRoot3 = _context.CreateResource("~/dependency-root3.js").Resource; var dependencyRoot1 = StubResource.WithPath("~/dependency-root1.js"); var dependencyRoot1Minified = _context.CreateResource("~/dependency-root1.min.js").Resource; var dependencyBranch1 = _context.CreateResource("~/dependency-branch1.js").Resource; var dependencyLeaf5 = _context.CreateResource("~/dependency-leaf5.js").Resource; var dependencyRoot2 = _context.CreateResource("~/dependency-root2.js").Resource; var dependencyBranch2 = _context.CreateResource("~/dependency-branch2.js").Resource; var dependencyLeaf4 = _context.CreateResource("~/dependency-leaf4.js").Resource; var dependencyLeaf3 = _context.CreateResource("~/dependency-leaf3.js").Resource; var group = new ResourceGroup("~/consolidated.js", new IResource[] { dependencyLeaf1, dependencyLeaf2, dependencyRoot1.ExternallyCompiledWith(dependencyRoot1Minified, ResourceMode.Release), dependencyRoot2, dependencyBranch1, dependencyLeaf3, dependencyRoot3, dependencyBranch2, dependencyLeaf4, dependencyLeaf5 }); var groupTemplate = new StubResourceGroupTemplate(group); groupTemplate.ResourceType = ResourceType.Script; _context.AddGlobalScriptDependencies(dependencyRoot1, dependencyRoot2, dependencyRoot3); _context.DependencyProvider.SetDependencies(dependencyBranch2, dependencyBranch1.VirtualPath); _context.DependencyProvider.SetDependencies(dependencyLeaf1, dependencyBranch1.VirtualPath); _context.DependencyProvider.SetDependencies(dependencyLeaf2, dependencyBranch1.VirtualPath); _context.DependencyProvider.SetDependencies(dependencyLeaf3, dependencyBranch2.VirtualPath); _context.DependencyProvider.SetDependencies(dependencyLeaf4, dependencyBranch2.VirtualPath); _context.DependencyProvider.SetDependencies(dependencyLeaf5, dependencyBranch1.VirtualPath, dependencyBranch2.VirtualPath); var consolidatedResource = _compiler.CompileGroup(group); var resources = consolidatedResource.Resources.ToList(); resources[0].VirtualPath.ShouldEqual(dependencyRoot1.VirtualPath); resources[1].VirtualPath.ShouldEqual(dependencyRoot2.VirtualPath); resources[2].VirtualPath.ShouldEqual(dependencyRoot3.VirtualPath); resources[3].VirtualPath.ShouldEqual(dependencyBranch1.VirtualPath); resources[4].VirtualPath.ShouldEqual(dependencyLeaf1.VirtualPath); resources[5].VirtualPath.ShouldEqual(dependencyLeaf2.VirtualPath); resources[6].VirtualPath.ShouldEqual(dependencyBranch2.VirtualPath); resources[7].VirtualPath.ShouldEqual(dependencyLeaf3.VirtualPath); resources[8].VirtualPath.ShouldEqual(dependencyLeaf4.VirtualPath); resources[9].VirtualPath.ShouldEqual(dependencyLeaf5.VirtualPath); }
public void WhenReferencePathIsRelative_ItIsResolvedRelativeToTheResource() { var resource = StubResource.WithContent(@"/* dependency:url(../styles/mystylesheet.css); */"); resource.VirtualPath = "~/Content/MyStylsheet.css"; var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("~/styles/mystylesheet.css"); }
public void WhenReferencePathIsRelative_ItIsResolvedRelativeToTheResource() { var resource = StubResource.WithContent(@"///<reference path=""../Shared/MyComponent.js"" />"); resource.VirtualPath = "~/Views/MyController/MyView.js"; var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(1); dependencies[0].ShouldEqual("~/Views/Shared/MyComponent.js"); }
public void WhenDependenciesAreCachedByVirtualPath_TheyAreReturnedFromThere() { var myscript = StubResource.WithPath("~/scripts/myscript.js"); IEnumerable <string> cachedDependencies = new string[] { "~/scripts/jquery.js" }; _dependencyCache.StoreDependencies(myscript, cachedDependencies); var returnedDependencies = _dependencyManager.GetDependencies(myscript.VirtualPath).ToList(); returnedDependencies.CountShouldEqual(1); returnedDependencies[0].ShouldEqual("~/scripts/jquery.js"); }
public void MultipleReferenceElementsAreRecognized() { var resource = StubResource.WithContent(@"///<reference path=""~/scripts/script1.js"" /> ///<reference path=""~/scripts/script2.js"" />" ); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(2); dependencies[0].ShouldEqual("~/scripts/script1.js"); dependencies[1].ShouldEqual("~/scripts/script2.js"); }
public void MultipleDependenciesAreRecognized() { var resource = StubResource.WithContent(@"/* dependency:url(~/styles/mystylesheet.css); dependency:url(~/styles/myotherstylesheet.css);*/" ); var dependencies = _provider.GetDependencies(resource).ToList(); dependencies.CountShouldEqual(2); dependencies[0].ShouldEqual("~/styles/mystylesheet.css"); dependencies[1].ShouldEqual("~/styles/myotherstylesheet.css"); }
public void SetupContext() { _httpItems = new Hashtable(); _httpContext = new Mock <HttpContextBase>(); _httpContext.SetupGet(c => c.Items).Returns(_httpItems); _cache = new HttpDependencyCache(() => _httpContext.Object); _resource = StubResource.WithPath("~/scripts/myscript.js"); _resource.LastModified = DateTime.Now.AddDays(-1); _dependencies = new string[] { "~/scripts/jquery.js", "~/scripts/site.js" }; _cache.StoreDependencies(_resource, _dependencies); }
public void GetDependenciesReturnsParsedDependencies() { var myscript = StubResource.WithPath("~/scripts/myscript.js"); _resourceFinder.AddResource(myscript); SetDependencies(myscript, "~/scripts/jquery.js", "~/scripts/common.js"); var dependencies = _dependencyManager.GetDependencies(myscript.VirtualPath).ToList(); dependencies[0].ShouldEqual("~/scripts/jquery.js"); dependencies[1].ShouldEqual("~/scripts/common.js"); }
public void GlobalDependenciesAreReturnedBeforeAllOthers() { var jquery = StubResource.WithPath("~/scripts/jquery.js"); var jquerypluginA = StubResource.WithPath("~/scripts/jquery-plugin-a.js"); var myscript = StubResource.WithPath("~/scripts/myscript.js"); _resourceFinder.AddResources(jquery, jquerypluginA, myscript); _scriptGroups.AddGlobalDependencies(new[] { jquery.VirtualPath }); SetDependencies(myscript, jquerypluginA.VirtualPath); var dependencies = _dependencyManager.GetDependencies(myscript.VirtualPath).ToList(); dependencies.CountShouldEqual(2); dependencies[0].ShouldEqual(jquery.VirtualPath); dependencies[1].ShouldEqual(jquerypluginA.VirtualPath); }
public void DependenciesAreRecursivelyCachedByBothVirtualPathAndResource() { var jquery = StubResource.WithPath("~/scripts/jquery.js"); var jquerypluginA = StubResource.WithPath("~/scripts/jquery-plugin-a.js"); var jquerypluginB = StubResource.WithPath("~/scripts/jquery-plugin-b.js"); var myscript = StubResource.WithPath("~/scripts/myscript.js"); _resourceFinder.AddResources(jquery, jquerypluginA, jquerypluginB, myscript); SetDependencies(jquerypluginB, jquery.VirtualPath, jquerypluginA.VirtualPath); SetDependencies(jquerypluginA, jquery.VirtualPath); SetDependencies(myscript, jquerypluginB.VirtualPath); _dependencyManager.GetDependencies(myscript.VirtualPath).ToList(); VerifyDependenciesAreCached(myscript.VirtualPath, jquery.VirtualPath, jquerypluginA.VirtualPath, jquerypluginB.VirtualPath); VerifyDependenciesAreCached(jquerypluginB.VirtualPath, jquery.VirtualPath, jquerypluginA.VirtualPath); VerifyDependenciesAreCached(jquerypluginA.VirtualPath, jquery.VirtualPath); }
public void WhenConsolidatedUrlMatchesPatternOfAGroup_ItIsNotIncludedInTheConsolidatedResource() { var jquery = StubResource.WithPath("~/scripts/jquery.js"); var component = StubResource.WithPath("~/scripts/component.js"); var core = StubResource.WithPath("~/scripts/core.js"); var otherscript = StubResource.WithPath("~/scripts/otherscript.js"); var finder = new StubResourceFinder(); finder.AddResources(jquery, component, core, otherscript); var group1 = new ResourceGroup("~/scripts/core.js", new IResource[] { jquery, component }); var group2 = new ResourceGroup("~/scripts/everything-else.js", new IResource[] { core, otherscript }); _context.AddFinder(finder); var group1Template = new StubResourceGroupTemplate(group1) { ResourceType = ResourceType.Script }; var group2Template = new StubResourceGroupTemplate(group2) { ResourceType = ResourceType.Script }; _context.ScriptGroups.Add(group1Template); _context.ScriptGroups.Add(group2Template); var consolidator = _context.GetConsolidator(); var preConsolidationReport = consolidator.CompileAll((resource) => { }); var group2Consolidated = preConsolidationReport.Scripts.Groups.Where(g => g.ConsolidatedUrl == "~/scripts/everything-else.js").Single(); group2Consolidated.Resources.CountShouldEqual(1); group2Consolidated.Resources[0].ShouldEqual("~/scripts/otherscript.js"); }
public void GetDependenciesReturnsRecursiveDependenciesInOrder() { var jquery = StubResource.WithPath("~/scripts/jquery.js"); var jquerypluginA = StubResource.WithPath("~/scripts/jquery-plugin-a.js"); var jquerypluginB = StubResource.WithPath("~/scripts/jquery-plugin-b.js"); var myscript = StubResource.WithPath("~/scripts/myscript.js"); _resourceFinder.AddResources(jquery, jquerypluginA, jquerypluginB, myscript); SetDependencies(jquerypluginB, jquery.VirtualPath, jquerypluginA.VirtualPath); SetDependencies(jquerypluginA, jquery.VirtualPath); SetDependencies(myscript, jquerypluginB.VirtualPath); var dependencies = _dependencyManager.GetDependencies(myscript.VirtualPath).ToList(); dependencies.CountShouldEqual(3); dependencies[0].ShouldEqual(jquery.VirtualPath); dependencies[1].ShouldEqual(jquerypluginA.VirtualPath); dependencies[2].ShouldEqual(jquerypluginB.VirtualPath); }
public void ResourceCanBeInMultipleGroupsIfExplicitlyPrevented() { var jquery = StubResource.WithPath("~/scripts/jquery.js"); var componentA = StubResource.WithPath("~/scripts/componentA.js"); var componentB = StubResource.WithPath("~/scripts/componentB.js"); var finder = new StubResourceFinder(); finder.AddResources(jquery, componentA, componentB); _context.AddFinder(finder); _context.MutuallyExclusiveGroups = false; var pageAGroup = new ResourceGroup("~/scripts/compiled/pageA.js", new[] { jquery, componentA }); _context.ScriptGroups.Add(new StubResourceGroupTemplate(pageAGroup) { ResourceType = ResourceType.Script }); var pageBGroup = new ResourceGroup("~/scripts/compiled/pageB.js", new[] { jquery, componentB }); _context.ScriptGroups.Add(new StubResourceGroupTemplate(pageBGroup) { ResourceType = ResourceType.Script }); var report = CompileAll(); var pageAGroupReport = report.Scripts.Groups.Single(g => g.ConsolidatedUrl == "~/scripts/compiled/pageA.js"); var pageBGroupReport = report.Scripts.Groups.Single(g => g.ConsolidatedUrl == "~/scripts/compiled/pageB.js"); pageAGroupReport.Resources.CountShouldEqual(2); pageBGroupReport.Resources.CountShouldEqual(2); }
public void ResourceCanOnlyBeInOneGroupByDefault() { var jquery = StubResource.WithPath("~/scripts/jquery.js"); var componentA = StubResource.WithPath("~/scripts/componentA.js"); var componentB = StubResource.WithPath("~/scripts/componentB.js"); var finder = new StubResourceFinder(); finder.AddResources(jquery, componentA, componentB); _context.AddFinder(finder); var pageAGroup = new ResourceGroup("~/scripts/compiled/pageA.js", new[] { jquery, componentA }); _context.ScriptGroups.Add(new StubResourceGroupTemplate(pageAGroup) { ResourceType = ResourceType.Script }); var pageBGroup = new ResourceGroup("~/scripts/compiled/pageB.js", new[] { jquery, componentB }); _context.ScriptGroups.Add(new StubResourceGroupTemplate(pageBGroup) { ResourceType = ResourceType.Script }); var report = CompileAll(); var pageAGroupReport = report.Scripts.Groups.Single(g => g.ConsolidatedUrl == "~/scripts/compiled/pageA.js"); var pageBGroupReport = report.Scripts.Groups.Single(g => g.ConsolidatedUrl == "~/scripts/compiled/pageB.js"); pageAGroupReport.Resources.CountShouldEqual(2); pageBGroupReport.Resources.CountShouldEqual(1); }