public void WhenPreConsolidatedReportIsLoaded_ConsolidatedUrlsAreCachedAsThemselvesSoGroupsCanBeIncludedDirectly() { var groupTemplate = new Mock<IResourceGroupTemplate>(); _context.ScriptGroups.Add(groupTemplate.Object); var preConsolidationReport = new PreCompilationReport(); var scriptGroup = new PreCompiledResourceGroup { ConsolidatedUrl = "~/scripts/consolidated/common.js", Resources = new List<string> { "~/scripts/myscript.js" } }; preConsolidationReport.Scripts.Groups.Add(scriptGroup); _context.LoadPreCompilationReport(preConsolidationReport); var resolvedUrl = _context.ScriptPathResolver.GetMatchingGroupUrls("~/scripts/consolidated/common.js").Single(); resolvedUrl.ShouldEqual("~/scripts/consolidated/common.js"); //verify that the group template was not looked at (that proves the value came from the prepopulated cache) string consolidatedUrl; groupTemplate.Verify(t => t.TryGetConsolidatedUrl(It.IsAny<string>(), It.IsAny<ResourceMode>(), out consolidatedUrl), Times.Never()); }
public void AfterPreConsolidatedReportIsLoaded_WhenUrlForFileThatDoesNotExistButWhosePatternMatchesGroup_ItsGroupUrlCanStillBeResolved() { var group = new ScriptGroupElement(); group.ConsolidatedUrl = "~/scripts/consolidated/common.js"; group.Include.AddPattern("~/scripts/.+"); _context.ScriptGroups.Add(group); var preConsolidationReport = new PreCompilationReport(); var scriptGroup = new PreCompiledResourceGroup { ConsolidatedUrl = "~/scripts/consolidated/common.js", Resources = new List<string> { "~/scripts/myscript.js" } }; preConsolidationReport.Scripts.Groups.Add(scriptGroup); _context.LoadPreCompilationReport(preConsolidationReport); var resolvedUrl = _context.ScriptPathResolver.GetMatchingGroupUrls("~/scripts/bogusscript.js").Single(); resolvedUrl.ShouldEqual("~/scripts/consolidated/common.js"); }
private IEnumerable<PreCompiledResourceGroup> ConsolidateGroupsInternal(ResourceType resourceType, IResourceGroupManager groupTemplates, Action<ICompiledResource> onCompiled) { if (!groupTemplates.Any()) return Enumerable.Empty<PreCompiledResourceGroup>(); var allResources = _finder.FindResources(resourceType).ToArray(); var preConsolidatedGroups = new List<PreCompiledResourceGroup>(); groupTemplates.EachGroup(allResources, group => { var consolidatedResource = CompileGroup(group); onCompiled(consolidatedResource); var preConsolidatedGroup = new PreCompiledResourceGroup { ConsolidatedUrl = group.ConsolidatedUrl, Resources = consolidatedResource.Resources.Select(resource => resource.VirtualPath).ToList() }; preConsolidatedGroups.Add(preConsolidatedGroup); }); return preConsolidatedGroups; }