public void only_group_by_the_same_folder()
        {
            var files = new AssetFile[] {
                new AssetFile("a.css"),
                new AssetFile("b.css"),
                new AssetFile("f1/c.css"),
                new AssetFile("f1/d.css"),
                new AssetFile("e.css"),
                new AssetFile("f2/f.css"),
                new AssetFile("f2/g.css")
            };

            var plan = new AssetTagPlan(MimeType.Css, files);

            var policy = new CombineAllStylesheets();
            var combos = policy.DetermineCombinations(plan);

            combos.Count().ShouldEqual(3);

            combos.ElementAt(0).Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("a.css", "b.css");

            combos.ElementAt(1).Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("f1/c.css", "f1/d.css");
            combos.ElementAt(1).ShouldBeOfType <StyleFileCombination>().Name.ShouldStartWith("f1/");

            combos.ElementAt(2).Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("f2/f.css", "f2/g.css");
            combos.ElementAt(2).ShouldBeOfType <StyleFileCombination>().Name.ShouldStartWith("f2/");
        }
        private void run_with_plan(AssetTagPlan plan)
        {
            ClassUnderTest.TryToReplaceWithCombinations(plan);

            plan.Subjects.ShouldHaveCount(1)
            .First().MimeType.ShouldEqual(plan.MimeType);
        }
Example #3
0
        public void only_requests_the_plan_once()
        {
            var key1 = new AssetPlanKey(MimeType.Javascript, new string[] { "a.js", "b.js", "c.js" });
            var key2 = new AssetPlanKey(MimeType.Javascript, new string[] { "d.js", "b.js", "c.js" });
            var key3 = new AssetPlanKey(MimeType.Javascript, new string[] { "e.js", "b.js", "c.js" });

            var otherKey = new AssetPlanKey(MimeType.Javascript, key1.Names);

            otherKey.ShouldEqual(key1);

            var plan1 = new AssetTagPlan(MimeType.Javascript);
            var plan2 = new AssetTagPlan(MimeType.Javascript);
            var plan3 = new AssetTagPlan(MimeType.Javascript);

            var planner = MockFor <IAssetTagPlanner>();

            planner.Expect(x => x.BuildPlan(key1)).Return(plan1).Repeat.Once();
            planner.Expect(x => x.BuildPlan(key2)).Return(plan2).Repeat.Once();
            planner.Expect(x => x.BuildPlan(key3)).Return(plan3).Repeat.Once();

            ClassUnderTest.PlanFor(key1.MimeType, key1.Names).ShouldBeTheSameAs(plan1);
            ClassUnderTest.PlanFor(key1.MimeType, key1.Names).ShouldBeTheSameAs(plan1);
            ClassUnderTest.PlanFor(key1.MimeType, key1.Names).ShouldBeTheSameAs(plan1);

            ClassUnderTest.PlanFor(key2.MimeType, key2.Names).ShouldBeTheSameAs(plan2);
            ClassUnderTest.PlanFor(key2.MimeType, key2.Names).ShouldBeTheSameAs(plan2);
            ClassUnderTest.PlanFor(key2.MimeType, key2.Names).ShouldBeTheSameAs(plan2);

            ClassUnderTest.PlanFor(key3.MimeType, key3.Names).ShouldBeTheSameAs(plan3);
            ClassUnderTest.PlanFor(key3.MimeType, key3.Names).ShouldBeTheSameAs(plan3);
            ClassUnderTest.PlanFor(key3.MimeType, key3.Names).ShouldBeTheSameAs(plan3);

            planner.VerifyAllExpectations();
        }
Example #4
0
        public void negative_match_because_the_mimetype_is_all_wrong()
        {
            var assetFiles   = new [] { _files["a"], _files["b"] };
            var thePlan      = new AssetTagPlan(MimeType.Css, assetFiles);
            var theCandidate = new CombinationCandidate(MimeType.Javascript, "c1", assetFiles);

            theCandidate.DetermineCombinations(thePlan).Any().ShouldBeFalse();
        }
 private static void validateMatchingMimetypes(MimeType mimeType, AssetTagPlan plan, IEnumerable <string> names)
 {
     if (plan.Subjects.Any(x => x.MimeType != mimeType))
     {
         var message = "Files {0} have mixed mimetype's".ToFormat(names.Join(", "));
         throw new MixedMimetypeException(message);
     }
 }
