public Given_a_UnresolvedJavaScriptParser_When_Parse_source_with_two_references()
 {
     using (var sourceStream = CreateSourceStream())
     {
         parser = new UnresolvedJavaScriptParser();
         script = parser.Parse(sourceStream, sourcePath);
     }
 }
 public Given_a_UnresolvedCssParser_When_Parse_source_with_two_references()
 {
     using (var sourceStream = CreateSourceStream())
     {
         parser = new UnresolvedCssParser("/");
         stylesheet = parser.Parse(sourceStream, sourcePath);
     }
 }
 public Given_a_UnresolvedJavaScriptParser_When_Parse_source_with_two_references()
 {
     using (var sourceStream = CreateSourceStream())
     {
         parser = new UnresolvedJavaScriptParser();
         script = parser.Parse(sourceStream, sourcePath);
     }
 }
 public Given_a_UnresolvedCssParser_When_Parse_source_with_two_references()
 {
     using (var sourceStream = CreateSourceStream())
     {
         parser     = new UnresolvedCssParser("/");
         stylesheet = parser.Parse(sourceStream, sourcePath);
     }
 }
 public void Resolve_when_path_is_just_tilde_throws_ArgumentException()
 {
     var resource = new UnresolvedResource(
         "module-a/test.js",
         new byte[0],
         new[] { "~" }
     );
     Assert.Throws<ArgumentException>(delegate
     {
         resource.Resolve(path => false);
     });
 }
 public void Resolve_when_path_has_too_many_dotdots_throws_ArgumentException()
 {
     var resource = new UnresolvedResource(
         "module-a/test.js",
         new byte[0],
         new[] { "../../fail.js" }
     );
     Assert.Throws<ArgumentException>(delegate
     {
         resource.Resolve(path => false);
     });
 }
Beispiel #7
0
        public void Resolve_when_path_is_empty_throws_ArgumentException()
        {
            var resource = new UnresolvedResource(
                "module-a/test.js",
                new byte[0],
                new[] { "" }
                );

            Assert.Throws <ArgumentException>(delegate
            {
                resource.Resolve(path => false);
            });
        }
Beispiel #8
0
        public void Resolve_when_app_rooted_path_has_too_many_dotdots_throws_ArgumentException()
        {
            var resource = new UnresolvedResource(
                "module-a/test.js",
                new byte[0],
                new[] { "~/../../fail.js" }
                );

            Assert.Throws <ArgumentException>(delegate
            {
                resource.Resolve(path => false);
            });
        }
Beispiel #9
0
        public Resolve_a_UnresolvedModule_with_script_having_an_external_reference()
        {
            var script = new UnresolvedResource(
                @"scripts/module-a/test.js",
                new byte[0],
                new[] { @"scripts/module-b/lib.js" }
                );

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script },
                null,
                false
                );

            module = unresolvedModule.Resolve(s => @"scripts/module-b");
        }
        public Resolve_an_UnresolvedModule_with_scripts_in_subdirectory()
        {
            var script1 = new UnresolvedResource(
                @"scripts/module-a/sub/test-1.js",
                new byte[0],
                new[] { @"test-2.js" }
            );
            var script2 = new UnresolvedResource(
                @"scripts/module-a/sub/test-2.js",
                new byte[0],
                new string[] { }
            );
            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script1, script2 },
                null,
                false
            );

            module = unresolvedModule.Resolve(s => @"scripts/module-a");
        }
Beispiel #11
0
        public Resolve_an_UnresolvedModule_with_scripts_in_subdirectory()
        {
            var script1 = new UnresolvedResource(
                @"scripts/module-a/sub/test-1.js",
                new byte[0],
                new[] { @"test-2.js" }
                );
            var script2 = new UnresolvedResource(
                @"scripts/module-a/sub/test-2.js",
                new byte[0],
                new string[] { }
                );

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script1, script2 },
                null,
                false
                );

            module = unresolvedModule.Resolve(s => @"scripts/module-a");
        }
 Tuple<Resource, string[]>[] PartitionResourceReferences(UnresolvedResource[] resources, HashSet<string> pathsInModule)
 {
     return resources.Select(
         resource => resource.Resolve(pathsInModule.Contains)
     ).ToArray();
 }
        public Resolve_a_UnresolvedModule_with_script_having_an_external_reference()
        {
            var script = new UnresolvedResource(
                @"scripts/module-a/test.js",
                new byte[0],
                new[] { @"scripts/module-b/lib.js" }
            );

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script },
                null,
                false
            );

            module = unresolvedModule.Resolve(s => @"scripts/module-b");
        }
Beispiel #14
-1
        /// <param name="path">Application relative path to the module directory.</param>
        /// <param name="resources">All the unresolved resources found in the module.</param>
        /// <param name="isResourceOrderFixed">When true, the resources will not be sorted by their dependency ordering.</param>
        public UnresolvedModule(string path, UnresolvedResource[] resources, string location, bool isResourceOrderFixed)
        {
            this.path = path;
            this.location = location;

            var pathsInModule = new HashSet<string>(resources.Select(resource => resource.Path));
            partition = PartitionResourceReferences(resources, pathsInModule);
            // Store all the references to external resources.
            this.externalReferences = partition.SelectMany(p => p.Item2).Distinct().ToArray();
            // The resources now only contain references found in this module.
            var resolvedResources = partition.Select(p => p.Item1).ToArray();
            if (isResourceOrderFixed)
            {
                this.resources = resolvedResources;
            }
            else
            {
                this.resources = OrderScriptsByDependency(resolvedResources);
            }
        }