Exemple #1
0
        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);
        }
Exemple #2
0
        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 SetupContext()
        {
            _finder = new StubResourceFinder();

            _context = AssmanContext.Create(ResourceMode.Release);
            _context.ManageDependencies = true;
            _context.AddFinder(_finder);
            _accessor = new ConsolidatingResourceRegistryAccessor(_context);
        }
Exemple #4
0
 public ResourceTestContext(ResourceMode resourceMode = ResourceMode.Debug)
 {
     Mode    = resourceMode;
     _finder = new StubResourceFinder();
     _contentFilterPipelineMap = new ContentFilterPipelineMap();
     _scriptGroups             = new ResourceGroupManager(Mode);
     _styleGroups        = new ResourceGroupManager(Mode);
     _dependencyCache    = new InMemoryDependencyCache();
     _dependencyProvider = new StubDependencyProvider();
     _dependencyManager  = new DependencyManager(_finder, _dependencyCache, _scriptGroups, _styleGroups);
     _dependencyManager.MapProvider(".js", _dependencyProvider);
     _dependencyManager.MapProvider(".css", _dependencyProvider);
 }
 public ResourceTestContext(ResourceMode resourceMode = ResourceMode.Debug)
 {
     Mode = resourceMode;
     _innerFinder = new StubResourceFinder();
     _outerFinder = new ResourceModeFilteringFinder(resourceMode, _innerFinder);
     _contentFilterPipelineMap = new ContentFilterPipelineMap();
     _scriptGroups = new ResourceGroupManager(Mode);
     _styleGroups = new ResourceGroupManager(Mode);
     _dependencyCache = new InMemoryDependencyCache();
     _dependencyProvider = new StubDependencyProvider();
     _dependencyManager = new DependencyManager(_outerFinder, _dependencyCache, _scriptGroups, _styleGroups, resourceMode);
     _dependencyManager.MapProvider(".js", _dependencyProvider);
     _dependencyManager.MapProvider(".css", _dependencyProvider);
 }
        public void FindResourcesCombinesResultsOfChildren()
        {
            StubResourceFinder finder1 = new StubResourceFinder();
            finder1.AddResource("~/myfile1.js", "content1");
            finder1.AddResource("~/myfile2.js", "content2");
            _instance.AddFinder(finder1);

            StubResourceFinder finder2 = new StubResourceFinder();
            finder2.AddResource("assembly://MyAssembly/MyNamespace.Myfile1.js", "content3");
            _instance.AddFinder(finder2);

            var resources = _instance.FindResources(ResourceType.Script).ToList();
            Assert.That(resources, Is.Not.Null);
            Assert.That(resources.Count, Is.EqualTo(3));
            Assert.That(resources[0].VirtualPath, Is.EqualTo("~/myfile1.js"));
            Assert.That(resources[1].VirtualPath, Is.EqualTo("~/myfile2.js"));
            Assert.That(resources[2].VirtualPath, Is.EqualTo("assembly://MyAssembly/MyNamespace.Myfile1.js"));
        }
        private void SetupWithMode(ResourceMode resourceMode)
        {
            _dependencyProvider = new StubDependencyProvider();
            _resourceFinder = new StubResourceFinder();
            _dependencyCache = new InMemoryDependencyCache();
            _scriptGroups = new ResourceGroupManager(resourceMode);
            _styleGroups = new ResourceGroupManager(resourceMode);

            _dependencyManager = new DependencyManager(new ResourceModeFilteringFinder(resourceMode, _resourceFinder), _dependencyCache, _scriptGroups, _styleGroups,
                                                       resourceMode);
            _dependencyManager.MapProvider(".js", _dependencyProvider);
        }
        public void Init()
        {
            _finder = new StubResourceFinder();
            _finder.CreateResource(myScript);
            _finder.CreateResource(mySecondScript);
            _finder.CreateResource(excludedScript);

            _dependencyProvider = new StubDependencyProvider();
            DependencyManagerFactory.ClearDependencyCache();

            _context = AssmanContext.Create(ResourceMode.Debug);
            _context.ConsolidateScripts = true;
            _context.ConfigurationLastModified = DateTime.MinValue;
            _context.AddFinder(_finder);
            _context.MapExtensionToDependencyProvider(".js", _dependencyProvider);
            _groupElement = new ScriptGroupElement();
            _groupElement.ConsolidatedUrl = consolidatedScript;
            _groupElement.Exclude.AddPattern(excludedScript);
            _context.ScriptGroups.Add(_groupElement);

            _registry = new ConsolidatingResourceRegistry(new ResourceRequirementCollection(), "Default", _context.ScriptPathResolver, new ConfiguredVersioningStrategy(() => _context.Version));
        }
Exemple #9
0
        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");
        }
Exemple #10
0
 public void SetupContext()
 {
     DependencyManagerFactory.ClearDependencyCache();
     _finder = new StubResourceFinder();
     _context = new AssmanContext(ResourceMode.Release);
     _context.AddFinder(_finder);
 }