Example #6
0
        public void tags_for_plan_should_pull_the_plan_from_the_cache_before_building()
        {
            var tags    = new HtmlTag[0];
            var key     = AssetPlanKey.For(MimeType.Javascript, "a.js");
            var thePlan = new AssetTagPlan(MimeType.Javascript);

            MockFor <IAssetTagPlanCache>().Stub(x => x.PlanFor(key)).Return(thePlan);
            MockFor <IAssetTagBuilder>().Stub(x => x.Build(thePlan)).Return(tags);

            ClassUnderTest.TagsForPlan(key).ShouldBeTheSameAs(tags);
        }
        public void when_writing_a_style_tag()
        {
            MockFor <IMissingAssetHandler>().Stub(x => x.BuildTagsAndRecord(null))
            .Return(new HtmlTag[0])
            .IgnoreArguments();

            MockFor <IUrlRegistry>().Stub(x => x.UrlForAsset(AssetFolder.styles, "main.css"))
            .Return("http://myapp/_content/styles/main.css");

            var file = new AssetFile("main.css", AssetFolder.styles);
            var plan = AssetTagPlan.For(MimeType.Css, file);

            var tag = ClassUnderTest.Build(plan).Single();

            tag.ToString().ShouldEqual("<link href=\"http://myapp/_content/styles/main.css\" rel=\"stylesheet\" type=\"text/css\" />");
        }
        public void when_writing_a_script_tag()
        {
            MockFor <IMissingAssetHandler>().Stub(x => x.BuildTagsAndRecord(null))
            .Return(new HtmlTag[0])
            .IgnoreArguments();

            MockFor <IUrlRegistry>().Stub(x => x.UrlForAsset(AssetFolder.scripts, "script.js"))
            .Return("http://myapp/_content/scripts/script.js");

            var file = new AssetFile("script.js", AssetFolder.scripts);
            var plan = AssetTagPlan.For(MimeType.Javascript, file);

            var tag = ClassUnderTest.Build(plan).Single();

            tag.ToString().ShouldEqual("<script type=\"application/javascript\" src=\"http://myapp/_content/scripts/script.js\"></script>");
        }
        public void apply_to_an_asset_tag_plan_simple_condition_of_all_files()
        {
            var files = new AssetFile[] {
                new AssetFile("a.js"),
                new AssetFile("b.js"),
                new AssetFile("c.js"),
                new AssetFile("d.js")
            };

            var plan = new AssetTagPlan(MimeType.Javascript, files);

            var policy = new CombineAllScriptFiles();

            var combo = policy.DetermineCombinations(plan).Single();

            combo.Files.ShouldHaveTheSameElementsAs(files);
        }
        public AssetTagPlan BuildPlan(MimeType mimeType, IEnumerable <string> names)
        {
            var plan = new AssetTagPlan(mimeType);

            plan.AddSubjects(FindSubjects(names));

            validateMatchingMimetypes(mimeType, plan, names);

            if (plan.Subjects.Count == 1)
            {
                return(plan);
            }

            _combinations.TryToReplaceWithCombinations(plan);

            return(plan);
        }
        public void when_writing_a_tag_plan_with_missing_assets()
        {
            var file     = new AssetFile("main.css", AssetFolder.styles);
            var missing1 = new MissingAssetTagSubject("main.css");
            var missing2 = new MissingAssetTagSubject("other.css");
            var plan     = AssetTagPlan.For(MimeType.Css, file, missing1, missing2);

            var handler = new StubMissingAssetHandler();

            Services.Inject <IMissingAssetHandler>(handler);

            var allTags = ClassUnderTest.Build(plan);

            allTags.Count().ShouldEqual(3);

            handler.Subjects.ShouldHaveTheSameElementsAs(missing1, missing2);

            allTags.Contains(handler.Tags.First());
            allTags.Contains(handler.Tags.Last());
        }
Example #12
0
        public IEnumerable <HtmlTag> Build(AssetTagPlan plan)
        {
            // This will happen when a user tries to request an asset set
            // with no assets -- think optional sets
            if (!plan.Subjects.Any())
            {
                return(new HtmlTag[0]);
            }

            IEnumerable <MissingAssetTagSubject>     missingSubjects = plan.RemoveMissingAssets();
            Func <IAssetTagSubject, string, HtmlTag> func            = _builders[plan.MimeType];
            Func <IAssetTagSubject, HtmlTag>         builder         = s => {
                string url = _urls.UrlForAsset(s.Folder, s.Name);
                return(func(s, url));
            };

            IEnumerable <HtmlTag> missingTags = _missingHandler.BuildTagsAndRecord(missingSubjects);
            IEnumerable <HtmlTag> assetTags   = plan.Subjects.Select(builder);

            return(missingTags.Union(assetTags));
        }
        public void skip_over_non_files_in_the_plan()
        {
            var files = new IAssetTagSubject[] {
                new AssetFile("a.js"),
                new AssetFile("b.js"),
                new MissingAssetTagSubject("something.wrong"),
                new AssetFile("c.js"),
                new AssetFile("d.js"),
                new MissingAssetTagSubject("else.wrong"),
                new AssetFile("e.js")
            };

            var plan = new AssetTagPlan(MimeType.Javascript);

            plan.AddSubjects(files);

            var combos = new CombineAllScriptFiles().DetermineCombinations(plan);

            combos.Count().ShouldEqual(2);

            combos.First().Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("a.js", "b.js");
            combos.Last().Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("c.js", "d.js");
        }
Example #14
0
 public override void ExecutePolicy(AssetTagPlan plan, ICombinationPolicy policy)
 {
     Policies.Add(policy);
 }
Example #15
0
 public IEnumerable <AssetFileCombination> DetermineCombinations(AssetTagPlan plan)
 {
     throw new NotImplementedException();
 }
Example #16
0
 public void TryToReplaceWithCombinations(AssetTagPlan plan)
 {
     // That's right, do nothing
 }