public static string Update (DnnComboBox comboWorkingHours, string workingHours, bool addToVocabulary)
        {
            workingHours = workingHours.Trim ();
            var workingHoursNonEmpty = !string.IsNullOrWhiteSpace (workingHours);

            if (comboWorkingHours.SelectedIndex <= 0 || workingHoursNonEmpty)
            {
                // REVIEW: Shouldn't we try to add term after updating main item?
                if (addToVocabulary && workingHoursNonEmpty)
                {
                    // try add new term to University_WorkingHours vocabulary
                    var vocCtrl = new VocabularyController ();
                    var voc = vocCtrl.GetVocabularies ().SingleOrDefault (v => v.Name == "University_WorkingHours");
                    if (voc != null)
                    {
                        var termCtrl = new TermController ();
                        termCtrl.AddTerm (new Term (workingHours, "", voc.VocabularyId)); 
                        vocCtrl.ClearVocabularyCache ();
                    }
                }

                return workingHours;
            }

            // else: get working hours from a combo
            return comboWorkingHours.SelectedItem.Text;
        }
Exemplo n.º 2
0
        public void TermController_AddTerm_Throws_On_Null_Term()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var termController = new TermController(mockDataService.Object);

            //Act, Arrange
            Assert.Throws<ArgumentNullException>(() => termController.AddTerm(null));
        }
 public static void Init (PortalModuleBase module, DnnComboBox comboWorkingHours)
 {
     // fill working hours terms
     var termCtrl = new TermController ();
     var workingHours = termCtrl.GetTermsByVocabulary ("University_WorkingHours").ToList ();
     workingHours.Insert (0, new Term (Localization.GetString ("NotSelected.Text", module.LocalResourceFile)));
     comboWorkingHours.DataSource = workingHours;
     comboWorkingHours.DataBind ();
 }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
		public HttpResponseMessage Exist(int vocabularyId, int termId, int parentId, string termName)
		{
			var exists = false;

			var controller = new TermController();
			var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.VocabularyId == vocabularyId);
			if (vocabulary != null && !string.IsNullOrEmpty(termName))
			{
				var terms = controller.GetTermsByVocabulary(vocabularyId);
				exists = terms.Any(t => t.Name.Equals(termName.Trim(), StringComparison.InvariantCultureIgnoreCase) && t.TermId != termId && (parentId < 0 || t.ParentTermId == parentId));
			}

			return Request.CreateResponse(HttpStatusCode.OK, exists);
		}
Exemplo n.º 6
0
        public void TermController_AddTermToContent_Should_Call_DataService_If_Valid_Params()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            ContentItem content = ContentTestHelper.CreateValidContentItem();
            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);

            // Act
            termController.AddTermToContent(term, content);

            // Assert
            mockDataService.Verify(ds => ds.AddTermToContent(term, content));
        }
