Example #1
0
        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_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_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));
        }
Example #4
0
        public void VocabularyController_AddVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary()
        {
            //Arrange
            var mockDataService      = new Mock <IDataService>();
            var vocabularyController = new VocabularyController(mockDataService.Object);

            Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();

            //Act
            vocabularyController.AddVocabulary(vocabulary);

            //Assert
            mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey));
        }
Example #5
0
        public void VocabularyController_AddVocabulary_Calls_DataService_On_Valid_Arguments()
        {
            //Arrange
            var mockDataService      = new Mock <IDataService>();
            var 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 void VocabularyController_AddVocabulary_Returns_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
            int vocabularyId = vocabularyController.AddVocabulary(vocabulary);

            // Assert
            Assert.AreEqual(Constants.VOCABULARY_AddVocabularyId, vocabularyId);
        }
Example #7
0
        public int AddVocabulary(Vocabulary vocabulary)
        {
            if (vocabulary.ScopeType.ScopeType == Constants.VocabularyScopeTypeWebsite)
            {
                vocabulary.ScopeId = PortalSettings.Current.PortalId;
            }
            var result = _validator.ValidateObject(vocabulary);

            if (result.IsValid)
            {
                return(_vocabularyController.AddVocabulary(vocabulary));
            }
            else
            {
                throw new VocabularyNameAlreadyExistsException();
            }
        }