Exemplo n.º 1
0
        /// <summary>
        /// Gets an Umbraco context.
        /// </summary>
        /// <returns>An Umbraco context.</returns>
        /// <remarks>This should be the minimum Umbraco context.</remarks>
        public IUmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null)
        {
            var publishedSnapshotMock = new Mock <IPublishedSnapshot>();

            publishedSnapshotMock.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>());
            var publishedSnapshot            = publishedSnapshotMock.Object;
            var publishedSnapshotServiceMock = new Mock <IPublishedSnapshotService>();

            publishedSnapshotServiceMock.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(publishedSnapshot);
            var publishedSnapshotService = publishedSnapshotServiceMock.Object;

            var globalSettings = GetGlobalSettings();

            if (accessor == null)
            {
                accessor = new TestUmbracoContextAccessor();
            }

            var httpContextAccessor = TestHelper.GetHttpContextAccessor();

            var umbracoContextFactory = new UmbracoContextFactory(
                accessor,
                publishedSnapshotService,
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                globalSettings,
                Mock.Of <IUserService>(),
                TestHelper.GetHostingEnvironment(),
                TestHelper.UriUtility,
                httpContextAccessor,
                new AspNetCookieManager(httpContextAccessor));

            return(umbracoContextFactory.EnsureUmbracoContext().UmbracoContext);
        }
Exemplo n.º 2
0
        public void Matches_Default_Index()
        {
            var globalSettings = TestObjects.GetGlobalSettings();
            var attr           = new RenderIndexActionSelectorAttribute();
            var req            = new RequestContext();

            var umbracoContextFactory = new UmbracoContextFactory(
                Current.UmbracoContextAccessor,
                Mock.Of <IPublishedSnapshotService>(),
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                TestObjects.GetUmbracoSettings(),
                globalSettings,
                new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()),
                new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()),
                Mock.Of <IUserService>());

            var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>());
            var umbCtx = umbracoContextReference.UmbracoContext;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbCtx);
            var ctrl = new MatchesDefaultIndexController {
                UmbracoContextAccessor = umbracoContextAccessor
            };
            var controllerCtx = new ControllerContext(req, ctrl);
            var result        = attr.IsValidForRequest(controllerCtx,
                                                       GetRenderMvcControllerIndexMethodFromCurrentType(ctrl.GetType()));

            Assert.IsTrue(result);
        }
Exemplo n.º 3
0
        public void Ensure_Cache_Is_Correct()
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = false
            };

            var umbracoContext         = GetUmbracoContext("/test", 1111, globalSettings: _globalSettings);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);

            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            var samples = new Dictionary <int, string> {
                { 1046, "/home" },
                { 1173, "/home/sub1" },
                { 1174, "/home/sub1/sub2" },
                { 1176, "/home/sub1/sub-3" },
                { 1177, "/home/sub1/custom-sub-1" },
                { 1178, "/home/sub1/custom-sub-2" },
                { 1175, "/home/sub-2" },
                { 1172, "/test-page" }
            };

            foreach (var sample in samples)
            {
                var result = publishedUrlProvider.GetUrl(sample.Key);
                Assert.AreEqual(sample.Value, result);
            }

            var randomSample = new KeyValuePair <int, string>(1177, "/home/sub1/custom-sub-1");

            for (int i = 0; i < 5; i++)
            {
                var result = publishedUrlProvider.GetUrl(randomSample.Key);
                Assert.AreEqual(randomSample.Value, result);
            }

            var cache = umbracoContext.Content as PublishedContentCache;

            if (cache == null)
            {
                throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
            }
            var cachedRoutes = cache.RoutesCache.GetCachedRoutes();

            Assert.AreEqual(8, cachedRoutes.Count);

            foreach (var sample in samples)
            {
                Assert.IsTrue(cachedRoutes.ContainsKey(sample.Key));
                Assert.AreEqual(sample.Value, cachedRoutes[sample.Key]);
            }

            var cachedIds = cache.RoutesCache.GetCachedIds();

            Assert.AreEqual(0, cachedIds.Count);
        }
    public void Can_Lookup_Content()
    {
        var publishedSnapshot = new Mock <IPublishedSnapshot>();

        publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>());
        var content = new Mock <IPublishedContent>();

        content.Setup(x => x.Id).Returns(2);
        var backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>();

        Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>());
        var globalSettings = new GlobalSettings();

        var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor);

        var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
        var umbracoContext          = umbracoContextReference.UmbracoContext;

        var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);

        var publishedContentQuery = Mock.Of <IPublishedContentQuery>(query => query.Content(2) == content.Object);

        var ctrl   = new TestSurfaceController(umbracoContextAccessor, publishedContentQuery, Mock.Of <IPublishedUrlProvider>());
        var result = ctrl.GetContent(2) as PublishedContentResult;

        Assert.IsNotNull(result);
        Assert.IsNotNull(result.Content);
        Assert.AreEqual(2, result.Content.Id);
    }
