public void ControllerContextExtensions_GetUmbracoContext_From_RouteValues()
        {
            var appCtx = new ApplicationContext(
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));
            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(),
                new List <IUrlProvider>(),
                false);

            var r1 = new RouteData();

            r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
            var ctx1 = CreateViewContext(new ControllerContext(Mock.Of <HttpContextBase>(), r1, new MyController()));
            var r2   = new RouteData();

            r2.DataTokens.Add("ParentActionViewContext", ctx1);
            var ctx2 = CreateViewContext(new ControllerContext(Mock.Of <HttpContextBase>(), r2, new MyController()));
            var r3   = new RouteData();

            r3.DataTokens.Add("ParentActionViewContext", ctx2);
            var ctx3 = CreateViewContext(new ControllerContext(Mock.Of <HttpContextBase>(), r3, new MyController()));

            var result = ctx3.GetUmbracoContext();

            Assert.IsNotNull(result);
            Assert.AreSame(umbCtx, result);
        }
        public void UmbracoContextExtensions_GetUmbracoContext()
        {
            var appCtx = new ApplicationContext(
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));
            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(),
                new List <IUrlProvider>(),
                false);
            var items = new Dictionary <object, object>()
            {
                { UmbracoContext.HttpContextItemName, umbCtx }
            };
            var http = new Mock <HttpContextBase>();

            http.Setup(x => x.Items).Returns(items);

            var result = http.Object.GetUmbracoContext();

            Assert.IsNotNull(result);
            Assert.AreSame(umbCtx, result);
        }
        public void ShouldAuthenticateRequest_When_Configured()
        {
            var dbCtx = new Mock <DatabaseContext>(Mock.Of <IScopeProviderInternal>(), Mock.Of <ILogger>(), Mock.Of <ISqlSyntaxProvider>(), "test");

            dbCtx.Setup(x => x.IsDatabaseConfigured).Returns(true);

            var appCtx = new ApplicationContext(
                dbCtx.Object,
                MockHelper.GetMockedServiceContext(),
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));

            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(), new List <IUrlProvider>(), false);

            var mgr = new BackOfficeCookieManager(Mock.Of <IUmbracoContextAccessor>(accessor => accessor.Value == umbCtx));

            var request = new Mock <OwinRequest>();

            request.Setup(owinRequest => owinRequest.Uri).Returns(new Uri("http://localhost/umbraco"));

            var result = mgr.ShouldAuthenticateRequest(
                Mock.Of <IOwinContext>(context => context.Request == request.Object),
                new Uri("http://localhost/umbraco"));

            Assert.IsTrue(result);
        }
        public void ShouldAuthenticateRequest_When_Not_Configured()
        {
            //should force app ctx to show not-configured
            ConfigurationManager.AppSettings.Set("umbracoConfigurationStatus", "");

            var dbCtx = new Mock <DatabaseContext>(Mock.Of <IScopeProviderInternal>(), Mock.Of <ILogger>(), Mock.Of <ISqlSyntaxProvider>(), "test");

            dbCtx.Setup(x => x.IsDatabaseConfigured).Returns(false);

            var appCtx = new ApplicationContext(
                dbCtx.Object,
                MockHelper.GetMockedServiceContext(),
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));

            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(), new List <IUrlProvider>(), false);

            var mgr = new BackOfficeCookieManager(Mock.Of <IUmbracoContextAccessor>(accessor => accessor.Value == umbCtx));

            var result = mgr.ShouldAuthenticateRequest(Mock.Of <IOwinContext>(), new Uri("http://localhost/umbraco"));

            Assert.IsFalse(result);
        }
Beispiel #5
0
        /// <summary>
        /// The get umbraco context.
        /// </summary>
        /// <returns>
        /// The <see cref="UmbracoContext"/>.
        /// </returns>
        private static UmbracoContext GetUmbracoContext()
        {
            // If there is an existing UmbracoContext, return it
            if (UmbracoContext.Current != null)
            {
                return(UmbracoContext.Current);
            }

            var request = new SimpleWorkerRequest(string.Empty, string.Empty, string.Empty, null, new StringWriter());

            var dummyHttpContext = new HttpContextWrapper(new HttpContext(request));

            // Create a brand new UmbracoContext so that we don't disturb any other threads that may be using UmbracoContext.Current
            return(UmbracoContext.CreateContext(
                       dummyHttpContext,
                       ApplicationContext.Current,
                       new WebSecurity(dummyHttpContext, ApplicationContext.Current),
                       UmbracoConfig.For.UmbracoSettings(),
                       UrlProviderResolver.Current.Providers,
                       false));
        }
        public void RouteDataExtensions_GetUmbracoContext()
        {
            var appCtx = new ApplicationContext(
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));
            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(),
                new List <IUrlProvider>(),
                false);
            var r1 = new RouteData();

            r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);

            var result = r1.GetUmbracoContext();

            Assert.IsNotNull(result);
            Assert.AreSame(umbCtx, result);
        }
        public void ControllerContextExtensions_GetUmbracoContext_From_HttpContext()
        {
            var appCtx = new ApplicationContext(
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));
            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(),
                new List <IUrlProvider>(),
                false);
            var items = new Dictionary <object, object>()
            {
                { UmbracoContext.HttpContextItemName, umbCtx }
            };
            var http = new Mock <HttpContextBase>();

            http.Setup(x => x.Items).Returns(items);

            var r1   = new RouteData();
            var ctx1 = CreateViewContext(new ControllerContext(http.Object, r1, new MyController()));
            var r2   = new RouteData();

            r2.DataTokens.Add("ParentActionViewContext", ctx1);
            var ctx2 = CreateViewContext(new ControllerContext(http.Object, r2, new MyController()));
            var r3   = new RouteData();

            r3.DataTokens.Add("ParentActionViewContext", ctx2);
            var ctx3 = CreateViewContext(new ControllerContext(http.Object, r3, new MyController()));

            var result = ctx3.GetUmbracoContext();

            Assert.IsNotNull(result);
            Assert.AreSame(umbCtx, result);
        }