Пример #1
0
 public override void TearDown()
 {
     if (_service == null)
     {
         return;
     }
     _service.Dispose();
     _service = null;
 }
Пример #2
0
        protected UmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false)
        {
            var svcCtx = GetServiceContext();

            var databaseFactory = TestObjects.GetDatabaseFactoryMock();

            //var appCtx = new ApplicationContext(
            //    new DatabaseContext(databaseFactory, logger, Mock.Of<IRuntimeState>(), Mock.Of<IMigrationEntryService>()),
            //    svcCtx,
            //    CacheHelper.CreateDisabledCacheHelper(),
            //    new ProfilingLogger(logger, Mock.Of<IProfiler>())) { /*IsReady = true*/ };

            var cache = NoAppCache.Instance;
            //var provider = new ScopeUnitOfWorkProvider(databaseFactory, new RepositoryFactory(Mock.Of<IServiceContainer>()));
            var scopeProvider          = TestObjects.GetScopeProvider(Mock.Of <ILogger>());
            var factory                = Mock.Of <IPublishedContentTypeFactory>();
            var umbracoContextAccessor = Mock.Of <IUmbracoContextAccessor>();

            _service = new XmlPublishedSnapshotService(svcCtx, factory, scopeProvider, cache,
                                                       null, null,
                                                       umbracoContextAccessor, null, null, null,
                                                       new TestDefaultCultureAccessor(),
                                                       Current.Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(),
                                                       Factory.GetInstance <IEntityXmlSerializer>(),
                                                       null, true, false
                                                       ); // no events

            var http = GetHttpContextFactory(url, routeData).HttpContext;

            var globalSettings = TestObjects.GetGlobalSettings();

            var ctx = new UmbracoContext(
                http,
                _service,
                new WebSecurity(http, Current.Services.UserService, globalSettings),
                TestObjects.GetUmbracoSettings(),
                Enumerable.Empty <IUrlProvider>(),
                Enumerable.Empty <IMediaUrlProvider>(),
                globalSettings,
                new TestVariationContextAccessor());

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

            return(ctx);
        }
        protected virtual IPublishedSnapshotService CreatePublishedSnapshotService(GlobalSettings globalSettings = null)
        {
            var cache = NoAppCache.Instance;

            ContentTypesCache ??= new PublishedContentTypeCache(
                Factory.GetRequiredService <IContentTypeService>(),
                Factory.GetRequiredService <IMediaTypeService>(),
                Factory.GetRequiredService <IMemberTypeService>(),
                Factory.GetRequiredService <IPublishedContentTypeFactory>(),
                Factory.GetRequiredService <ILogger <PublishedContentTypeCache> >());

            // testing=true so XmlStore will not use the file nor the database

            var publishedSnapshotAccessor = new UmbracoContextPublishedSnapshotAccessor(Umbraco.Web.Composing.Current.UmbracoContextAccessor);
            var variationContextAccessor  = new TestVariationContextAccessor();
            var service = new XmlPublishedSnapshotService(
                ServiceContext,
                Factory.GetRequiredService <IPublishedContentTypeFactory>(),
                ScopeProvider,
                cache, publishedSnapshotAccessor, variationContextAccessor,
                Factory.GetRequiredService <IUmbracoContextAccessor>(),
                Factory.GetRequiredService <IDocumentRepository>(), Factory.GetRequiredService <IMediaRepository>(), Factory.GetRequiredService <IMemberRepository>(),
                DefaultCultureAccessor,
                Factory.GetRequiredService <ILoggerFactory>(),
                globalSettings ?? TestObjects.GetGlobalSettings(),
                HostingEnvironment,
                HostingLifetime,
                ShortStringHelper,
                Factory.GetRequiredService <IEntityXmlSerializer>(),
                ContentTypesCache,
                null, true, Options.PublishedRepositoryEvents);

            // initialize PublishedCacheService content with an Xml source
            service.XmlStore.GetXmlDocument = () =>
            {
                var doc = new XmlDocument();
                doc.LoadXml(GetXmlContent(0));
                return(doc);
            };

            return(service);
        }