Exemplo n.º 5
0
        public void Get_Url_For_Culture_Variant_With_Current_Url()
        {
            const string currentUri = "http://example.fr/test";

            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };

            var contentType      = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Culture);
            var publishedContent = new SolidPublishedContent(contentType)
            {
                Id = 1234
            };

            var publishedContentCache = new Mock <IPublishedContentCache>();

            publishedContentCache.Setup(x => x.GetRouteById(1234, "fr-FR"))
            .Returns("9876/home/test-fr");     //prefix with the root id node with the domain assigned as per the umbraco standard
            publishedContentCache.Setup(x => x.GetById(It.IsAny <int>()))
            .Returns <int>(id => id == 1234 ? publishedContent : null);

            var domainCache = new Mock <IDomainCache>();

            domainCache.Setup(x => x.GetAssigned(It.IsAny <int>(), false))
            .Returns((int contentId, bool includeWildcards) =>
            {
                if (contentId != 9876)
                {
                    return(Enumerable.Empty <Domain>());
                }
                return(new[]
                {
                    new Domain(2, "example.us", 9876, "en-US", false),     //default
                    new Domain(3, "example.fr", 9876, "fr-FR", false)
                });
            });
            domainCache.Setup(x => x.DefaultCulture).Returns(CultureInfo.GetCultureInfo("en-US").Name);

            var snapshot = Mock.Of <IPublishedSnapshot>(x => x.Content == publishedContentCache.Object && x.Domains == domainCache.Object);

            var snapshotService = new Mock <IPublishedSnapshotService>();

            snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>()))
            .Returns(snapshot);

            var umbracoContext = GetUmbracoContext(currentUri,
                                                   globalSettings: _globalSettings,
                                                   snapshotService: snapshotService.Object);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);

            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            var url = publishedUrlProvider.GetUrl(1234, culture: "fr-FR");

            Assert.AreEqual("/home/test-fr/", url);
        }
Exemplo n.º 6
0
        public void Can_Construct_And_Get_Result()
        {
            var globalSettings = TestObjects.GetGlobalSettings();

            var umbracoContextFactory = new UmbracoContextFactory(
                Current.UmbracoContextAccessor,
                Mock.Of <IPublishedSnapshotService>(),
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                TestObjects.GetUmbracoSettings(),
                globalSettings,
                new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()),
                new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()),
                Mock.Of <IUserService>());

            var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>());
            var umbracoContext          = umbracoContextReference.UmbracoContext;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);

            var ctrl = new TestSurfaceController(umbracoContextAccessor);

            var result = ctrl.Index();

            Assert.IsNotNull(result);
        }
        public void Get_Url_Alternate()
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };
            var globalSettings = new GlobalSettings {
                HideTopLevelNodeFromPath = false
            };

            var umbracoContext         = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings: globalSettings);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);
            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            SetDomains5();

            var url = publishedUrlProvider.GetUrl(100111, UrlMode.Absolute);

            Assert.AreEqual("http://domain1.com/en/1001-1-1/", url);

            var result = publishedUrlProvider.GetOtherUrls(100111).ToArray();

            foreach (var x in result)
            {
                Console.WriteLine(x);
            }

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(result[0].Text, "http://domain1b.com/en/1001-1-1/");
            Assert.AreEqual(result[1].Text, "http://domain1a.com/en/1001-1-1/");
        }
        public void Get_Url_Relative_Or_Absolute()
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };
            var globalSettings = new GlobalSettings {
                HideTopLevelNodeFromPath = false
            };

            var umbracoContext         = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings: globalSettings);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);
            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            SetDomains4();

            Assert.AreEqual("/en/1001-1-1/", publishedUrlProvider.GetUrl(100111));
            Assert.AreEqual("http://domain3.com/en/1003-1-1/", publishedUrlProvider.GetUrl(100311));

            publishedUrlProvider.Mode = UrlMode.Absolute;

            Assert.AreEqual("http://domain1.com/en/1001-1-1/", publishedUrlProvider.GetUrl(100111));
            Assert.AreEqual("http://domain3.com/en/1003-1-1/", publishedUrlProvider.GetUrl(100311));
        }
        public void Get_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected)
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };
            var globalSettings = new GlobalSettings {
                HideTopLevelNodeFromPath = false
            };

            var umbracoContext         = GetUmbracoContext("/test", 1111, globalSettings: globalSettings);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);
            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            SetDomains4();

            var currentUri = new Uri(currentUrl);
            var mode       = absolute ? UrlMode.Absolute : UrlMode.Auto;
            var result     = publishedUrlProvider.GetUrl(nodeId, mode, current: currentUri);

            Assert.AreEqual(expected, result);
        }
        /// <summary>
        /// Gets an Umbraco context.
        /// </summary>
        /// <returns>An Umbraco context.</returns>
        /// <remarks>This should be the minimum Umbraco context.</remarks>
        public UmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null)
        {
            var httpContext = Mock.Of <HttpContextBase>();

            var publishedSnapshotMock = new Mock <IPublishedSnapshot>();

            publishedSnapshotMock.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>());
            var publishedSnapshot            = publishedSnapshotMock.Object;
            var publishedSnapshotServiceMock = new Mock <IPublishedSnapshotService>();

            publishedSnapshotServiceMock.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(publishedSnapshot);
            var publishedSnapshotService = publishedSnapshotServiceMock.Object;

            var umbracoSettings = GetUmbracoSettings();
            var globalSettings  = GetGlobalSettings();
            var urlProviders    = new UrlProviderCollection(Enumerable.Empty <IUrlProvider>());

            if (accessor == null)
            {
                accessor = new TestUmbracoContextAccessor();
            }

            var umbracoContextFactory = new UmbracoContextFactory(
                accessor,
                publishedSnapshotService,
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                umbracoSettings,
                globalSettings,
                urlProviders,
                Mock.Of <IUserService>());

            return(umbracoContextFactory.EnsureUmbracoContext(httpContext).UmbracoContext);
        }
