コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UmbracoRequestMiddleware"/> class.
        /// </summary>
        public UmbracoRequestMiddleware(
            ILogger <UmbracoRequestMiddleware> logger,
            IUmbracoContextFactory umbracoContextFactory,
            IRequestCache requestCache,
            IEventAggregator eventAggregator,
            IProfiler profiler,
            IHostingEnvironment hostingEnvironment,
            UmbracoRequestPaths umbracoRequestPaths,
            BackOfficeWebAssets backOfficeWebAssets,
            IOptionsMonitor <SmidgeOptions> smidgeOptions,
            IRuntimeState runtimeState,
            IVariationContextAccessor variationContextAccessor,
            IDefaultCultureAccessor defaultCultureAccessor,
            IOptions <UmbracoRequestOptions> umbracoRequestOptions)
        {
            _logger = logger;
            _umbracoContextFactory    = umbracoContextFactory;
            _requestCache             = requestCache;
            _eventAggregator          = eventAggregator;
            _hostingEnvironment       = hostingEnvironment;
            _umbracoRequestPaths      = umbracoRequestPaths;
            _backOfficeWebAssets      = backOfficeWebAssets;
            _runtimeState             = runtimeState;
            _variationContextAccessor = variationContextAccessor;
            _defaultCultureAccessor   = defaultCultureAccessor;
            _umbracoRequestOptions    = umbracoRequestOptions;
            _smidgeOptions            = smidgeOptions.CurrentValue;
            _profiler = profiler as WebProfiler; // Ignore if not a WebProfiler

            smidgeOptions.OnChange(x => _smidgeOptions = x);
        }
コード例 #2
0
        public void Make_Bundle_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("blah");
            var options = new SmidgeOptions {
                UrlOptions = new UrlManagerOptions {
                    BundleFilePath = "sg"
                }
            };
            var creator = new DefaultUrlManager(
                Mock.Of <IOptions <SmidgeOptions> >(x => x.Value == options),
                hasher.Object,
                urlHelper);

            var url = creator.GetUrl("my-bundle", ".js", false, Mock.Of <ICacheBuster>(buster => buster.GetValue() == "1"));

            Assert.Equal("/sg/my-bundle.js.v1", url);
        }
コード例 #3
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);
        }
コード例 #4
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")));
        }
コード例 #5
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);
        }
コード例 #6
0
        public void Parse_Path()
        {
            var path    = "c61531b5.2512be3b.bb1214f7.a21bd1fd.js.v1";
            var options = new SmidgeOptions {
                UrlOptions = new UrlManagerOptions {
                    CompositeFilePath = "sg"
                }
            };
            var manager = new DefaultUrlManager(
                Mock.Of <IOptions <SmidgeOptions> >(x => x.Value == options),
                Mock.Of <IHasher>(),
                Mock.Of <IRequestHelper>());

            var result = manager.ParsePath(path);

            Assert.Equal("1", result.Version);
            Assert.Equal(4, result.Names.Count());
            Assert.Equal(WebFileType.Js, result.WebType);
        }
コード例 #7
0
        public void Make_Bundle_Url()
        {
            var hasher = new Mock <IHasher>();

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

            var url = creator.GetUrl("my-bundle", ".js");

            Assert.Equal("sg/my-bundle.js.v1", url);
        }
コード例 #8
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"));
        }