예제 #1
0
        public void TermController_AddTerm_Throws_On_Invalid_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);

            term.Name = Constants.TERM_InValidName;

            //Act, Arrange
            Assert.Throws <ArgumentException>(() => termController.AddTerm(term));
        }
예제 #2
0
        public int AddTerm(Term term)
        {
            var result = _validator.ValidateObject(term);

            if (result.IsValid)
            {
                return(_termController.AddTerm(term));
            }
            else
            {
                throw new TermValidationException();
            }
        }
예제 #3
0
        public void TermController_AddTerm_Clears_Term_Cache_On_Valid_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);

            //Act
            termController.AddTerm(term);

            //Assert
            mockCache.Verify(cache => cache.Remove(String.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
        }
예제 #4
0
        public void TermController_AddTerm_Should_Call_DataService_AddHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);

            // Act
            int termId = termController.AddTerm(term);

            // Assert
            mockDataService.Verify(ds => ds.AddHeirarchicalTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
        }
예제 #5
0
        public void TermController_AddTerm_Sets_Valid_Id_On_Valid_Term_If_Term_Is_Heirarchical_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            mockDataService.Setup(ds => ds.AddHeirarchicalTerm(It.IsAny <Term>(), It.IsAny <int>())).Returns(Constants.TERM_AddTermId);

            Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);

            //Act
            termController.AddTerm(term);

            //Assert
            Assert.AreEqual(Constants.TERM_AddTermId, term.TermId);
        }
예제 #6
0
        public void TermController_AddTerm_Returns_Valid_Id_On_Valid_Term_If_Term_Is_Simple_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            mockDataService.Setup(ds => ds.AddSimpleTerm(It.IsAny <Term>(), It.IsAny <int>())).Returns(Constants.TERM_AddTermId);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);

            //Act
            int termId = termController.AddTerm(term);

            //Assert
            Assert.AreEqual(Constants.TERM_AddTermId, termId);
        }
예제 #7
0
        private void SaveTags()
        {
            string tags = new PortalSecurity().InputFilter(_Tags, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);

            tags = HttpContext.Current.Server.HtmlEncode(tags);
            if (!string.IsNullOrEmpty(tags))
            {
                foreach (string t in tags.Split(','))
                {
                    if (!string.IsNullOrEmpty(t))
                    {
                        string tagName      = t.Trim(' ');
                        Term   existingTerm = (from term in ContentItem.Terms.AsQueryable() where term.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select term).SingleOrDefault();

                        if (existingTerm == null)
                        {
                            //Not tagged
                            TermController termController = new TermController();
                            Term           term           =
                                (from te in termController.GetTermsByVocabulary(TagVocabulary.VocabularyId) where te.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select te).
                                SingleOrDefault();
                            if (term == null)
                            {
                                //Add term
                                term      = new Term(TagVocabulary.VocabularyId);
                                term.Name = tagName;
                                termController.AddTerm(term);
                            }

                            //Add term to content
                            ContentItem.Terms.Add(term);
                            termController.AddTermToContent(term, ContentItem);
                        }
                    }
                }
            }

            IsEditMode = false;

            //Raise the Tags Updated Event
            OnTagsUpdate(EventArgs.Empty);
        }
예제 #8
0
파일: Tags.cs 프로젝트: Mariusz11711/DNN
        private void SaveTags()
        {
            string tags = this._Tags;

            if (!string.IsNullOrEmpty(tags))
            {
                foreach (string t in tags.Split(','))
                {
                    if (!string.IsNullOrEmpty(t))
                    {
                        string tagName      = t.Trim(' ');
                        Term   existingTerm = (from term in this.ContentItem.Terms.AsQueryable() where term.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select term).SingleOrDefault();

                        if (existingTerm == null)
                        {
                            // Not tagged
                            TermController termController = new TermController();
                            Term           term           =
                                (from te in termController.GetTermsByVocabulary(this.TagVocabulary.VocabularyId) where te.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select te).
                                SingleOrDefault();
                            if (term == null)
                            {
                                // Add term
                                term      = new Term(this.TagVocabulary.VocabularyId);
                                term.Name = tagName;
                                termController.AddTerm(term);
                            }

                            // Add term to content
                            this.ContentItem.Terms.Add(term);
                            termController.AddTermToContent(term, this.ContentItem);
                        }
                    }
                }
            }

            this.IsEditMode = false;

            // Raise the Tags Updated Event
            this.OnTagsUpdate(EventArgs.Empty);
        }