Exemplo n.º 11
0
        private IUmbracoContextAccessor GetUmbracoContextAccessor()
        {
            var uri                    = new Uri("http://example.com");
            var umbracoContext         = Mock.Of <IUmbracoContext>(x => x.CleanedUmbracoUrl == uri);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);

            return(umbracoContextAccessor);
        }
Exemplo n.º 12
0
        public void Ensure_Image_Sources()
        {
            // setup a mock URL provider which we'll use for testing
            var mediaType = new PublishedContentType(Guid.NewGuid(), 777, "image", PublishedItemType.Media, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing);
            var media     = new Mock <IPublishedContent>();

            media.Setup(x => x.ContentType).Returns(mediaType);
            var mediaUrlProvider = new Mock <IMediaUrlProvider>();

            mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny <IPublishedContent>(), It.IsAny <string>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>()))
            .Returns(UrlInfo.Url("/media/1001/my-image.jpg"));

            var umbracoContextAccessor = new TestUmbracoContextAccessor();

            IUmbracoContextFactory umbracoContextFactory = TestUmbracoContextFactory.Create(
                umbracoContextAccessor: umbracoContextAccessor);

            var webRoutingSettings   = new WebRoutingSettings();
            var publishedUrlProvider = new UrlProvider(
                umbracoContextAccessor,
                Options.Create(webRoutingSettings),
                new UrlProviderCollection(() => Enumerable.Empty <IUrlProvider>()),
                new MediaUrlProviderCollection(() => new[] { mediaUrlProvider.Object }),
                Mock.Of <IVariationContextAccessor>());

            using (UmbracoContextReference reference = umbracoContextFactory.EnsureUmbracoContext())
            {
                var mediaCache = Mock.Get(reference.UmbracoContext.Media);
                mediaCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(media.Object);

                var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider);

                var result = imageSourceParser.EnsureImageSources(@"<p>
<div>
    <img src="""" />
</div></p>
<p>
    <div><img src="""" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div>
</p>
<p>
    <div><img src=""?width=100"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div>
</p>");

                Assert.AreEqual(
                    @"<p>
<div>
    <img src="""" />
</div></p>
<p>
    <div><img src=""/media/1001/my-image.jpg"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div>
</p>
<p>
    <div><img src=""/media/1001/my-image.jpg?width=100"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div>
</p>", result);
            }
        }
        public void ParseLocalLinks(string input, string result)
        {
            // setup a mock URL provider which we'll use for testing
            var contentUrlProvider = new Mock <IUrlProvider>();

            contentUrlProvider
            .Setup(x => x.GetUrl(It.IsAny <IPublishedContent>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>()))
            .Returns(UrlInfo.Url("/my-test-url"));
            var contentType      = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing);
            var publishedContent = new Mock <IPublishedContent>();

            publishedContent.Setup(x => x.Id).Returns(1234);
            publishedContent.Setup(x => x.ContentType).Returns(contentType);

            var mediaType = new PublishedContentType(Guid.NewGuid(), 777, "image", PublishedItemType.Media, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing);
            var media     = new Mock <IPublishedContent>();

            media.Setup(x => x.ContentType).Returns(mediaType);
            var mediaUrlProvider = new Mock <IMediaUrlProvider>();

            mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny <IPublishedContent>(), It.IsAny <string>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>()))
            .Returns(UrlInfo.Url("/media/1001/my-image.jpg"));

            var umbracoContextAccessor = new TestUmbracoContextAccessor();

            IUmbracoContextFactory umbracoContextFactory = TestUmbracoContextFactory.Create(
                umbracoContextAccessor: umbracoContextAccessor);

            var webRoutingSettings   = new WebRoutingSettings();
            var publishedUrlProvider = new UrlProvider(
                umbracoContextAccessor,
                Microsoft.Extensions.Options.Options.Create(webRoutingSettings),
                new UrlProviderCollection(() => new[] { contentUrlProvider.Object }),
                new MediaUrlProviderCollection(() => new[] { mediaUrlProvider.Object }),
                Mock.Of <IVariationContextAccessor>());

            using (UmbracoContextReference reference = umbracoContextFactory.EnsureUmbracoContext())
            {
                var contentCache = Mock.Get(reference.UmbracoContext.Content);
                contentCache.Setup(x => x.GetById(It.IsAny <int>())).Returns(publishedContent.Object);
                contentCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(publishedContent.Object);

                var mediaCache = Mock.Get(reference.UmbracoContext.Media);
                mediaCache.Setup(x => x.GetById(It.IsAny <int>())).Returns(media.Object);
                mediaCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(media.Object);

                var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider);

                var output = linkParser.EnsureInternalLinks(input);

                Assert.AreEqual(result, output);
            }
        }
Exemplo n.º 14
0
        public void ParseLocalLinks(string input, string result)
        {
            //setup a mock url provider which we'll use for testing
            var testUrlProvider = new Mock <IUrlProvider>();

            testUrlProvider
            .Setup(x => x.GetUrl(It.IsAny <UmbracoContext>(), It.IsAny <IPublishedContent>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>()))
            .Returns((UmbracoContext umbCtx, IPublishedContent content, UrlMode mode, string culture, Uri url) => UrlInfo.Url("/my-test-url"));

            var globalSettings = SettingsForTests.GenerateMockGlobalSettings();

            var contentType      = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing);
            var publishedContent = Mock.Of <IPublishedContent>();

            Mock.Get(publishedContent).Setup(x => x.Id).Returns(1234);
            Mock.Get(publishedContent).Setup(x => x.ContentType).Returns(contentType);
            var contentCache = Mock.Of <IPublishedContentCache>();

            Mock.Get(contentCache).Setup(x => x.GetById(It.IsAny <int>())).Returns(publishedContent);
            Mock.Get(contentCache).Setup(x => x.GetById(It.IsAny <Guid>())).Returns(publishedContent);
            var snapshot = Mock.Of <IPublishedSnapshot>();

            Mock.Get(snapshot).Setup(x => x.Content).Returns(contentCache);
            var snapshotService = Mock.Of <IPublishedSnapshotService>();

            Mock.Get(snapshotService).Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(snapshot);
            var media = Mock.Of <IPublishedContent>();

            Mock.Get(media).Setup(x => x.Url).Returns("/media/1001/my-image.jpg");
            var mediaCache = Mock.Of <IPublishedMediaCache>();

            Mock.Get(mediaCache).Setup(x => x.GetById(It.IsAny <Guid>())).Returns(media);

            var umbracoContextAccessor = new TestUmbracoContextAccessor();
            var umbracoContextFactory  = new UmbracoContextFactory(
                umbracoContextAccessor,
                snapshotService,
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of <IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "Auto")),
                globalSettings,
                new UrlProviderCollection(new[] { testUrlProvider.Object }),
                new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()),
                Mock.Of <IUserService>());

            using (var reference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>()))
            {
                var output = TemplateUtilities.ParseInternalLinks(input, reference.UmbracoContext.UrlProvider, mediaCache);

                Assert.AreEqual(result, output);
            }
        }
        public static IUmbracoContextFactory Create(
            GlobalSettings globalSettings = null,
            IUmbracoContextAccessor umbracoContextAccessor = null,
            IHttpContextAccessor httpContextAccessor       = null,
            IPublishedUrlProvider publishedUrlProvider     = null)
        {
            if (globalSettings == null)
            {
                globalSettings = new GlobalSettings();
            }

            if (umbracoContextAccessor == null)
            {
                umbracoContextAccessor = new TestUmbracoContextAccessor();
            }

            if (httpContextAccessor == null)
            {
                httpContextAccessor = Mock.Of <IHttpContextAccessor>();
            }

            if (publishedUrlProvider == null)
            {
                publishedUrlProvider = Mock.Of <IPublishedUrlProvider>();
            }

            var contentCache = new Mock <IPublishedContentCache>();
            var mediaCache   = new Mock <IPublishedMediaCache>();
            var snapshot     = new Mock <IPublishedSnapshot>();

            snapshot.Setup(x => x.Content).Returns(contentCache.Object);
            snapshot.Setup(x => x.Media).Returns(mediaCache.Object);
            var snapshotService = new Mock <IPublishedSnapshotService>();

            snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(snapshot.Object);

            IHostingEnvironment hostingEnvironment = TestHelper.GetHostingEnvironment();

            var umbracoContextFactory = new UmbracoContextFactory(
                umbracoContextAccessor,
                snapshotService.Object,
                new UmbracoRequestPaths(Options.Create(globalSettings), hostingEnvironment),
                hostingEnvironment,
                new UriUtility(hostingEnvironment),
                new AspNetCoreCookieManager(httpContextAccessor),
                httpContextAccessor);

            return(umbracoContextFactory);
        }
Exemplo n.º 16
0
        public void ParseLocalLinks(string input, string result)
        {
            //setup a mock url provider which we'll use for testing
            var contentUrlProvider = new Mock <IUrlProvider>();

            contentUrlProvider
            .Setup(x => x.GetUrl(It.IsAny <UmbracoContext>(), It.IsAny <IPublishedContent>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>()))
            .Returns(UrlInfo.Url("/my-test-url"));
            var contentType      = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing);
            var publishedContent = new Mock <IPublishedContent>();

            publishedContent.Setup(x => x.Id).Returns(1234);
            publishedContent.Setup(x => x.ContentType).Returns(contentType);

            var mediaType = new PublishedContentType(777, "image", PublishedItemType.Media, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing);
            var media     = new Mock <IPublishedContent>();

            media.Setup(x => x.ContentType).Returns(mediaType);
            var mediaUrlProvider = new Mock <IMediaUrlProvider>();

            mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny <UmbracoContext>(), It.IsAny <IPublishedContent>(), It.IsAny <string>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>()))
            .Returns(UrlInfo.Url("/media/1001/my-image.jpg"));

            var umbracoContextAccessor = new TestUmbracoContextAccessor();

            var umbracoContextFactory = TestUmbracoContextFactory.Create(
                urlProvider: contentUrlProvider.Object,
                mediaUrlProvider: mediaUrlProvider.Object,
                umbracoContextAccessor: umbracoContextAccessor);

            using (var reference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>()))
            {
                var contentCache = Mock.Get(reference.UmbracoContext.Content);
                contentCache.Setup(x => x.GetById(It.IsAny <int>())).Returns(publishedContent.Object);
                contentCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(publishedContent.Object);

                var mediaCache = Mock.Get(reference.UmbracoContext.Media);
                mediaCache.Setup(x => x.GetById(It.IsAny <int>())).Returns(media.Object);
                mediaCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(media.Object);

                var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor);

                var output = linkParser.EnsureInternalLinks(input);

                Assert.AreEqual(result, output);
            }
        }
Exemplo n.º 17
0
        public void Mock_Current_Page()
        {
            var webRoutingSettings = Mock.Of <IWebRoutingSection>(section => section.UrlProviderMode == "Auto");
            var globalSettings     = TestObjects.GetGlobalSettings();

            var umbracoContextFactory = new UmbracoContextFactory(
                Current.UmbracoContextAccessor,
                Mock.Of <IPublishedSnapshotService>(),
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == webRoutingSettings),
                globalSettings,
                new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()),
                new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()),
                Mock.Of <IUserService>());

            var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>());
            var umbracoContext          = umbracoContextReference.UmbracoContext;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);

            var content = Mock.Of <IPublishedContent>(publishedContent => publishedContent.Id == 12345);

            var contextBase     = umbracoContext.HttpContext;
            var publishedRouter = BaseWebTest.CreatePublishedRouter(TestObjects.GetUmbracoSettings().WebRouting);
            var frequest        = publishedRouter.CreateRequest(umbracoContext, new Uri("http://localhost/test"));

            frequest.PublishedContent = content;

            var routeDefinition = new RouteDefinition
            {
                PublishedRequest = frequest
            };

            var routeData = new RouteData();

            routeData.DataTokens.Add(Core.Constants.Web.UmbracoRouteDefinitionDataToken, routeDefinition);

            var ctrl = new TestSurfaceController(umbracoContextAccessor, new UmbracoHelper());

            ctrl.ControllerContext = new ControllerContext(contextBase, routeData, ctrl);

            var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult;

            Assert.AreEqual(12345, result.Content.Id);
        }
        public void Returns_Udis_From_Data_Udi_Html_Attributes()
        {
            var input = @"<p>
    <div>
        <img src='/media/12312.jpg' data-udi='umb://media/D4B18427A1544721B09AC7692F35C264' />
    </div>
</p><p><img src='/media/234234.jpg' data-udi=""umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"" /></p>";

            var umbracoContextAccessor = new TestUmbracoContextAccessor();
            var imageSourceParser      = new HtmlImageSourceParser(umbracoContextAccessor);

            var result = imageSourceParser.FindUdisFromDataAttributes(input).ToList();

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(Udi.Parse("umb://media/D4B18427A1544721B09AC7692F35C264"), result[0]);
            Assert.AreEqual(Udi.Parse("umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"), result[1]);
        }
Exemplo n.º 19
0
    public void Umbraco_Context_Not_Null()
    {
        var globalSettings             = new GlobalSettings();
        var backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>();

        Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>());
        var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor);

        var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
        var umbCtx = umbracoContextReference.UmbracoContext;

        var umbracoContextAccessor = new TestUmbracoContextAccessor(umbCtx);

        var ctrl = new TestSurfaceController(umbracoContextAccessor, Mock.Of <IPublishedContentQuery>(), Mock.Of <IPublishedUrlProvider>());

        Assert.IsNotNull(ctrl.UmbracoContext);
    }
        [TestCase(1172, "/test-page/")] // not hidden because not first root
        public void Get_Url_Hiding_Top_Level(int nodeId, string niceUrlMatch)
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };

            var umbracoContext         = GetUmbracoContext("/test", 1111, globalSettings: _globalSettings, snapshotService: PublishedSnapshotService);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);
            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            var result = publishedUrlProvider.GetUrl(nodeId);

            Assert.AreEqual(niceUrlMatch, result);
        }
Exemplo n.º 21
0
        public static IUmbracoContextFactory Create(IGlobalSettings globalSettings                 = null, IUrlProvider urlProvider = null,
                                                    IMediaUrlProvider mediaUrlProvider             = null,
                                                    IUmbracoContextAccessor umbracoContextAccessor = null)
        {
            if (globalSettings == null)
            {
                globalSettings = SettingsForTests.GenerateMockGlobalSettings();
            }
            if (urlProvider == null)
            {
                urlProvider = Mock.Of <IUrlProvider>();
            }
            if (mediaUrlProvider == null)
            {
                mediaUrlProvider = Mock.Of <IMediaUrlProvider>();
            }
            if (umbracoContextAccessor == null)
            {
                umbracoContextAccessor = new TestUmbracoContextAccessor();
            }

            var contentCache = new Mock <IPublishedContentCache>();
            var mediaCache   = new Mock <IPublishedMediaCache>();
            var snapshot     = new Mock <IPublishedSnapshot>();

            snapshot.Setup(x => x.Content).Returns(contentCache.Object);
            snapshot.Setup(x => x.Media).Returns(mediaCache.Object);
            var snapshotService = new Mock <IPublishedSnapshotService>();

            snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(snapshot.Object);

            var umbracoContextFactory = new UmbracoContextFactory(
                umbracoContextAccessor,
                snapshotService.Object,
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of <IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "Auto")),
                globalSettings,
                new UrlProviderCollection(new[] { urlProvider }),
                new MediaUrlProviderCollection(new[] { mediaUrlProvider }),
                Mock.Of <IUserService>());

            return(umbracoContextFactory);
        }
Exemplo n.º 22
0
        public void Get_Url_Relative_Or_Absolute()
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };

            var umbracoContext         = GetUmbracoContext("http://example.com/test", 1111, globalSettings: _globalSettings);
            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);
            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            Assert.AreEqual("/home/sub1/custom-sub-1/", publishedUrlProvider.GetUrl(1177));

            publishedUrlProvider.Mode = UrlMode.Absolute;
            Assert.AreEqual("http://example.com/home/sub1/custom-sub-1/", publishedUrlProvider.GetUrl(1177));
        }
        public void Umbraco_Route_User_Defined_Controller_Action(string templateName)
        {
            // NOTE - here we create templates with crazy aliases... assuming that these
            // could exist in the database... yet creating templates should sanitize
            // aliases one way or another...

            var template  = CreateTemplate(templateName);
            var route     = RouteTable.Routes["Umbraco_default"];
            var routeData = new RouteData()
            {
                Route = route
            };
            var umbracoContext  = GetUmbracoContext("~/dummy-page", template.Id, routeData, true);
            var publishedRouter = CreatePublishedRouter();
            var frequest        = publishedRouter.CreateRequest(umbracoContext);

            frequest.PublishedContent = umbracoContext.ContentCache.GetById(1172);
            frequest.TemplateModel    = template;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var type = new AutoPublishedContentType(22, "CustomDocument", new PublishedPropertyType[] { });

            ContentTypesCache.GetPublishedContentTypeByAlias = alias => type;

            var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of <ILogger>(), context =>
            {
                var membershipHelper = new MembershipHelper(
                    umbracoContext.HttpContext, Mock.Of <IPublishedMemberCache>(), Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>(), Mock.Of <IMemberService>(), Mock.Of <IMemberTypeService>(), Mock.Of <IUserService>(), Mock.Of <IPublicAccessService>(), Mock.Of <AppCaches>(), Mock.Of <ILogger>());
                return(new CustomDocumentController(Factory.GetInstance <IGlobalSettings>(),
                                                    umbracoContextAccessor,
                                                    Factory.GetInstance <ServiceContext>(),
                                                    Factory.GetInstance <AppCaches>(),
                                                    Factory.GetInstance <IProfilingLogger>(),
                                                    new UmbracoHelper(Mock.Of <IPublishedContent>(), Mock.Of <ITagQuery>(), Mock.Of <ICultureDictionaryFactory>(), Mock.Of <IUmbracoComponentRenderer>(), Mock.Of <IPublishedContentQuery>(), membershipHelper)));
            }));

            handler.GetHandlerForRoute(umbracoContext.HttpContext.Request.RequestContext, frequest);
            Assert.AreEqual("CustomDocument", routeData.Values["controller"].ToString());
            Assert.AreEqual(
                //global::umbraco.cms.helpers.Casing.SafeAlias(template.Alias),
                template.Alias.ToSafeAlias(),
                routeData.Values["action"].ToString());
        }
Exemplo n.º 24
0
        public void Can_Lookup_Content()
        {
            var publishedSnapshot = new Mock <IPublishedSnapshot>();

            publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>());
            var content = new Mock <IPublishedContent>();

            content.Setup(x => x.Id).Returns(2);
            var publishedSnapshotService = new Mock <IPublishedSnapshotService>();
            var globalSettings           = TestObjects.GetGlobalSettings();

            var umbracoContextFactory = new UmbracoContextFactory(
                Current.UmbracoContextAccessor,
                publishedSnapshotService.Object,
                new TestVariationContextAccessor(),
                new TestDefaultCultureAccessor(),
                Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of <IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "Auto")),
                globalSettings,
                new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()),
                new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()),
                Mock.Of <IUserService>());

            var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>());
            var umbracoContext          = umbracoContextReference.UmbracoContext;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);

            var helper = new UmbracoHelper(
                content.Object,
                Mock.Of <ITagQuery>(),
                Mock.Of <ICultureDictionaryFactory>(),
                Mock.Of <IUmbracoComponentRenderer>(),
                Mock.Of <IPublishedContentQuery>(query => query.Content(2) == content.Object),
                new MembershipHelper(umbracoContext.HttpContext, Mock.Of <IPublishedMemberCache>(), Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>(), Mock.Of <IMemberService>(), Mock.Of <IMemberTypeService>(), Mock.Of <IUserService>(), Mock.Of <IPublicAccessService>(), AppCaches.Disabled, Mock.Of <ILogger>()));

            var ctrl   = new TestSurfaceController(umbracoContextAccessor, helper);
            var result = ctrl.GetContent(2) as PublishedContentResult;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(2, result.Content.Id);
        }
        public void Returns_Udis_From_LocalLinks()
        {
            var input = @"<p>
    <div>
        <img src='/media/12312.jpg' data-udi='umb://media/D4B18427A1544721B09AC7692F35C264' />
        <a href=""{locallink:umb://document/C093961595094900AAF9170DDE6AD442}"">hello</a>
    </div>
</p><p><img src='/media/234234.jpg' data-udi=""umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"" />
<a href=""{locallink:umb://document-type/2D692FCB070B4CDA92FB6883FDBFD6E2}"">hello</a>
</p>";

            var umbracoContextAccessor = new TestUmbracoContextAccessor();
            var parser = new HtmlLocalLinkParser(umbracoContextAccessor, Mock.Of <IPublishedUrlProvider>());

            var result = parser.FindUdisFromLocalLinks(input).ToList();

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(UdiParser.Parse("umb://document/C093961595094900AAF9170DDE6AD442"), result[0]);
            Assert.AreEqual(UdiParser.Parse("umb://document-type/2D692FCB070B4CDA92FB6883FDBFD6E2"), result[1]);
        }
        public void Remove_Image_Sources()
        {
            var umbracoContextAccessor = new TestUmbracoContextAccessor();
            var imageSourceParser      = new HtmlImageSourceParser(umbracoContextAccessor);

            var result = imageSourceParser.RemoveImageSources(@"<p>
<div>
    <img src=""/media/12354/test.jpg"" />
</div></p>
<p>
    <div><img src=""/media/987645/test.jpg"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div>
</p>");

            Assert.AreEqual(@"<p>
<div>
    <img src=""/media/12354/test.jpg"" />
</div></p>
<p>
    <div><img src="""" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div>
</p>", result);
        }
Exemplo n.º 27
0
        public void Can_Construct_And_Get_Result()
        {
            IHostingEnvironment         hostingEnvironment         = Mock.Of <IHostingEnvironment>();
            IBackOfficeSecurityAccessor backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>();

            Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>());
            var globalSettings = new GlobalSettings();

            var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor);

            UmbracoContextReference umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
            IUmbracoContext         umbracoContext          = umbracoContextReference.UmbracoContext;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);

            var ctrl = new TestSurfaceController(umbracoContextAccessor, Mock.Of <IPublishedContentQuery>(), Mock.Of <IPublishedUrlProvider>());

            IActionResult result = ctrl.Index();

            Assert.IsNotNull(result);
        }