Exemplo n.º 7
0
		public HttpResponseMessage Search(int vocabularyId, int termId, int parentId, string termName)
		{
			IList<SearchResult> results = new List<SearchResult>();

			var controller = new TermController();
			var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.VocabularyId == vocabularyId);
			if (vocabulary != null && !string.IsNullOrEmpty(termName))
			{
				var terms = controller.GetTermsByVocabulary(vocabularyId);
				var relatedTerms = terms.Where(t => t.Name.ToLowerInvariant().Contains(termName.Trim().ToLowerInvariant()) && t.TermId != termId && (parentId < 0 || t.ParentTermId == parentId));

				foreach (Term term in relatedTerms)
				{
					results.Add(new SearchResult(){label = term.Name, value = term.Name});
				}
			}

			return Request.CreateResponse(HttpStatusCode.OK, results);
		}
		/// <summary>
		/// Handles Init event for a control.
		/// </summary>
		/// <param name="e">Event args.</param>
		protected override void OnInit (EventArgs e)
		{
			base.OnInit (e);

			// set url for Cancel link
			linkCancel.NavigateUrl = Globals.NavigateURL ();

			// add confirmation dialog to delete button
			buttonDelete.Attributes.Add ("onClick", "javascript:return confirm('" + Localization.GetString ("DeleteItem") + "');");

			// parse QueryString
			itemId = Utils.ParseToNullableInt (Request.QueryString ["division_id"]);
		
			// fill divisions dropdown
            var divisions = DivisionController.GetObjects<DivisionInfo> ()
                // exclude current division
                .Where (d => (itemId == null || itemId != d.DivisionID)).OrderBy (dd => dd.Title).ToList ();

            // insert default item
            divisions.Insert (0, DivisionInfo.DefaultItem (LocalizeString ("NotSelected.Text")));

            // bind divisions to the tree
            treeParentDivisions.DataSource = divisions;
            treeParentDivisions.DataBind ();

			// init working hours
			WorkingHoursLogic.Init (this, comboWorkingHours);
			
			// Fill terms list
			// TODO: Org. structure vocabulary name must be set in settings
			var termCtrl = new TermController ();
			var terms = termCtrl.GetTermsByVocabulary ("University_Structure").ToList (); 

			// add default term, 
			// TermId = Null.NullInteger is set in cstor
			terms.Insert (0, new Term (Localization.GetString ("NotSelected.Text", LocalResourceFile)));

            // bind terms to the tree
            treeDivisionTerms.DataSource = terms;
            treeDivisionTerms.DataBind ();
		}
		protected void DisplayDivision (DivisionInfo division)
		{
			// division title
			var divisionTitle = division.Title;

			// add division short title
			if (division.HasUniqueShortTitle)
			{
				divisionTitle += string.Format (" ({0})", division.ShortTitle);
			}

			// home page 
			int homeTabId;
			if (int.TryParse (division.HomePage, out homeTabId) && TabId != homeTabId)
			{
				// has home page, display as link 
				linkHomePage.Text = divisionTitle;
				linkHomePage.NavigateUrl = Globals.NavigateURL (homeTabId);
				labelTitle.Visible = false;
			}
			else
			{
				// no home page, display as label
				labelTitle.Text = divisionTitle;
				linkHomePage.Visible = false;
			}

			// link to division resources
			var displaySearchByTerm = false;
			if (division.DivisionTermID != null)
			{
				var termCtrl = new TermController ();
				var term = termCtrl.GetTerm (division.DivisionTermID.Value);
				if (term != null)
				{
					// NOTE: Add raw tag to Globals.NavigateURL to allow search work 
					// independently of current friendly urls settings
					// linkSearchByTerm.NavigateUrl = "/Default.aspx?tabid=" + PortalSettings.SearchTabId + "&tag=" + term.Name;
					linkSearchByTerm.NavigateUrl = Globals.NavigateURL (PortalSettings.SearchTabId) + "?tag=" + term.Name;
					displaySearchByTerm = true;
				}
			}

			if (!displaySearchByTerm)
				linkSearchByTerm.Visible = false;

			// WebSite
			if (!string.IsNullOrWhiteSpace (division.WebSite))
			{
				linkWebSite.NavigateUrl = division.FormatWebSiteUrl;
				linkWebSite.Text = division.FormatWebSiteLabel;
			}
			else
				linkWebSite.Visible = false;
				
			// email
			if (!string.IsNullOrWhiteSpace (division.Email))
			{
				linkEmail.Text = division.Email;
				linkEmail.NavigateUrl = "mailto:" + division.Email;
			}
			else
				linkEmail.Visible = false;

			// secondary email
			if (!string.IsNullOrWhiteSpace (division.SecondaryEmail))
			{
				linkSecondaryEmail.Text = division.SecondaryEmail;
				linkSecondaryEmail.NavigateUrl = "mailto:" + division.SecondaryEmail;
			}
			else
				linkSecondaryEmail.Visible = false;

			// phone
			if (!string.IsNullOrWhiteSpace (division.Phone))
				labelPhone.Text = division.Phone;
			else
				labelPhone.Visible = false;

			// fax
			if (!string.IsNullOrWhiteSpace (division.Fax))
				labelFax.Text = string.Format (Localization.GetString ("Fax.Format", LocalResourceFile), division.Fax);
			else
				labelFax.Visible = false;

			// location
			if (!string.IsNullOrWhiteSpace (division.Location))
				labelLocation.Text = division.Location;
			else
				labelLocation.Visible = false;

			// working hours
			if (!string.IsNullOrWhiteSpace (division.WorkingHours))
				labelWorkingHours.Text = division.WorkingHours;
			else
				labelWorkingHours.Visible = false;

			// document
			if (!string.IsNullOrWhiteSpace (division.DocumentUrl))
			{
				// apply CSS class according to url type or file extension
				var urlType = Globals.GetURLType (division.DocumentUrl);
				if (urlType == TabType.File)
				{
					var file = FileManager.Instance.GetFile (int.Parse (division.DocumentUrl.Remove (0, "FileID=".Length)));
					linkDocumentUrl.CssClass += " " + file.Extension.ToLowerInvariant ();
				}
				else if (urlType == TabType.Tab)
					linkDocumentUrl.CssClass += " page";
				else 
					linkDocumentUrl.CssClass += " url";

				linkDocumentUrl.Text = LocalizeString ("DocumentUrl.Text");
				linkDocumentUrl.NavigateUrl = Globals.LinkClick (division.DocumentUrl, TabId, ModuleId);
				linkDocumentUrl.Target = "_blank";
			}
			else
				linkDocumentUrl.Visible = false;

			// barcode image test
			var barcodeWidth = DivisionSettings.BarcodeWidth;
            imageBarcode.ImageUrl = R7.University.Utilities.UrlUtils.FullUrl (string.Format (
                "/imagehandler.ashx?barcode=1&width={0}&height={1}&type=qrcode&encoding=UTF-8&content={2}",
				barcodeWidth, barcodeWidth, 
				Server.UrlEncode (division.VCard.ToString ()
						.Replace ("+", "%2b")) // fix for "+" signs in phone numbers
            ));

			imageBarcode.ToolTip = Localization.GetString ("imageBarcode.ToolTip", LocalResourceFile);
			imageBarcode.AlternateText = Localization.GetString ("imageBarcode.AlternateText", LocalResourceFile);

			// get & bind subdivisions
			var subDivisions = DivisionController.GetObjects<DivisionInfo> (
				                   "WHERE [ParentDivisionID] = @0 ORDER BY [Title]", division.DivisionID); 
			
            if (subDivisions.Any ())
			{
				repeatSubDivisions.DataSource = subDivisions;
				repeatSubDivisions.DataBind ();
			}
		}
