Ejemplo n.º 1
0
        protected UmbracoContext GetUmbracoContext(string url, int templateId, RouteData routeData = null, bool setSingleton = false)
        {
            var cache = new PublishedContentCache();

            //cache.GetXmlDelegate = (context, preview) =>
            //{
            //    var doc = new XmlDocument();
            //    doc.LoadXml(GetXmlContent(templateId));
            //    return doc;
            //};

            //PublishedContentCache.UnitTesting = true;

            // ApplicationContext.Current = new ApplicationContext(false) { IsReady = true };
            var appCtx = new ApplicationContext(false)
            {
                IsReady = true
            };

            var ctx = new UmbracoContext(
                GetHttpContextFactory(url, routeData).HttpContext,
                appCtx,
                new PublishedCaches(cache, new PublishedMediaCache()));

            //if (setSingleton)
            //{
            //    UmbracoContext.Current = ctx;
            //}

            return(ctx);
        }
Ejemplo n.º 2
0
        protected UmbracoContext GetUmbracoContext(string url, int templateId, RouteData routeData = null, bool setSingleton = false)
        {
            var cache = new PublishedContentCache();

            cache.GetXmlDelegate = (context, preview) =>
            {
                var doc = new XmlDocument();
                doc.LoadXml(GetXmlContent(templateId));
                return(doc);
            };

            PublishedContentCache.UnitTesting = true;

            var ctx = new UmbracoContext(
                GetHttpContextFactory(url, routeData).HttpContext,
                ApplicationContext,
                new PublishedCaches(cache, new PublishedMediaCache()));

            if (setSingleton)
            {
                UmbracoContext.Current = ctx;
            }

            return(ctx);
        }
Ejemplo n.º 3
0
        public override void Initialize()
        {
            base.Initialize();

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

            var settings    = SettingsForTests.GenerateMockSettings();
            var contentMock = Mock.Get(settings.Content);

            contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(false);
            SettingsForTests.ConfigureSettings(settings);
            _xml = new XmlDocument();
            _xml.LoadXml(GetXml());
            var cache = new PublishedContentCache
            {
                GetXmlDelegate = (context, preview) => _xml
            };

            _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext,
                new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
                new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext));

            _cache = _umbracoContext.ContentCache;
        }
Ejemplo n.º 4
0
        public void SetUp()
        {
            TestHelper.SetupLog4NetForTests();

            //create the app context
            ApplicationContext.Current = new ApplicationContext(false);

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

            UmbracoSettings.UseLegacyXmlSchema = false;
            var cache = new PublishedContentCache
            {
                GetXmlDelegate = (context, preview) =>
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(GetXml());
                    return(doc);
                }
            };

            _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext.Current,
                new PublishedCaches(cache, new PublishedMediaCache()));

            _cache = _umbracoContext.ContentCache;
        }
        protected UmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false)
        {
            var cache = new PublishedContentCache();

            //cache.GetXmlDelegate = (context, preview) =>
            //{
            //    var doc = new XmlDocument();
            //    doc.LoadXml(GetXmlContent(templateId));
            //    return doc;
            //};

            //PublishedContentCache.UnitTesting = true;

            // ApplicationContext.Current = new ApplicationContext(false) { IsReady = true };
            var svcCtx = GetServiceContext(umbracoSettings, logger);

            var appCtx = new ApplicationContext(
                new DatabaseContext(Mock.Of <IDatabaseFactory>(), logger, Mock.Of <ISqlSyntaxProvider>(), "test"),
                svcCtx,
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(logger, Mock.Of <IProfiler>()))
            {
                IsReady = true
            };

            var http = GetHttpContextFactory(url, routeData).HttpContext;
            var ctx  = new UmbracoContext(
                GetHttpContextFactory(url, routeData).HttpContext,
                appCtx,
                new PublishedCaches(cache, new PublishedMediaCache(appCtx)),
                new WebSecurity(http, appCtx));

            //if (setSingleton)
            //{
            //    UmbracoContext.Current = ctx;
            //}

            return(ctx);
        }
Ejemplo n.º 6
0
        public override void Initialize()
        {
            base.Initialize();

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

            UmbracoSettings.UseLegacyXmlSchema = false;
            _xml = new XmlDocument();
            _xml.LoadXml(GetXml());
            var cache = new PublishedContentCache
            {
                GetXmlDelegate = (context, preview) => _xml
            };

            _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext.Current,
                new PublishedCaches(cache, new PublishedMediaCache()));

            _cache = _umbracoContext.ContentCache;
        }