Exemplo n.º 28
0
        public void Mock_Current_Page()
        {
            var globalSettings = new GlobalSettings();
            IHostingEnvironment         hostingEnvironment         = Mock.Of <IHostingEnvironment>();
            IBackOfficeSecurityAccessor backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>();

            Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>());
            var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor);

            UmbracoContextReference umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
            IUmbracoContext         umbracoContext          = umbracoContextReference.UmbracoContext;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);

            IPublishedContent content = Mock.Of <IPublishedContent>(publishedContent => publishedContent.Id == 12345);
            var builder = new PublishedRequestBuilder(umbracoContext.CleanedUmbracoUrl, Mock.Of <IFileService>());

            builder.SetPublishedContent(content);
            IPublishedRequest publishedRequest = builder.Build();

            var routeDefinition = new UmbracoRouteValues(publishedRequest, null);

            var httpContext = new DefaultHttpContext();

            httpContext.Features.Set(routeDefinition);

            var ctrl = new TestSurfaceController(umbracoContextAccessor, Mock.Of <IPublishedContentQuery>(), Mock.Of <IPublishedUrlProvider>())
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = httpContext,
                    RouteData   = new RouteData()
                }
            };

            var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult;

            Assert.AreEqual(12345, result.Content.Id);
        }
        public void Umbraco_Route_Umbraco_Defined_Controller_Action()
        {
            var template  = CreateTemplate("homePage");
            var route     = RouteTable.Routes["Umbraco_default"];
            var routeData = new RouteData {
                Route = route
            };
            var umbracoContext  = GetUmbracoContext("~/dummy-page", template.Id, routeData);
            var publishedRouter = CreatePublishedRouter();
            var frequest        = publishedRouter.CreateRequest(umbracoContext);

            frequest.PublishedContent = umbracoContext.ContentCache.GetById(1174);
            frequest.TemplateModel    = template;

            var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
            var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of <ILogger>()));

            handler.GetHandlerForRoute(umbracoContext.HttpContext.Request.RequestContext, frequest);
            Assert.AreEqual("RenderMvc", routeData.Values["controller"].ToString());
            //the route action will still be the one we've asked for because our RenderActionInvoker is the thing that decides
            // if the action matches.
            Assert.AreEqual("homePage", routeData.Values["action"].ToString());
        }