Exemplo n.º 10
0
        public void TermController_UpdateTerm_Throws_On_Negative_VocabularyId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);

            //Act, Arrange
            Assert.Throws<ArgumentException>(() => termController.UpdateTerm(term));
        }
Exemplo n.º 11
0
        public void TermController_UpdateTerm_Clears_Term_Cache_On_Valid_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
            term.TermId = Constants.TERM_UpdateTermId;
            term.Name = Constants.TERM_UpdateName;
            term.Weight = Constants.TERM_UpdateWeight;

            //Act
            termController.UpdateTerm(term);

            //Assert
            mockCache.Verify(
                cache => cache.Remove(String.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
        }
Exemplo n.º 12
0
        public void TermController_RemoveTermsFromContent_Should_Call_DataService_If_Valid_Params()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            ContentItem content = ContentTestHelper.CreateValidContentItem();

            // Act
            termController.RemoveTermsFromContent(content);

            // Assert
            mockDataService.Verify(ds => ds.RemoveTermsFromContent(content));
        }
Exemplo n.º 13
0
        public void TermController_GetTerm_Returns_Term_On_Valid_TermId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId))
                .Returns(MockHelper.CreateValidTermReader());

            TermController termController = new TermController(mockDataService.Object);

            //Act
            Term term = termController.GetTerm(Constants.TERM_ValidTermId);

            //Assert
            Assert.AreEqual(Constants.TERM_ValidTermId, term.TermId);
            Assert.AreEqual(Constants.TERM_ValidName, term.Name);
        }
