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)); }
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)); }
public void TermController_DeleteTerm_Throws_On_Negative_TermId() { //Arrange var mockDataService = new Mock <IDataService>(); var termController = new TermController(mockDataService.Object); var term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId); term.TermId = Null.NullInteger; //Act, Arrange Assert.Throws <ArgumentOutOfRangeException>(() => termController.DeleteTerm(term)); }
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))); }
public void TermController_RemoveTermsFromContent_Should_Call_DataService_If_Valid_Params() { //Arrange var mockDataService = new Mock <IDataService>(); var termController = new TermController(mockDataService.Object); ContentItem content = ContentTestHelper.CreateValidContentItem(); // Act termController.RemoveTermsFromContent(content); // Assert mockDataService.Verify(ds => ds.RemoveTermsFromContent(content)); }
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.GetCurrentUserInfo().UserID)); }
internal static IDataReader CreateValidContentItemReader(ContentItem contentItem) { DataTable table = CreateContentItemTable(); AddContentItemToTable(table, contentItem.ContentItemId, ContentTestHelper.GetContent(contentItem.ContentItemId), ContentTestHelper.GetContentKey(contentItem.ContentItemId), true, Constants.USER_ValidId, Null.NullString); return(table.CreateDataReader()); }
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)); }
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 TermController_AddTermToContent_Should_Call_DataService_If_Valid_Params() { //Arrange var mockDataService = new Mock <IDataService>(); var 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)); }
internal static IDataReader CreateValidVocabulariesReader(int count) { DataTable table = CreateVocabularyTable(); for (int i = Constants.VOCABULARY_ValidVocabularyId; i < Constants.VOCABULARY_ValidVocabularyId + count; i++) { string name = (count == 1) ? Constants.VOCABULARY_ValidName : ContentTestHelper.GetVocabularyName(i); int typeId = Constants.VOCABULARY_SimpleTypeId; string description = (count == 1) ? Constants.VOCABULARY_ValidName : ContentTestHelper.GetVocabularyName(i); int weight = Constants.VOCABULARY_ValidWeight; AddVocabularyToTable(table, i, typeId, name, description, Constants.VOCABULARY_ValidScopeId, Constants.VOCABULARY_ValidScopeTypeId, weight); } return(table.CreateDataReader()); }
internal static IDataReader CreateValidContentItemsReader(int count, bool indexed, int startUserId, string term) { DataTable table = CreateContentItemTable(); for (int i = Constants.CONTENT_ValidContentItemId; i < Constants.CONTENT_ValidContentItemId + count; i++) { string content = (count == 1) ? Constants.CONTENT_ValidContent : ContentTestHelper.GetContent(i); string contentKey = (count == 1) ? Constants.CONTENT_ValidContentKey : ContentTestHelper.GetContentKey(i); int userId = (startUserId == Null.NullInteger) ? Constants.USER_ValidId + i : startUserId; AddContentItemToTable(table, i, content, contentKey, indexed, startUserId, term); } return(table.CreateDataReader()); }
internal static IDataReader CreateValidTermsReader(int count, Func <int, int> vocabularyIdFunction, Func <int, int> contentIdFunction) { DataTable table = CreateTermTable(); for (int i = Constants.TERM_ValidTermId; i < Constants.TERM_ValidTermId + count; i++) { string name = (count == 1) ? Constants.TERM_ValidName : ContentTestHelper.GetTermName(i); string description = (count == 1) ? Constants.VOCABULARY_ValidName : ContentTestHelper.GetTermName(i); int weight = Constants.TERM_ValidWeight; int parentId = Constants.TERM_ValidParentTermId; AddTermToTable(table, i, contentIdFunction(i), vocabularyIdFunction(i), name, description, weight, parentId); } return(table.CreateDataReader()); }
public void TermController_DeleteTerm_Should_Call_DataService_DeleteHeirarchicalTerm_If_Term_Is_Heirarchical_Term() { //Arrange var mockDataService = new Mock <IDataService>(); var termController = new TermController(mockDataService.Object); var term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId); term.TermId = Constants.TERM_DeleteTermId; // Act termController.DeleteTerm(term); // Assert mockDataService.Verify(ds => ds.DeleteHeirarchicalTerm(term)); }
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); }
public void VocabularyController_DeleteVocabulary_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_ValidVocabularyId; //Act vocabularyController.DeleteVocabulary(vocabulary); //Assert mockDataService.Verify(ds => ds.DeleteVocabulary(vocabulary)); }
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); }
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); }
public void TermController_UpdateTerm_Should_Call_DataService_UpdateSimpleTerm_If_Term_Is_Simple_Term() { //Arrange var mockDataService = new Mock <IDataService>(); var 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)); }
public void TermController_GetTermsByContent_Returns_Terms_On_Valid_ContentItemId() { //Arrange var 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)); var termController = new TermController(mockDataService.Object); //Act var terms = termController.GetTermsByContent(Constants.TERM_ValidContent1).ToList(); //Assert Assert.AreEqual(Constants.TERM_ValidCountForContent1, terms.Count); for (int i = 0; i < Constants.TERM_ValidCountForContent1; i++) { Assert.AreEqual(i + Constants.TERM_ValidTermId, terms[i].TermId); Assert.AreEqual(ContentTestHelper.GetTermName(i + Constants.TERM_ValidTermId), terms[i].Name); } }
public void TermController_GetTermsByVocabulary_Returns_Terms_On_Valid_VocabularyId() { //Arrange var 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)); MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(String.Empty); var termController = new TermController(mockDataService.Object); //Act var 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); } }
internal static IDataReader CreateValidScopeTypesReader(int count) { DataTable table = CreateScopeTypeTable(); for (int i = Constants.SCOPETYPE_ValidScopeTypeId; i < Constants.SCOPETYPE_ValidScopeTypeId + count; i++) { string scopeType = (count == 1) ? Constants.SCOPETYPE_ValidScopeType : ContentTestHelper.GetScopeType(i); AddScopeTypeToTable(table, i, scopeType); } return(table.CreateDataReader()); }
internal static IDataReader CreateValidContentTypesReader(int count) { DataTable table = CreateContentTypeTable(); for (int i = Constants.CONTENTTYPE_ValidContentTypeId; i < Constants.CONTENTTYPE_ValidContentTypeId + count; i++) { string contentType = (count == 1) ? Constants.CONTENTTYPE_ValidContentType : ContentTestHelper.GetContentType(i); AddContentTypeToTable(table, i, contentType); } return(table.CreateDataReader()); }