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); }
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 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); }
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 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 preConsolidationReport = CompileAll(); var group2Consolidated = preConsolidationReport.Scripts.Groups.Single(g => g.ConsolidatedUrl == "~/scripts/everything-else.js"); group2Consolidated.Resources.CountShouldEqual(1); group2Consolidated.Resources[0].ShouldEqual("~/scripts/otherscript.js"); }