Exemplo n.º 14
0
        public void TermController_GetTerm_Calls_DataService()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId))
                .Returns(MockHelper.CreateValidTermReader());
            TermController termController = new TermController(mockDataService.Object);

            //Act
            Term term = termController.GetTerm(Constants.TERM_ValidTermId);

            //Assert
            mockDataService.Verify(ds => ds.GetTerm(Constants.TERM_ValidTermId));
        }
Exemplo n.º 15
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 && v.ScopeId == tabPortalId)
                                       .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.OrdinalIgnoreCase)
                               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.OrdinalIgnoreCase));
                    if (term == null)
                    {
                        var termId = termController.AddTerm(new Term(tag, string.Empty, vocabularyId));
                        term = termController.GetTerm(termId);
                    }

                    terms.Add(term);
                }
            }

            return(terms);
        }
Exemplo n.º 16
0
        public void TermController_GetTermsByVocabulary_Throws_On_Invalid_VocabularyId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            //Act, Arrange
            Assert.Throws<ArgumentOutOfRangeException>(() => termController.GetTermsByVocabulary(Null.NullInteger));
        }
Exemplo n.º 17
0
        public void TermController_AddTerm_Returns_Valid_Id_On_Valid_Term_If_Term_Is_Heirarchical_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController 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
            int termId = termController.AddTerm(term);

            //Assert
            Assert.AreEqual(Constants.TERM_AddTermId, termId);
        }
Exemplo n.º 18
0
        public void TermController_GetTerm_Returns_Null_On_InValidTermId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_InValidTermId))
                .Returns(MockHelper.CreateEmptyTermReader());

            TermController termController = new TermController(mockDataService.Object);

            //Act
            Term term = termController.GetTerm(Constants.TERM_InValidTermId);

            //Assert
            Assert.IsNull(term);
        }
Exemplo n.º 19
0
        public void TermController_AddTerm_Sets_Valid_Id_On_Valid_Term_If_Term_Is_Simple_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController 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
            termController.AddTerm(term);

            //Assert
            Assert.AreEqual(Constants.TERM_AddTermId, term.TermId);
        }
Exemplo n.º 20
0
        public void TermController_GetTerm_Throws_On_Negative_TermId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            //Act, Arrange
            Assert.Throws<ArgumentOutOfRangeException>(() => termController.GetTerm(Null.NullInteger));
        }
Exemplo n.º 21
0
        public void TermController_AddTerm_Should_Call_DataService_AddSimpleTerm_If_Term_Is_Simple_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

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

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

            // Assert
            mockDataService.Verify(ds => ds.AddSimpleTerm(term, UserController.GetCurrentUserInfo().UserID));
        }
Exemplo n.º 22
0
        public void TermController_RemoveTermsFromContent_Throws_On_Null_ContentItem()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            //Act, Arrange
            AutoTester.ArgumentNull<ContentItem>(content => termController.RemoveTermsFromContent(content));
        }
Exemplo n.º 23
0
        public void TermController_DeleteTerm_Clears_Term_Cache_On_Valid_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            Term term = new Term(Constants.VOCABULARY_ValidVocabularyId) {TermId = Constants.TERM_DeleteTermId};

            //Act
            termController.DeleteTerm(term);

            //Assert
            mockCache.Verify(
                cache => cache.Remove(String.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
        }
Exemplo n.º 24
0
        public void TermController_UpdateTerm_Should_Call_DataService_UpdateSimpleTerm_If_Term_Is_Simple_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
            term.TermId = Constants.TERM_UpdateTermId;
            term.Name = Constants.TERM_UpdateName;
            term.Weight = Constants.TERM_UpdateWeight;

            // Act
            termController.UpdateTerm(term);

            // Assert
            mockDataService.Verify(ds => ds.UpdateSimpleTerm(term, UserController.GetCurrentUserInfo().UserID));
        }