예제 #9
0
        protected virtual void UpdateTabInfoFromPageSettings(TabInfo tab, PageSettings pageSettings)
        {
            tab.TabName     = pageSettings.Name;
            tab.TabPath     = Globals.GenerateTabPath(tab.ParentId, tab.TabName);
            tab.Title       = pageSettings.Title;
            tab.Description = GetTabDescription(pageSettings);
            tab.KeyWords    = GetKeyWords(pageSettings);
            tab.IsVisible   = pageSettings.IncludeInMenu;
            tab.DisableLink = pageSettings.DisableLink;

            tab.StartDate = pageSettings.StartDate ?? Null.NullDate;
            tab.EndDate   = pageSettings.EndDate ?? Null.NullDate;

            tab.IsSecure = pageSettings.IsSecure;
            tab.TabSettings["AllowIndex"] = pageSettings.AllowIndex;

            tab.SiteMapPriority = pageSettings.SiteMapPriority;
            tab.PageHeadText    = pageSettings.PageHeadText;

            tab.PermanentRedirect = pageSettings.PermanentRedirect;
            tab.Url = GetInternalUrl(pageSettings);

            tab.TabSettings["CacheProvider"] = pageSettings.CacheProvider;
            if (pageSettings.CacheProvider != null)
            {
                tab.TabSettings["CacheDuration"] = pageSettings.CacheDuration;
                if (pageSettings.CacheIncludeExclude.HasValue)
                {
                    if (pageSettings.CacheIncludeExclude.Value)
                    {
                        tab.TabSettings["CacheIncludeExclude"] = "1";
                        tab.TabSettings["IncludeVaryBy"]       = null;
                        tab.TabSettings["ExcludeVaryBy"]       = pageSettings.CacheExcludeVaryBy;
                    }
                    else
                    {
                        tab.TabSettings["CacheIncludeExclude"] = "0";
                        tab.TabSettings["IncludeVaryBy"]       = pageSettings.CacheIncludeVaryBy;
                        tab.TabSettings["ExcludeVaryBy"]       = null;
                    }
                    tab.TabSettings["MaxVaryByCount"] = pageSettings.CacheMaxVaryByCount;
                }
            }

            else
            {
                tab.TabSettings["CacheDuration"]       = null;
                tab.TabSettings["CacheIncludeExclude"] = null;
                tab.TabSettings["IncludeVaryBy"]       = null;
                tab.TabSettings["ExcludeVaryBy"]       = null;
                tab.TabSettings["MaxVaryByCount"]      = null;
            }

            tab.TabSettings["LinkNewWindow"]    = pageSettings.LinkNewWindow;
            tab.TabSettings["CustomStylesheet"] = pageSettings.PageStyleSheet;

            // Tab Skin
            tab.SkinSrc      = GetSkinSrc(pageSettings);
            tab.ContainerSrc = GetContainerSrc(pageSettings);

            if (pageSettings.PageType == "template")
            {
                tab.ParentId = GetTemplateParentId(tab.PortalID);
                tab.IsSystem = true;
            }

            tab.Terms.Clear();
            if (!string.IsNullOrEmpty(pageSettings.Tags))
            {
                tab.Terms.Clear();
                var termController       = new TermController();
                var vocabularyController = Util.GetVocabularyController();
                var vocabulary           = (vocabularyController.GetVocabularies()
                                            .Cast <Vocabulary>()
                                            .Where(v => v.Name == PageTagsVocabulary))
                                           .SingleOrDefault();

                int vocabularyId;
                if (vocabulary == null)
                {
                    var scopeType = Util.GetScopeTypeController().GetScopeTypes().SingleOrDefault(s => s.ScopeType == "Portal");
                    if (scopeType == null)
                    {
                        throw new Exception("Can't create default vocabulary as scope type 'Portal' can't finded.");
                    }

                    vocabularyId = vocabularyController.AddVocabulary(
                        new Vocabulary(PageTagsVocabulary, string.Empty, VocabularyType.Simple)
                    {
                        ScopeTypeId = scopeType.ScopeTypeId,
                        ScopeId     = tab.PortalID
                    });
                }
                else
                {
                    vocabularyId = vocabulary.VocabularyId;
                }

                //get all terms info
                var allTerms     = new List <Term>();
                var vocabularies = from v in vocabularyController.GetVocabularies()
                                   where (v.ScopeType.ScopeType == "Portal" && v.ScopeId == tab.PortalID && !v.Name.Equals("Tags", StringComparison.InvariantCultureIgnoreCase))
                                   select v;
                foreach (var v in vocabularies)
                {
                    allTerms.AddRange(termController.GetTermsByVocabulary(v.VocabularyId));
                }

                foreach (var tag in pageSettings.Tags.Trim().Split(','))
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        var term = allTerms.FirstOrDefault(t => t.Name.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
                        if (term == null)
                        {
                            var termId = termController.AddTerm(new Term(tag, string.Empty, vocabularyId));
                            term = termController.GetTerm(termId);
                        }

                        tab.Terms.Add(term);
                    }
                }
            }
        }
