Esempio n. 1
0
        public void Initialize(InitializationEngine context)
        {
            _tagService         = new TagService();
            _pageTypeRepository = ServiceLocator.Current.GetInstance <PageTypeRepository>();

            DataFactory.Instance.PublishedPage += OnPublishedPage;
        }
Esempio n. 2
0
        public void GivenPageTypeWithSpecifiedNameAndNoGuid_GetExistingPageType_ReturnsPageTypeReturnedFromPageTypeFactoryLoad()
        {
            MockRepository     mockRepository     = new MockRepository();
            Type               pageTypeType       = typeof(object);
            PageTypeDefinition pageTypeDefinition = new PageTypeDefinition
            {
                Type      = pageTypeType,
                Attribute = new PageTypeAttribute {
                    Name = Guid.NewGuid().ToString()
                }
            };
            PageTypeRepository fakePageTypeRepository = mockRepository.Stub <PageTypeRepository>();
            IPageType          pageTypeFromFactory    = new NativePageType();

            pageTypeFromFactory.ID = 1;
            fakePageTypeRepository.Expect(factory => factory.Load(pageTypeDefinition.Attribute.Name)).Return(pageTypeFromFactory);
            fakePageTypeRepository.Replay();
            PageTypeUpdater pageTypeUpdater = PageTypeUpdaterFactory.Create(
                PageTypeDefinitionLocatorFactory.Stub(), fakePageTypeRepository);

            IPageType returnedPageType = pageTypeUpdater.GetExistingPageType(pageTypeDefinition);

            fakePageTypeRepository.AssertWasCalled(factory => factory.Load(pageTypeDefinition.Attribute.Name));
            Assert.Equal <int>(pageTypeFromFactory.ID, returnedPageType.ID);
        }
        private PageTypeUpdater CreateFakePageTypeUpdaterWithUpdatePageTypeMethodHelperStubs()
        {
            MockRepository  mocks           = new MockRepository();
            PageTypeUpdater pageTypeUpdater = mocks.PartialMock <PageTypeUpdater>(
                PageTypeDefinitionLocatorFactory.Stub(),
                new PageTypeRepository(),
                new PageTypeValueExtractor(),
                new PageTypeLocator(new PageTypeRepository()));
            PageTypeRepository pageTypeRepository = mocks.Stub <PageTypeRepository>();

            pageTypeRepository.Stub(factory => factory.Save(Arg <IPageType> .Is.Anything));
            pageTypeRepository.Replay();
            pageTypeUpdater.PageTypeRepository = pageTypeRepository;
            pageTypeUpdater.Stub(updater => updater.GetExistingPageType(Arg <PageTypeDefinition> .Is.Anything)).Return(new NativePageType());
            pageTypeUpdater.Stub(updater => updater.UpdateName(Arg <IPageType> .Is.Anything, Arg <PageTypeDefinition> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateFilename(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateSortOrder(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDescription(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateIsAvailable(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDefaultArchivePageLink(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDefaultChildOrderRule(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDefaultPageName(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDefaultPeerOrder(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDefaultStartPublishOffset(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDefaultStopPublishOffset(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateDefaultVisibleInMenu(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateFrame(Arg <IPageType> .Is.Anything, Arg <PageTypeAttribute> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.UpdateAvailablePageTypes(Arg <IPageType> .Is.Anything, Arg <Type[]> .Is.Anything));
            pageTypeUpdater.Stub(updater => updater.SerializeValues(Arg <IPageType> .Is.Anything)).Repeat.Once().Return(string.Empty);
            pageTypeUpdater.Stub(updater => updater.SerializeValues(Arg <IPageType> .Is.Anything)).Repeat.Once().Return("test");
            pageTypeUpdater.Replay();
            return(pageTypeUpdater);
        }
        protected internal virtual IPageType CreateNewPageType(PageTypeDefinition definition)
        {
            IPageType pageType = PageTypeRepository.CreateNew();

            PageTypeAttribute attribute = definition.Attribute;

            string name = attribute.Name;

            if (name == null)
            {
                name = definition.Type.Name;
            }
            pageType.Name = name;

            if (definition.Attribute.Guid.HasValue)
            {
                pageType.GUID = definition.Attribute.Guid.Value;
            }

            string filename = attribute.Filename;

            if (string.IsNullOrEmpty(filename))
            {
                filename = DefaultFilename;
            }
            pageType.FileName = filename;

            PageTypeRepository.Save(pageType);

            NewlyCreatedPageTypes.Add(pageType);
            return(pageType);
        }
Esempio n. 5
0
        public void Initialize(InitializationEngine context)
        {
            _tagService = new TagService();
            _pageTypeRepository = ServiceLocator.Current.GetInstance<PageTypeRepository>();

            DataFactory.Instance.PublishedPage += OnPublishedPage;
        }
Esempio n. 6
0
 public NewsPageCreator(PageTypeRepository pageTypeRepository, IContentRepository contentRepository,
                        IEipaFileHelper eipaFileHelper, INewsPageMapper newsPageMapper)
 {
     PageTypeRepository = pageTypeRepository;
     ContentRepository  = contentRepository;
     EipaFileHelper     = eipaFileHelper;
     NewsPageMapper     = newsPageMapper;
 }
        public PageDefinition GetPageDefinition(string name, string pageTypeName)
        {
            var pageType = PageTypeRepository.Load(pageTypeName);

            return(PageDefinitionRepository.List(pageType.ID)
                   .Where(def => def.Name == name)
                   .FirstOrDefault());
        }
Esempio n. 8
0
        public void WhenPageTypeFactoryPropertySet_SetsPageTypeFactoryPropertyValue()
        {
            PageTypeUpdater pageTypeUpdater = CreatePageTypeUpdater();

            PageTypeRepository setPageTypeRepository = new PageTypeRepository();

            pageTypeUpdater.PageTypeRepository = setPageTypeRepository;

            Assert.Equal <IPageTypeRepository>(setPageTypeRepository, pageTypeUpdater.PageTypeRepository);
        }
        private void SetupPageTypeUpdaterWithFakePageTypeFactory(PageTypeUpdater pageTypeUpdater)
        {
            MockRepository     mocks = new MockRepository();
            PageTypeRepository fakePageTypeRepository = mocks.Stub <PageTypeRepository>();

            fakePageTypeRepository.Stub(factory => factory.Save(Arg <IPageType> .Is.NotNull));
            fakePageTypeRepository.Stub(factory => factory.CreateNew()).Return(new NativePageType());
            fakePageTypeRepository.Replay();
            pageTypeUpdater.PageTypeRepository = fakePageTypeRepository;
        }
Esempio n. 10
0
        public void GetPageTypesToAdd_IsNotEmpty()
        {
            var repo = new PageTypeRepository(getPageTypes());

            var types = repo.GetPageTypesToAdd();

            Assert.IsTrue(types.Any());
            Assert.IsTrue(types["primary"].Any());
            Assert.IsTrue(types["other"].Any());
        }
Esempio n. 11
0
        public void GetPageTypesToAdd_PageListingContainsPage_DoesNotContainPageListing()
        {
            var repo = new PageTypeRepository(getPageTypes());

            var typesDict = repo.GetPageTypesToAdd("pageListing");
            var types = typesDict["primary"];
            types.AddRange(typesDict["other"]);

            Assert.IsTrue(types.Any(p => p.Key == "page"));
            Assert.IsFalse(types.Any(p => p.Key == "pageListing"));
        }
Esempio n. 12
0
        /// <summary>
        /// Configures the api.
        /// </summary>
        /// <param name="modelCache">The optional model cache</param>
        /// <param name="imageProcessor">The optional image processor</param>
        private void Setup(IContentServiceFactory factory, ICache modelCache = null, IImageProcessor imageProcessor = null)
        {
            cache = modelCache;

            var cacheLevel = (int)App.CacheLevel;

            Aliases    = new AliasRepository(this, db, cacheLevel > 2 ? cache : null);
            Archives   = new ArchiveRepository(this, db);
            Categories = new CategoryRepository(this, db, cacheLevel > 2 ? cache : null);
            Media      = new MediaRepository(this, db, storage, cacheLevel > 2 ? cache : null, imageProcessor);
            Pages      = new PageRepository(this, db, factory, cacheLevel > 2 ? cache : null);
            PageTypes  = new PageTypeRepository(db, cacheLevel > 1 ? cache : null);
            Params     = new ParamRepository(db, cacheLevel > 0 ? cache : null);
            Posts      = new PostRepository(this, db, factory, cacheLevel > 2 ? cache : null);
            PostTypes  = new PostTypeRepository(db, cacheLevel > 1 ? cache : null);
            Sites      = new SiteRepository(this, db, cacheLevel > 0 ? cache : null);
            Tags       = new TagRepository(db, cacheLevel > 2 ? cache : null);
        }
Esempio n. 13
0
        public void GivenPageTypeWithNoGuidOrSpecifiedName_GetExistingPageType_ReturnsPageTypeReturnedFromPageTypeFactoryLoad()
        {
            MockRepository     mockRepository         = new MockRepository();
            PageTypeDefinition pageTypeDefinition     = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeRepository fakePageTypeRepository = mockRepository.Stub <PageTypeRepository>();
            IPageType          pageTypeFromFactory    = new NativePageType();

            pageTypeFromFactory.ID = 1;
            fakePageTypeRepository.Expect(factory => factory.Load(pageTypeDefinition.Type.Name)).Return(pageTypeFromFactory);
            fakePageTypeRepository.Replay();
            PageTypeUpdater pageTypeUpdater = PageTypeUpdaterFactory.Create(
                PageTypeDefinitionLocatorFactory.Stub(), fakePageTypeRepository);

            IPageType returnedPageType = pageTypeUpdater.GetExistingPageType(pageTypeDefinition);

            fakePageTypeRepository.AssertWasCalled(factory => factory.Load(pageTypeDefinition.Type.Name));
            Assert.Equal <int>(pageTypeFromFactory.ID, returnedPageType.ID);
        }
        protected internal virtual void UpdatePageType(PageTypeDefinition definition)
        {
            IPageType         pageType       = GetExistingPageType(definition);
            PageTypeAttribute attribute      = definition.Attribute;
            string            oldValueString = SerializeValues(pageType);

            UpdateName(pageType, definition);
            UpdateFilename(pageType, attribute);
            UpdateSortOrder(pageType, attribute);
            UpdateDescription(pageType, attribute);
            UpdateIsAvailable(pageType, attribute);
            UpdateDefaultArchivePageLink(pageType, attribute);
            UpdateDefaultChildOrderRule(pageType, attribute);
            UpdateDefaultPageName(pageType, attribute);
            UpdateDefaultPeerOrder(pageType, attribute);
            UpdateDefaultStartPublishOffset(pageType, attribute);
            UpdateDefaultStopPublishOffset(pageType, attribute);
            UpdateDefaultVisibleInMenu(pageType, attribute);
            UpdateFrame(pageType, attribute);

            bool availablePageTypesSet = false;

            if (CanModifyProperty(pageType, attribute.AvailablePageTypesSet))
            {
                UpdateAvailablePageTypes(pageType, attribute.AvailablePageTypes);

                if (attribute.AvailablePageTypes != null && attribute.AvailablePageTypes.Length > 0)
                {
                    availablePageTypesSet = true;
                }
            }

            if (!availablePageTypesSet && CanModifyProperty(pageType, attribute.ExcludedPageTypesSet) && attribute.ExcludedPageTypes != null)
            {
                UpdateAvailablePageTypesExcluded(pageType, attribute.ExcludedPageTypes);
            }

            string newValuesString = SerializeValues(pageType);

            if (newValuesString != oldValueString)
            {
                PageTypeRepository.Save(pageType);
            }
        }
        protected internal void UpdateAvailablePageTypesExcluded(IPageType pageType, Type[] excludedPageTypeTypes)
        {
            if (excludedPageTypeTypes == null || excludedPageTypeTypes.Length == 0)
            {
                pageType.AllowedPageTypes = null;
                return;
            }
            List <int> availablePageTypeIds = PageTypeRepository.List().Select(currentPageType => currentPageType.ID).ToList();

            foreach (Type excludedPageTypeType in excludedPageTypeTypes)
            {
                Type currentExcludedPageTypeType = excludedPageTypeType;

                if (IsValidPageType(currentExcludedPageTypeType))
                {
                    IPageType availablePageType = GetExistingPageType(_pageTypeDefinitions.
                                                                      First(definition => definition.Type.GUID == currentExcludedPageTypeType.GUID));

                    if (availablePageTypeIds.Contains(availablePageType.ID))
                    {
                        availablePageTypeIds.Remove(availablePageType.ID);
                    }
                }
                else if (currentExcludedPageTypeType.IsSubclassOf(typeof(TypedPageData)))
                {
                    foreach (int pageTypeId in GetPageDefinitionsThatInheritFromType(_pageTypeDefinitions, currentExcludedPageTypeType).Where(availablePageTypeIds.Contains))
                    {
                        availablePageTypeIds.Remove(pageTypeId);
                    }
                }
                else if (currentExcludedPageTypeType.IsInterface)
                {
                    foreach (int pageTypeId in GetPageDefinitionsThatImplementInteface(_pageTypeDefinitions, currentExcludedPageTypeType).Where(availablePageTypeIds.Contains))
                    {
                        availablePageTypeIds.Remove(pageTypeId);
                    }
                }
            }

            pageType.AllowedPageTypes = availablePageTypeIds.ToArray();
        }
Esempio n. 16
0
 public TagsScheduledJob(ITagService tagService)
 {
     _tagService = tagService;
     _pageTypeRepository = ServiceLocator.Current.GetInstance<PageTypeRepository>();
 }
 public MiniLockingCachedFindPagesWithCriterion(SearchPages searchPages, PageTypeRepository pageTypeRepository, ISynchronizedObjectInstanceCache synchronizedObjectInstanceCache)
 {
     _searchPages = searchPages;
     _pageTypeRepository = pageTypeRepository;
     _synchronizedObjectInstanceCache = synchronizedObjectInstanceCache;
 }
Esempio n. 18
0
 static PageTypeHelper()
 {
     PageTypeRepository = new PageTypeRepository();
 }
 public FindPagesWithCritera(IPageCriteriaQueryService searchPages, PageTypeRepository pageTypeRepository)
 {
     _searchPages = searchPages;
     _pageTypeRepository = pageTypeRepository;
 }
Esempio n. 20
0
 public TagsScheduledJob(ITagService tagService)
 {
     _tagService         = tagService;
     _pageTypeRepository = ServiceLocator.Current.GetInstance <PageTypeRepository>();
 }