Exemplo n.º 30
0
        /// <summary>
        /// Gets an Umbraco context.
        /// </summary>
        /// <returns>An Umbraco context.</returns>
        /// <remarks>This should be the minimum Umbraco context.</remarks>
        public UmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null)
        {
            var httpContext = Mock.Of <HttpContextBase>();

            var publishedSnapshotMock = new Mock <IPublishedSnapshot>();

            publishedSnapshotMock.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>());
            var publishedSnapshot            = publishedSnapshotMock.Object;
            var publishedSnapshotServiceMock = new Mock <IPublishedSnapshotService>();

            publishedSnapshotServiceMock.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(publishedSnapshot);
            var publishedSnapshotService = publishedSnapshotServiceMock.Object;

            var umbracoSettings = GetUmbracoSettings();
            var globalSettings  = GetGlobalSettings();
            var webSecurity     = new Mock <WebSecurity>(null, null, globalSettings).Object;
            var urlProviders    = Enumerable.Empty <IUrlProvider>();

            if (accessor == null)
            {
                accessor = new TestUmbracoContextAccessor();
            }
            return(UmbracoContext.EnsureContext(accessor, httpContext, publishedSnapshotService, webSecurity, umbracoSettings, urlProviders, globalSettings, new TestVariationContextAccessor(), true));
        }