Example #1
0
        public void Make_Composite_Url()
        {
            var websiteInfo = new Mock <IWebsiteInfo>();

            websiteInfo.Setup(x => x.GetBasePath()).Returns(string.Empty);
            websiteInfo.Setup(x => x.GetBaseUrl()).Returns(new Uri("http://test.com"));

            var urlHelper = new RequestHelper(websiteInfo.Object);
            var hasher    = new Mock <IHasher>();

            hasher.Setup(x => x.Hash(It.IsAny <string>())).Returns((string s) => s.ToLower());
            var options = new SmidgeOptions {
                UrlOptions = new UrlManagerOptions {
                    CompositeFilePath = "sg", MaxUrlLength = 100
                }
            };
            var creator = new DefaultUrlManager(
                Mock.Of <IOptions <SmidgeOptions> >(x => x.Value == options),
                hasher.Object,
                urlHelper);

            var url = creator.GetUrls(
                new List <IWebFile> {
                new JavaScriptFile("Test1.js"), new JavaScriptFile("Test2.js")
            }, ".js",
                Mock.Of <ICacheBuster>(buster => buster.GetValue() == "1"));

            Assert.Single(url);
            Assert.Equal("/sg/Test1.Test2.js.v1", url.First().Url);
            Assert.Equal("test1.test2", url.First().Key);
        }
Example #2
0
        public void Make_Composite_Url_Splits()
        {
            var hasher = new Mock <IHasher>();

            hasher.Setup(x => x.Hash(It.IsAny <string>())).Returns((string s) => s.ToLower());
            var options = new SmidgeOptions {
                UrlOptions = new UrlManagerOptions {
                    CompositeFilePath = "sg", MaxUrlLength = 14 + 10
                }
            };
            var creator = new DefaultUrlManager(
                Mock.Of <IOptions <SmidgeOptions> >(x => x.Value == options),
                Mock.Of <ISmidgeConfig>(x => x.Version == "1"),
                hasher.Object);

            var url = creator.GetUrls(new List <IWebFile> {
                new JavaScriptFile("Test1.js"), new JavaScriptFile("Test2.js")
            }, ".js");

            Assert.Equal(2, url.Count());
            Assert.Equal("sg/Test1.js.v1", url.ElementAt(0).Url);
            Assert.Equal("test1", url.ElementAt(0).Key);
            Assert.Equal("sg/Test2.js.v1", url.ElementAt(1).Url);
            Assert.Equal("test2", url.ElementAt(1).Key);
        }
Example #3
0
        public void Throws_When_Single_Dependency_Too_Long()
        {
            var websiteInfo = new Mock <IWebsiteInfo>();

            websiteInfo.Setup(x => x.GetBasePath()).Returns(string.Empty);
            websiteInfo.Setup(x => x.GetBaseUrl()).Returns(new Uri("http://test.com"));

            var urlHelper = new RequestHelper(websiteInfo.Object);
            var hasher    = new Mock <IHasher>();

            hasher.Setup(x => x.Hash(It.IsAny <string>())).Returns((string s) => s.ToLower());
            var options = new SmidgeOptions {
                UrlOptions = new UrlManagerOptions {
                    CompositeFilePath = "sg", MaxUrlLength = 10
                }
            };
            var creator = new DefaultUrlManager(
                Mock.Of <IOptions <SmidgeOptions> >(x => x.Value == options),
                hasher.Object,
                urlHelper);

            Assert.Throws <InvalidOperationException>(() => creator.GetUrls(
                                                          new List <IWebFile> {
                new JavaScriptFile("Test1.js")
            }, ".js",
                                                          Mock.Of <ICacheBuster>(buster => buster.GetValue() == "1")));
        }
Example #4
0
        public void Throws_When_Single_Dependency_Too_Long()
        {
            var hasher = new Mock <IHasher>();

            hasher.Setup(x => x.Hash(It.IsAny <string>())).Returns((string s) => s.ToLower());
            var options = new SmidgeOptions {
                UrlOptions = new UrlManagerOptions {
                    CompositeFilePath = "sg", MaxUrlLength = 10
                }
            };
            var creator = new DefaultUrlManager(
                Mock.Of <IOptions <SmidgeOptions> >(x => x.Value == options),
                Mock.Of <ISmidgeConfig>(x => x.Version == "1"),
                hasher.Object);

            Assert.Throws <InvalidOperationException>(() => creator.GetUrls(new List <IWebFile> {
                new JavaScriptFile("Test1.js")
            }, ".js"));
        }