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;
        }
        public void VocabularyController_AddVocabulary_Throws_On_Null_Vocabulary()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var vocabularyController = new VocabularyController(mockDataService.Object);

            //Act, Arrange
            Assert.Throws<ArgumentNullException>(() => vocabularyController.AddVocabulary(null));
        }
        public void VocabularyController_AddVocabulary_Throws_On_Invalid_Name()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
            vocabulary.Name = Constants.VOCABULARY_InValidName;

            //Act, Arrange
            Assert.Throws<ArgumentException>(() => vocabularyController.AddVocabulary(vocabulary));
        }
		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);
		}
        public void VocabularyController_AddVocabulary_Calls_DataService_On_Valid_Arguments()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            VocabularyController vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();

            //Act
            int vocabularyId = vocabularyController.AddVocabulary(vocabulary);

            //Assert
            mockDataService.Verify(ds => ds.AddVocabulary(vocabulary, It.IsAny<int>()));
        }
		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);
		}
        public void VocabularyController_AddVocabulary_Throws_On_Negative_ScopeTypeID()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
            vocabulary.ScopeTypeId = Null.NullInteger;

            //Act, Arrange
            Assert.Throws<ArgumentOutOfRangeException>(() => vocabularyController.AddVocabulary(vocabulary));
        }
        public void VocabularyController__UpdateVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
            vocabulary.VocabularyId = Constants.VOCABULARY_UpdateVocabularyId;

            //Act
            vocabularyController.UpdateVocabulary(vocabulary);

            //Assert
            mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey));
        }
        public void VocabularyController_UpdateVocabulary_Calls_DataService_On_Valid_Arguments()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
            vocabulary.VocabularyId = Constants.VOCABULARY_UpdateVocabularyId;

            //Act
            vocabularyController.UpdateVocabulary(vocabulary);

            //Assert
            mockDataService.Verify(ds => ds.UpdateVocabulary(vocabulary, It.IsAny<int>()));
        }
        public void VocabularyController_GetVocabularies_Returns_List_Of_Vocabularies()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetVocabularies()).Returns(MockHelper.CreateValidVocabulariesReader(Constants.VOCABULARY_ValidCount));
            var vocabularyController = new VocabularyController(mockDataService.Object);

            //Act
            IQueryable<Vocabulary> vocabularys = vocabularyController.GetVocabularies();

            //Assert
            Assert.AreEqual(Constants.VOCABULARY_ValidCount, vocabularys.Count());
        }
        public void VocabularyController_AddVocabulary_Sets_ValidId_On_Valid_Vocabulary()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.AddVocabulary(It.IsAny<Vocabulary>(), It.IsAny<int>())).Returns(Constants.VOCABULARY_AddVocabularyId);
            var vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();

            //Act
            vocabularyController.AddVocabulary(vocabulary);

            //Assert
            Assert.AreEqual(Constants.VOCABULARY_AddVocabularyId, vocabulary.VocabularyId);
        }
Exemple #12
0
		/// <summary>
		/// Gets the vocabulary controller.
		/// </summary>
		/// <returns>VocabularyController from ComponentFactory.</returns>
        public static IVocabularyController GetVocabularyController()
        {
            var ctl = ComponentFactory.GetComponent<IVocabularyController>();

            if (ctl == null)
            {
                ctl = new VocabularyController();
                ComponentFactory.RegisterComponentInstance<IVocabularyController>(ctl);
            }
            return ctl;
        }
        public void VocabularyController_UpdateVocabulary_Throws_On_Null_Vocabulary()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            VocabularyController vocabularyController = new VocabularyController(mockDataService.Object);

            //Act, Arrange
            AutoTester.ArgumentNull<Vocabulary>(marker => vocabularyController.UpdateVocabulary(marker));
        }
        public void VocabularyController_UpdateVocabulary_Throws_On_Negative_VocabularyId()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            VocabularyController vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
            vocabulary.VocabularyId = Null.NullInteger;

            //Act, Arrange
            Assert.Throws<ArgumentException>(() => vocabularyController.UpdateVocabulary(vocabulary));
        }
        public void VocabularyController_GetVocabularies_Calls_DataService()
        {
            //Arrange
            Mock<IDataService> mockDataService = new Mock<IDataService>();
            mockDataService.Setup(ds => ds.GetVocabularies())
                .Returns(MockHelper.CreateValidVocabulariesReader(Constants.VOCABULARY_ValidCount));
            VocabularyController vocabularyController = new VocabularyController(mockDataService.Object);

            //Act
            IQueryable<Vocabulary> vocabularys = vocabularyController.GetVocabularies();

            //Assert
            mockDataService.Verify(ds => ds.GetVocabularies());
        }
Exemple #16
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);
            }
        }
Exemple #17
0
        private static void ImportDocumentLibraryCategories()
        {
            VocabularyController vocabularyController = new VocabularyController();
            var defaultTags = (from v in vocabularyController.GetVocabularies() where v.IsSystem && v.Name == "Tags" select v).SingleOrDefault();

            DataProvider dataProvider = DataProvider.Instance();
            dataProvider.ExecuteNonQuery("ImportDocumentLibraryCategories", defaultTags.VocabularyId);
        }
        public void VocabularyController_DeleteVocabulary_Throws_On_Negative_VocabularyId()
        {
            //Arrange
            var mockDataService = new Mock<IDataService>();
            var vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = new Vocabulary();
            vocabulary.VocabularyId = Null.NullInteger;

            //Act, Arrange
            Assert.Throws<ArgumentOutOfRangeException>(() => vocabularyController.DeleteVocabulary(vocabulary));
        }