예제 #10
0
        public static List <Term> ToTabTerms(string pageSettingsTags, int tabPortalId)
        {
            var terms = new List <Term>();

            if (string.IsNullOrEmpty(pageSettingsTags))
            {
                return(terms);
            }

            var termController       = new TermController();
            var vocabularyController = Util.GetVocabularyController();
            var vocabulary           = (vocabularyController.GetVocabularies()
                                        .Cast <Vocabulary>()
                                        .Where(v => v.Name == PageTagsVocabulary))
                                       .SingleOrDefault();

            var vocabularyId = Null.NullInteger;

            if (vocabulary == null)
            {
                var scopeType = Util.GetScopeTypeController().GetScopeTypes().SingleOrDefault(s => s.ScopeType == "Portal");
                if (scopeType == null)
                {
                    throw new Exception("Can't create default vocabulary as scope type 'Portal' can't finded.");
                }

                vocabularyId = vocabularyController.AddVocabulary(
                    new Vocabulary(PageTagsVocabulary, string.Empty, VocabularyType.Simple)
                {
                    ScopeTypeId = scopeType.ScopeTypeId,
                    ScopeId     = tabPortalId
                });
            }
            else
            {
                vocabularyId = vocabulary.VocabularyId;
            }

            //get all terms info
            var allTerms     = new List <Term>();
            var vocabularies = from v in vocabularyController.GetVocabularies()
                               where (v.ScopeType.ScopeType == "Portal" && v.ScopeId == tabPortalId && !v.Name.Equals("Tags", StringComparison.InvariantCultureIgnoreCase))
                               select v;

            foreach (var v in vocabularies)
            {
                allTerms.AddRange(termController.GetTermsByVocabulary(v.VocabularyId));
            }

            foreach (var tag in pageSettingsTags.Trim().Split(','))
            {
                if (!string.IsNullOrEmpty(tag))
                {
                    var term = allTerms.FirstOrDefault(t => t.Name.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
                    if (term == null)
                    {
                        var termId = termController.AddTerm(new Term(tag, string.Empty, vocabularyId));
                        term = termController.GetTerm(termId);
                    }

                    terms.Add(term);
                }
            }


            return(terms);
        }