public void WillNotTransformScriptsIgnoredByFilter() { 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> <script src=""http://server/ignore/Me.js"" type=""text/javascript"" ></script> <script src=""http://server/alsoignore/Me.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> <script src=""http://server/ignore/Me.js"" type=""text/javascript"" ></script> <script src=""http://server/alsoignore/Me.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")); Registry.AddFilter(new JavascriptFilter(x => x.FilteredUrl.Contains("ignore"))); var result = testable.ClassUnderTest.Transform(transform); Assert.Equal(transformed, result); RRContainer.Current = null; }
public void WillPlugFilterIntoContainer() { Registry.AddFilter <TestFilter>(); Assert.NotNull(RRContainer.Current.GetAllInstances <IFilter>().Where(x => x is CssFilter)); RRContainer.Current = null; }
public void WillNotAddImageToSpriteContainerIfTheRegistryFiltersIt() { var testable = new TestableSpriteManager(); var image = new BackgroundImageClass("", "http://server/content/style.css") { ImageUrl = "", Width = 110 }; Registry.AddFilter(new SpriteFilter(x => x.BackgroundImage.Width > 100)); testable.ClassUnderTest.Add(image); testable.ClassUnderTest.MockSpriteContainer.Verify(x => x.AddImage(image), Times.Never()); }
public void WillIgnoreFilteredImportedCss() { var testable = new TestableCssReducer(); testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadString <CssResource>("http://host/css1.css")).Returns("@import url('css2.css');"); testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadString <CssResource>("http://host/css2.css")).Returns("css2"); Registry.AddFilter(new CssFilter(x => x.FilteredUrl.Contains("2"))); testable.ClassUnderTest.Process("http://host/css1.css"); testable.Mock <IMinifier>().Verify( x => x.Minify <CssResource>("@import url('http://host/css2.css');"), Times.Once()); RRContainer.Current = null; }
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 WillNotSetResponseFilterIfPageFilterIgnoresTarget() { var context = new Mock <HttpContextBase>(); var config = new Mock <IRRConfiguration>(); config.Setup(x => x.SpriteVirtualPath).Returns("/Virtual"); context.Setup(x => x.Request.RawUrl).Returns("/NotVirtual/blah"); context.Setup(x => x.Items.Contains(ResponseFilter.ContextKey)).Returns(false); context.Setup(x => x.Response.ContentType).Returns("text/html"); context.Setup(x => x.Request.QueryString).Returns(new NameValueCollection()); context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object); RRContainer.Current = new Container(x => { x.For <IRRConfiguration>().Use(config.Object); x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object); }); Registry.AddFilter(new PageFilter(x => x.HttpRequest.RawUrl.Contains("blah"))); ResponseFilter.InstallFilter(context.Object); context.VerifySet(x => x.Response.Filter = It.IsAny <Stream>(), Times.Never()); RRContainer.Current = null; }