public void WillTransformJsAdjacentToComment() { var testable = new TestableResponseTransformer(); var transform = @" <script src=""http://server/Me.js"" type=""text/javascript"" ></script> <!-- this is a nice comment --> <script src=""http://server/Me2.js"" type=""text/javascript"" ></script> "; var transformed = @" <script src=""http://server/Me3.js"" type=""text/javascript"" ></script> <!-- this is a nice comment --> "; testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me.js::http://server/Me2.js::")).Returns("http://server/Me3.js"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); }
public void WillQueueUrlsWithoutHostIfNoContentHost(string contentHost) { var testable = new TestableResponseTransformer(); var transform = @"<head> <meta name=""description"" content="""" /> <link href=""http://server/Me.css"" rel=""Stylesheet"" type=""text/css"" /> <link href=""http://server/Me2.css"" rel=""Stylesheet"" type=""text/css"" /> <title>site</title></head> "; testable.Mock <IReductionRepository>().Setup( x => x.FindReduction("http://server/Me.css::http://server/Me2.css::")); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); testable.Mock <IRRConfiguration>().Setup(x => x.ContentHost).Returns(contentHost); testable.ClassUnderTest.Transform(transform); testable.Mock <IReducingQueue>().Verify(x => x.Enqueue(It.Is <QueueItem <CssResource> >(y => y.Urls == "http://server/Me.css::http://server/Me2.css::" && y.Host == string.Empty)), Times.Once()); }
public void WillNotMergeScriptsIntermingledWitIgnoredScriptsInorderToMaintainScriptOrder() { var testable = new TestableResponseTransformer(); var transform = @"<script src=""http://server/Me.js"" type=""text/javascript"" ></script><script src=""http://server/Me2.js"" type=""text/javascript"" ></script><script src=""http://server/ignore/Me.js"" type=""text/javascript"" ></script> <script src=""http://server/Me3.js"" type=""text/javascript"" ></script><script src=""http://server/Me4.js"" type=""text/javascript"" ></script>"; var transformed = @"<script src=""http://server/Me5.js"" type=""text/javascript"" ></script><script src=""http://server/ignore/Me.js"" type=""text/javascript"" ></script> <script src=""http://server/Me6.js"" type=""text/javascript"" ></script>"; testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me.js::http://server/Me2.js::")).Returns("http://server/Me5.js"); testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me3.js::http://server/Me4.js::")).Returns("http://server/Me6.js"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); var config = new Mock <IRRConfiguration>(); config.Setup(x => x.JavaScriptUrlsToIgnore).Returns("server/Ignore, server/alsoignore"); RRContainer.Current = new Container(x => x.For <IRRConfiguration>().Use(config.Object)); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); RRContainer.Current = null; }
public void WillTransformSigleQuotedStyles() { var testable = new TestableResponseTransformer(); var transform = @"<head id=""Head1""> <meta name=""description"" content="""" /> <link href='http://server/Me.css' rel='Stylesheet' type='text/css' /> <link href='http://server/Me2.css' rel='Stylesheet' type='text/css' /> <title>site</title></head> "; var transformed = @"<head id=""Head1""> <meta name=""description"" content="""" /> <link href=""http://server/Me3.css"" rel=""Stylesheet"" type=""text/css"" /><title>site</title></head> "; testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me.css::http://server/Me2.css::")).Returns("http://server/Me3.css"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); }
public void WillNotTransformCssIgnoredByFilter() { var testable = new TestableResponseTransformer(); var transform = @"<head id=""Head1""> <link href=""http://server/Me.css"" rel=""Stylesheet"" type=""text/css"" /> <link href=""http://server/Me2.css"" rel=""Stylesheet"" type=""text/css"" /> <link href=""http://server/Me3.css"" rel=""Stylesheet"" type=""text/css"" /></head> "; var transformed = @"<head id=""Head1""> <link href=""http://server/Me4.css"" rel=""Stylesheet"" type=""text/css"" /><link href=""http://server/Me3.css"" rel=""Stylesheet"" type=""text/css"" /></head> "; testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me.css::http://server/Me2.css::")).Returns("http://server/Me4.css"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); Registry.AddFilter(new CssFilter(x => x.FilteredUrl.Contains("3"))); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); RRContainer.Current = null; }
public void WillTransformToSingleScriptAtBeginningOfHeadOnMatch() { var testable = new TestableResponseTransformer(); var transform = @"<head id=""Head1""> <meta name=""description"" content="""" /> <script src=""http://server/Me.js"" type=""text/javascript"" ></script> <script src=""http://server/Me2.js"" type=""text/javascript"" ></script> <title>site</title></head> "; var transformed = @"<head id=""Head1""> <meta name=""description"" content="""" /> <script src=""http://server/Me3.js"" type=""text/javascript"" ></script><title>site</title></head> "; testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me.js::http://server/Me2.js::")).Returns("http://server/Me3.js"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); }
public void WillNotPlaceTransformedCssInsideConditionallyCommentedScriptBlock() { var testable = new TestableResponseTransformer(); var transform = @"<head id=""Head1""> <!--[if IE 6]><script src=""http://server/Me.js""></script> <script src=""http://server/Me4.js""></script><![endif]--> <link href=""http://server/Me.css"" rel=""Stylesheet"" type=""text/css"" /> <link href=""http://server/Me2.css"" rel=""Stylesheet"" type=""text/css"" /></head> "; var transformed = @"<head id=""Head1""> <!--[if IE 6]><script src=""http://server/Me.js""></script> <script src=""http://server/Me4.js""></script><![endif]--> <link href=""http://server/Me3.css"" rel=""Stylesheet"" type=""text/css"" /></head> "; testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me.css::http://server/Me2.css::")).Returns("http://server/Me3.css"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); RRContainer.Current = null; }
public void WillTransformHeadWithDuplicateScriptsAndInlineScript() { var testable = new TestableResponseTransformer(); var transform = @"<head> <script src=""http://server/script1.js"" type=""text/javascript"" ></script> <script src=""http://server/script2.js"" type=""text/javascript"" ></script> <script type=""text/javascript"" >here is some sphisticated javascript</script> <script src=""http://server/script1.js"" type=""text/javascript"" ></script> <title>site</title></head> "; var transformed = @"<head> <script src=""http://server/script4.js"" type=""text/javascript"" ></script><script type=""text/javascript"" >here is some sphisticated javascript</script> <script src=""http://server/script5.js"" type=""text/javascript"" ></script><title>site</title></head> "; testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/script1.js::http://server/script2.js::")).Returns("http://server/script4.js"); testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/script1.js::")).Returns("http://server/script5.js"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); testable.Mock <IRRConfiguration>().Setup(x => x.JavaScriptUrlsToIgnore).Returns("server/script3.js"); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); }
public void WillInjectCssCorrectlyWhenCommentsAreBeforeScripts() { var testable = new TestableResponseTransformer(); var transform = @" <!-- this is a nice comment --> <script src=""http://server/ignore/Me.js"" type=""text/javascript"" ></script> <link href=""http://server/Me.css"" rel=""Stylesheet"" type=""text/css"" /> "; var transformed = @" <!-- this is a nice comment --> <link href=""http://server/Me2.css"" rel=""Stylesheet"" type=""text/css"" /><script src=""http://server/ignore/Me.js"" type=""text/javascript"" ></script> "; var config = new Mock <IRRConfiguration>(); config.Setup(x => x.JavaScriptUrlsToIgnore).Returns("server/Ignore"); RRContainer.Current = new Container(x => x.For <IRRConfiguration>().Use(config.Object)); testable.Mock <IReductionRepository>().Setup(x => x.FindReduction("http://server/Me.css::")).Returns("http://server/Me2.css"); testable.Mock <HttpContextBase>().Setup(x => x.Request.Url).Returns(new Uri("http://server/megah")); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); RRContainer.Current = null; }