Exemplo n.º 25
0
        public void TermController_DeleteTerm_Should_Call_DataService_DeleteSimpleTerm_If_Term_Is_Simple_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

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

            // Act
            termController.DeleteTerm(term);

            // Assert
            mockDataService.Verify(ds => ds.DeleteSimpleTerm(term));
        }
Exemplo n.º 26
0
        public void TermController_UpdateTerm_Throws_On_Null_Term()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            //Act, Arrange
            AutoTester.ArgumentNull<Term>(term => termController.UpdateTerm(term));
        }
Exemplo n.º 27
0
        public void TermController_DeleteTerm_Throws_On_Negative_TermId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
            term.TermId = Null.NullInteger;

            //Act, Arrange
            Assert.Throws<ArgumentException>(() => termController.DeleteTerm(term));
        }
Exemplo n.º 28
0
        public void TermController_AddTermToContent_Throws_On_Null_ContentItem()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            TermController termController = new TermController(mockDataService.Object);

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

            //Act, Arrange
            AutoTester.ArgumentNull<ContentItem>(content => termController.AddTermToContent(term, content));
        }
Exemplo n.º 29
0
        public void TermController_GetTermsByContent_Calls_DataService()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1))
                .Returns(MockHelper.CreateValidTermsReader(Constants.TERM_ValidCountForContent1,
                                                           v => Constants.TERM_ValidVocabularyId,
                                                           c => Constants.TERM_ValidContent1));
            TermController termController = new TermController(mockDataService.Object);

            //Act
            IQueryable<Term> terms = termController.GetTermsByContent(Constants.TERM_ValidContent1);

            //Assert
            mockDataService.Verify(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1));
        }
Exemplo n.º 30
0
        private static void ImportDocumentLibraryCategoryAssoc(ContentType fileContentType)
        {
            DataProvider dataProvider = DataProvider.Instance();
            IDataReader dr;
            try
            {
                dr = dataProvider.ExecuteReader("ImportDocumentLibraryCategoryAssoc");
                var termController = new TermController();
                var vocabulary = new VocabularyController().GetVocabularies().Single(v => v.Name == "Tags");
                var terms = termController.GetTermsByVocabulary(vocabulary.VocabularyId);

                while (dr.Read())
                {
                    var file = FileManager.Instance.GetFile((int)dr["FileId"]);
                    ContentItem attachContentItem;
                    if (file.ContentItemID == Null.NullInteger)
                    {
                        attachContentItem = CreateFileContentItem();
                        file.ContentItemID = attachContentItem.ContentItemId;
                        FileManager.Instance.UpdateFile(file);
                    }
                    else
                    {
                        attachContentItem = Util.GetContentController().GetContentItem(file.ContentItemID);
                    }

                    var term = terms.SingleOrDefault(t => t.Name == dr["CategoryName"].ToString());
                    if (term == null)
                    {
                        term = new Term(dr["CategoryName"].ToString(), null, vocabulary.VocabularyId);
                        termController.AddTerm(term);
                    }
                    termController.AddTermToContent(term, attachContentItem);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Exemplo n.º 31
0
        public void TermController_GetTermsByVocabulary_Returns_Terms_On_Valid_VocabularyId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1))
                .Returns(MockHelper.CreateValidTermsReader(Constants.TERM_ValidCountForVocabulary1,
                                                           v => Constants.TERM_ValidVocabulary1,
                                                           c => Constants.TERM_ValidContent1));
            TermController termController = new TermController(mockDataService.Object);

            //Act
            List<Term> terms = termController.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1).ToList();

            //Assert
            Assert.AreEqual(Constants.TERM_ValidCountForVocabulary1, terms.Count);

            for (int i = 0; i < Constants.TERM_ValidCountForVocabulary1; i++)
            {
                Assert.AreEqual(i + Constants.TERM_ValidTermId, terms[i].TermId);
                Assert.AreEqual(ContentTestHelper.GetTermName(i + Constants.TERM_ValidTermId), terms[i].Name);
            }
        }