private void BindData() { using (var dt = new DataTable()) { dt.Columns.Add(new DataColumn("TabId", typeof (Int32))); dt.Columns.Add(new DataColumn("ContentKey", typeof (String))); dt.Columns.Add(new DataColumn("Title", typeof (String))); dt.Columns.Add(new DataColumn("Description", typeof (String))); dt.Columns.Add(new DataColumn("PubDate", typeof (DateTime))); var results = new ContentController().GetContentItemsByTerm(_tagQuery).ToList(); var tabController = new TabController(); if (_tagQuery.Length > 0) { foreach (var item in results) { var dr = dt.NewRow(); dr["TabId"] = item.TabID; dr["ContentKey"] = item.ContentKey; dr["Title"] = item.Content; //get tab info and use the tab description, if tab is deleted then ignore the item. var tab = tabController.GetTab(item.TabID, PortalId, false); if(tab != null) { if (tab.IsDeleted) { continue; } dr["Title"] = string.IsNullOrEmpty(tab.Title) ? tab.TabName : tab.Title; dr["Description"] = tab.Description; } else { dr["Description"] = item.Content.Length > 1000 ? item.Content.Substring(0, 1000) : item.Content; } dr["PubDate"] = item.CreatedOnDate; dt.Rows.Add(dr); } } //Bind Search Results Grid var dv = new DataView(dt); dgResults.DataSource = dv; dgResults.DataBind(); if (results.Count == 0) { dgResults.Visible = false; lblMessage.Text = string.Format(Localization.GetString("NoResults", LocalResourceFile), _tagQuery); } else { lblMessage.Text = string.Format(Localization.GetString("Results", LocalResourceFile), _tagQuery); } } }
private static Mock<IDataService> DataServiceFactory() { var dataService = new Mock<IDataService>(); dataService.Setup(ds => ds.SynchronizeMetaData( It.IsAny<ContentItem>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>())) .Callback<ContentItem, IEnumerable<KeyValuePair<string, string>>, IEnumerable<KeyValuePair<string, string>>>( (ci, added, deleted) => { deleted.ToList().ForEach( item => dataService.Object.DeleteMetaData(ci, item.Key, item.Value)); added.ToList().ForEach( item => dataService.Object.AddMetaData(ci, item.Key, item.Value)); }); // Register controller types that are dependent on our IDataService. var contentController = new ContentController(dataService.Object); ComponentFactory.RegisterComponentInstance<IAttachmentController>(new FileController(contentController)); ComponentFactory.RegisterComponentInstance<IContentController>(contentController); ComponentFactory.RegisterComponentInstance<IFileManager>(MockHelper.CreateMockFileManager().Object); return dataService; }
public void ContentController_AddContentItem_Throws_On_Null_ContentItem() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); //Act, Arrange Assert.Throws<ArgumentNullException>(() => controller.AddContentItem(null)); }
public void ContentController_AddContentItem_Calls_DataService_On_Valid_Arguments() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); ContentItem content = ContentTestHelper.CreateValidContentItem(); content.ContentItemId = Constants.CONTENT_ValidContentItemId; //Act int contentId = controller.AddContentItem(content); //Assert mockDataService.Verify(ds => ds.AddContentItem(content, It.IsAny<int>())); }
public void ContentController_AddContentItem_Returns_ValidId_On_Valid_ContentItem() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.AddContentItem(It.IsAny<ContentItem>(), It.IsAny<int>())) .Returns(Constants.CONTENT_AddContentItemId); ContentController controller = new ContentController(mockDataService.Object); ContentItem content = ContentTestHelper.CreateValidContentItem(); content.ContentItemId = Constants.CONTENT_ValidContentItemId; //Act int contentId = controller.AddContentItem(content); //Assert Assert.AreEqual(Constants.CONTENT_AddContentItemId, contentId); }
public void ContentController_GetContentItem_Returns_ContentItem_On_Valid_ContentItemId() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetContentItem(Constants.CONTENT_ValidContentItemId)) .Returns(MockHelper.CreateValidContentItemReader()); ContentController controller = new ContentController(mockDataService.Object); //Act ContentItem content = controller.GetContentItem(Constants.CONTENT_ValidContentItemId); //Assert Assert.AreEqual(Constants.CONTENT_ValidContentItemId, content.ContentItemId); Assert.AreEqual(ContentTestHelper.GetContent(Constants.CONTENT_ValidContentItemId), content.Content); Assert.AreEqual(ContentTestHelper.GetContentKey(Constants.CONTENT_ValidContentItemId), content.ContentKey); }
public void ContentController_GetContentItem_Returns_Null_On_InValid_ContentItemId() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetContentItem(Constants.CONTENT_InValidContentItemId)) .Returns(MockHelper.CreateEmptyContentItemReader()); ContentController controller = new ContentController(mockDataService.Object); //Act ContentItem content = controller.GetContentItem(Constants.CONTENT_InValidContentItemId); //Assert Assert.IsNull(content); }
public void ContentController_UpdateContentItem_Calls_DataService_On_Valid_ContentItem() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); ComponentFactory.RegisterComponentInstance<IContentController>(controller); ContentItem content = ContentTestHelper.CreateValidContentItem(); content.ContentItemId = Constants.CONTENT_UpdateContentItemId; content.Content = Constants.CONTENT_UpdateContent; content.ContentKey = Constants.CONTENT_UpdateContentKey; //Act controller.UpdateContentItem(content); //Assert mockDataService.Verify(ds => ds.UpdateContentItem(content, It.IsAny<int>())); }
public void ContentController_DeleteMetaData_Throws_On_Null_MetaDataName() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); ContentItem content = ContentTestHelper.CreateValidContentItem(); //Act, Arrange Assert.Throws<ArgumentOutOfRangeException>(() => controller.AddMetaData(content, Null.NullString, Constants.CONTENT_ValidMetaDataValue)); }
public void ContentController_GetUnIndexedContentItems_Returns_EmptyList_If_No_UnIndexed_Items() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetUnIndexedContentItems()) .Returns(MockHelper.CreateEmptyContentItemReader()); ContentController controller = new ContentController(mockDataService.Object); //Act IQueryable<ContentItem> contentItems = controller.GetUnIndexedContentItems(); //Assert Assert.AreEqual(0, contentItems.Count()); }
public void ContentController_UpdateContentItem_Throws_On_Negative_ContentItemId() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); ContentItem content = new ContentItem(); content.ContentItemId = Null.NullInteger; Assert.Throws<ArgumentException>(() => controller.UpdateContentItem(content)); }
public void ContentController_DeleteMetaData_Throws_On_Negative_ContentItemId() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); ContentItem content = ContentTestHelper.CreateValidContentItem(); content.ContentItemId = Null.NullInteger; //Act, Arrange Assert.Throws<ArgumentException>(() => controller.DeleteMetaData(content, Constants.CONTENT_ValidMetaDataName, Constants.CONTENT_ValidMetaDataValue)); }
public void ContentController_GetMetaData_Throws_On_Negative_ContentItemId() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); //Act, Arrange Assert.Throws<ArgumentException>(() => controller.GetMetaData(Null.NullInteger)); }
public void ContentController_DeleteContentItem_Throws_On_Null_ContentItem() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); //Act, Arrange controller.DeleteContentItem(null); }
public void ContentController_DeleteMetaData_Calls_DataService_On_Valid_Arguments() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); ContentItem content = ContentTestHelper.CreateValidContentItem(); content.ContentItemId = Constants.CONTENT_ValidContentItemId; //Act controller.DeleteMetaData(content, Constants.CONTENT_ValidMetaDataName, Constants.CONTENT_ValidMetaDataValue); //Assert mockDataService.Verify( ds => ds.DeleteMetaData(content, Constants.CONTENT_ValidMetaDataName, Constants.CONTENT_ValidMetaDataValue)); }
public void ContentController_DeleteContentItem_Calls_DataService_On_Valid_ContentItemId() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); ContentItem content = ContentTestHelper.CreateValidContentItem(); content.ContentItemId = Constants.CONTENT_DeleteContentItemId; //Act controller.DeleteContentItem(content); //Assert mockDataService.Verify(ds => ds.DeleteContentItem(content)); }
private void BindData() { using (var dt = new DataTable()) { dt.Columns.Add(new DataColumn("TabId", typeof (Int32))); dt.Columns.Add(new DataColumn("ContentKey", typeof (String))); dt.Columns.Add(new DataColumn("Title", typeof (String))); dt.Columns.Add(new DataColumn("Description", typeof (String))); dt.Columns.Add(new DataColumn("PubDate", typeof (DateTime))); var results = new ContentController().GetContentItemsByTerm(_tagQuery).ToList(); if (_tagQuery.Length > 0) { foreach (var item in results) { var dr = dt.NewRow(); dr["TabId"] = item.TabID; dr["ContentKey"] = item.ContentKey; dr["Title"] = item.Content; if (item.Content.Length > 1000) { dr["Description"] = item.Content.Substring(0, 1000); } else { dr["Description"] = item.Content; } dr["PubDate"] = item.CreatedOnDate; dt.Rows.Add(dr); } } //Bind Search Results Grid var dv = new DataView(dt); dgResults.PageSize = PageSize; dgResults.DataSource = dv; dgResults.DataBind(); if (results.Count == 0) { dgResults.Visible = false; lblMessage.Text = string.Format(Localization.GetString("NoResults", LocalResourceFile), _tagQuery); } else { lblMessage.Text = string.Format(Localization.GetString("Results", LocalResourceFile), _tagQuery); } if (results.Count <= dgResults.PageSize) { ctlPagingControl.Visible = false; } else { ctlPagingControl.Visible = true; } ctlPagingControl.TotalRecords = results.Count; } ctlPagingControl.PageSize = dgResults.PageSize; ctlPagingControl.CurrentPage = CurrentPage; }
public void ContentController_Title_Is_Saved_On_Update() { var mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.AddContentItem(It.IsAny<ContentItem>(), It.IsAny<int>())) .Returns(Constants.CONTENT_AddContentItemId); mockDataService.Setup(ds => ds.SynchronizeMetaData( It.IsAny<ContentItem>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>())) .Callback<ContentItem, IEnumerable<KeyValuePair<string, string>>, IEnumerable<KeyValuePair<string, string>>>( (ci, added, deleted) => { deleted.ToList().ForEach( item => mockDataService.Object.DeleteMetaData(ci, item.Key, item.Value)); added.ToList().ForEach( item => mockDataService.Object.AddMetaData(ci, item.Key, item.Value)); }); // Return empty set of metadata. mockDataService.Setup(ds => ds.GetMetaData(It.IsAny<int>())).Returns(MockHelper.CreateValidMetaDataReader); var controller = new ContentController(mockDataService.Object); // The ContentExtensions methods look this up. ComponentFactory.RegisterComponentInstance<IContentController>(controller); var content = ContentTestHelper.CreateValidContentItem(); content.ContentItemId = Constants.CONTENT_ValidContentItemId; content.ContentTitle = Constants.CONTENT_ValidTitle; //Act controller.AddContentItem(content); content.ContentTitle = Constants.CONTENT_ValidTitle2; controller.UpdateContentItem(content); //Assert mockDataService.Verify(ds => ds.AddMetaData(content, AttachmentController.TitleKey, Constants.CONTENT_ValidTitle)); mockDataService.Verify(ds => ds.AddMetaData(content, AttachmentController.TitleKey, Constants.CONTENT_ValidTitle2)); }
public void ContentController_GetMetaData_Calls_DataService_On_Valid_Arguments() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetMetaData(Constants.CONTENT_ValidContentItemId)) .Returns(MockHelper.CreateValidMetaDataReader()); ContentController controller = new ContentController(mockDataService.Object); //Act NameValueCollection metaData = controller.GetMetaData(Constants.CONTENT_ValidContentItemId); //Assert mockDataService.Verify(ds => ds.GetMetaData(Constants.CONTENT_ValidContentItemId)); }
public void ContentController_DeleteMetaData_Throws_On_Null_MetaDataName() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); //Act, Arrange AutoTester.ArgumentNull<ContentItem>(content => controller.DeleteMetaData(content, Null.NullString, Constants. CONTENT_ValidMetaDataValue)); }
public void ContentController_GetMetaData_Returns_NameValueCollection_Of_MetaData() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetMetaData(Constants.CONTENT_ValidContentItemId)) .Returns(MockHelper.CreateValidMetaDataReader()); ContentController controller = new ContentController(mockDataService.Object); //Act NameValueCollection metaData = controller.GetMetaData(Constants.CONTENT_ValidContentItemId); //Assert Assert.AreEqual(Constants.CONTENT_MetaDataCount, metaData.Count); }
public void ContentController_GetContentItemsByTerm_Returns_Empty_List_If_Term_Not_Used() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetContentItemsByTerm(Constants.TERM_UnusedName)) .Returns(MockHelper.CreateEmptyContentItemReader()); ContentController controller = new ContentController(mockDataService.Object); //Act IQueryable<ContentItem> contentItems = controller.GetContentItemsByTerm(Constants.TERM_UnusedName); //Assert Assert.AreEqual(0, contentItems.Count()); }
public void ContentController_GetUnIndexedContentItems_Calls_DataService() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetUnIndexedContentItems()) .Returns(MockHelper.CreateValidContentItemReader()); ContentController controller = new ContentController(mockDataService.Object); //Act IQueryable<ContentItem> contentItems = controller.GetUnIndexedContentItems(); //Assert mockDataService.Verify(ds => ds.GetUnIndexedContentItems()); }
public void ContentController_DeleteMetaData_Throws_On_Null_ContentItem() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); //Act, Arrange Assert.Throws<ArgumentNullException>(() => controller.AddMetaData(null, Constants.CONTENT_ValidMetaDataName, Constants.CONTENT_ValidMetaDataValue)); }
public void ContentController_GetUnIndexedContentItems_Returns_List_Of_UnIndexedContentItems() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetUnIndexedContentItems()) .Returns(MockHelper.CreateValidContentItemsReader(Constants.CONTENT_IndexedFalseItemCount, Constants.CONTENT_IndexedFalse, Null.NullInteger, Null.NullString)); ContentController controller = new ContentController(mockDataService.Object); //Act IQueryable<ContentItem> contentItems = controller.GetUnIndexedContentItems(); //Assert Assert.AreEqual(Constants.CONTENT_IndexedFalseItemCount, contentItems.Count()); foreach (ContentItem content in contentItems) { Assert.IsFalse(content.Indexed); } }
public void ContentController_GetContentItemsByTerm_Throws_On_Null_Term() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); //Act, Arrange Assert.Throws<ArgumentException>(() => controller.GetContentItemsByTerm(Null.NullString)); }
public void ContentController_UpdateContentItem_Throws_On_Null_ContentItem() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); ContentController controller = new ContentController(mockDataService.Object); //Act, Arrange AutoTester.ArgumentNull<ContentItem>(content => controller.UpdateContentItem(content)); }
public void ContentController_GetContentItem_Calls_DataService_On_Valid_ContentItemId() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetContentItem(Constants.CONTENT_ValidContentItemId)) .Returns(MockHelper.CreateValidContentItemReader()); ContentController controller = new ContentController(mockDataService.Object); //Act ContentItem content = controller.GetContentItem(Constants.CONTENT_ValidContentItemId); //Assert mockDataService.Verify(ds => ds.GetContentItem(Constants.CONTENT_ValidContentItemId)); }
public void ContentController_GetContentItemsByTerm_Returns_List_Of_ContentItems() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetContentItemsByTerm(Constants.TERM_ValidName)) .Returns(MockHelper.CreateValidContentItemsReader(Constants.CONTENT_TaggedItemCount, Constants.CONTENT_IndexedFalse, Null.NullInteger, Constants.TERM_ValidName)); ContentController controller = new ContentController(mockDataService.Object); //Act IQueryable<ContentItem> contentItems = controller.GetContentItemsByTerm(Constants.TERM_ValidName); //Assert Assert.AreEqual(Constants.CONTENT_TaggedItemCount, contentItems.Count()); }
public void ContentController_GetMetaData_Returns_NameValueCollection_Of_MetaData() { //Arrange Mock<IDataService> mockDataService = new Mock<IDataService>(); mockDataService.Setup(ds => ds.GetMetaData(Constants.CONTENT_ValidContentItemId)).Returns(MockHelper.CreateValidMetaDataReader()); mockDataService.Setup(ds => ds.SynchronizeMetaData( It.IsAny<ContentItem>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>())) .Callback<ContentItem, IEnumerable<KeyValuePair<string, string>>, IEnumerable<KeyValuePair<string, string>>>( (ci, added, deleted) => { deleted.ToList().ForEach( item => mockDataService.Object.DeleteMetaData(ci, item.Key, item.Value)); added.ToList().ForEach( item => mockDataService.Object.AddMetaData(ci, item.Key, item.Value)); }); var controller = new ContentController(mockDataService.Object); //Act var metaData = controller.GetMetaData(Constants.CONTENT_ValidContentItemId); //Assert Assert.AreEqual(Constants.CONTENT_MetaDataCount, metaData.Count); }