public void ContentItemController_Put_Validation_Test() { // Arrange Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict); mock.Setup(setup => setup.Add(It.IsAny <ContentItem>())); ContentItemController target = new ContentItemController(mock.Object); ContentItem item = new ContentItem() { HasChildren = false, SourceRef = string.Empty, SourceURL = string.Empty }; // Act target.Configuration = new HttpConfiguration(); target.Validate <ContentItem>(item); IHttpActionResult result = target.Put(0, item); // Assert Assert.IsNotNull(result); Assert.IsTrue(result is BadRequestErrorMessageResult); Assert.AreEqual(false, target.ModelState.IsValid); Assert.AreEqual(3, target.ModelState.Count); }
public void ContentItemController_Post_Test() { // Arrange Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict); mock.Setup(setup => setup.Add(It.IsAny <ContentItem>())).Returns(new ContentItem() { Id = 123 }); ContentItemController target = new ContentItemController(mock.Object); ContentItem item = new ContentItem() { BeginDate = -1, EndDate = -1, Title = "test", ParentId = 1, HasChildren = false, SourceRef = string.Empty, SourceURL = string.Empty }; // Act target.Configuration = new HttpConfiguration(); target.Validate <ContentItem>(item); IHttpActionResult result = target.Post(item); // Assert Assert.IsNotNull(result); Assert.IsTrue(result is OkNegotiatedContentResult <ContentItem>); Assert.AreEqual(123, (result as OkNegotiatedContentResult <ContentItem>).Content.Id); mock.Verify(verify => verify.Add(It.IsAny <ContentItem>()), Times.Once); }
public void ContentItemController_Put_Test() { // Arrange Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict); mock.Setup(setup => setup.Update(It.IsAny <ContentItem>())); ContentItemController target = new ContentItemController(mock.Object); ContentItem item = new ContentItem() { BeginDate = -1, EndDate = -1, Title = "test", ParentId = 1, HasChildren = false, Id = 1, SourceRef = string.Empty, SourceURL = string.Empty }; // Act target.Configuration = new HttpConfiguration(); target.Validate <ContentItem>(item); IHttpActionResult result = target.Put(0, item); // Assert Assert.IsNotNull(result); Assert.IsTrue(result is OkResult); mock.Verify(verify => verify.Update(It.IsAny <ContentItem>()), Times.Once); }
/// <summary> /// This completes the things necessary for creating a content item in the data store. /// </summary> /// <param name="objPost">The PostInfo entity we just created in the data store.</param> /// <param name="tabId">The page we will associate with our content item.</param> /// <returns>The ContentItemId primary key created in the Core ContentItems table.</returns> private static int CompleteQuestionCreation(AlbumInfo objPost, int tabId) { var cntTaxonomy = new ContentItemController(); var objContentItem = cntTaxonomy.CreateContentItem(objPost, tabId); return(objContentItem.ContentItemId); }
/// <summary> /// Handles any content item/taxonomy updates, then deals with cache clearing. /// </summary> /// <param name="objAlbum"></param> /// <param name="tabId"></param> private static void CompleteQuestionUpdate(AlbumInfo objAlbum, int tabId) { var cntTaxonomy = new ContentItemController(); cntTaxonomy.UpdateContentItem(objAlbum, tabId); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.HomeQuestionsCacheKey + objAlbum.ModuleID); //if (objAlbum.ParentId >= 1) return; DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.HomeTermsCacheKey + objAlbum.ModuleID); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.ModuleTermsCacheKey + objAlbum.ModuleID); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.ModuleQuestionsCacheKey + objAlbum.ModuleID); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.ContentTermsCacheKey + objAlbum.ContentItemId); }
public void ContentItemController_Get_BadRequest_Test() { // Arrange Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict); mock.Setup(setup => setup.Find(It.IsAny <long>(), It.IsAny <int>())).Throws(new Exception()); ContentItemController target = new ContentItemController(mock.Object); // Act IHttpActionResult result = target.Get(-1); // Assert Assert.IsNotNull(result); Assert.IsTrue(result is BadRequestErrorMessageResult); }
/// <summary> /// Add Album To DataBase /// I - Steps : /// 1 . first : Add ContentItem /// 2 . Second :Add Album to DataBase /// 3 . Store Album into Cache /// </summary> /// <param name="album"></param> /// <returns> /// Id of album /// </returns> public int AddAlbum(AlbumInfo album, int tabid) { int rt = -1; // # 1 Save ContentItem to DataBase ContentItemController content = new ContentItemController(); content.CreateContentItem(album, tabid); // # 2 Store Album to DataBase rt = int.Parse(SqlServerDb.GetInstance().Insert(album).ToString()); // # 3 Store Cache return(rt); }
public ContentItemController SetupController() { var contentService = Mock.Create <IContentItemService>(); var contentRepo = Mock.Create <IContentItemRepository>(); var controller = new ContentItemController(contentService); Mock.Arrange(() => contentService.GetAllPresidents()).Returns(new List <PresidentModel> { new PresidentModel { id = 1 } }); controller.Request = this.GetRequest(); return(controller); }
public void ContentItemController_Get_Test() { // Arrange Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict); mock.Setup(setup => setup.Find(It.IsAny <long>(), It.IsAny <int>())).Returns(new ContentItem() { Children = new ContentItem[2] }); ContentItemController target = new ContentItemController(mock.Object); // Act IHttpActionResult result = target.Get(1); // Assert Assert.IsNotNull(result); Assert.IsTrue(result is OkNegotiatedContentResult <ContentItem>); Assert.AreEqual(2, (result as OkNegotiatedContentResult <ContentItem>).Content.Children.Length); mock.Verify(verify => verify.Find(It.IsAny <long>(), It.IsAny <int>()), Times.Once); }
/// <summary> /// Add Album To DataBase /// I - Steps : /// 1 . first : Add ContentItem /// 2 . Second :Add Album to DataBase /// 3 . Store Album into Cache /// </summary> /// <param name="album"></param> /// <returns> /// Id of album /// </returns> public int AddAlbum(AlbumInfo album, int tabid) { int rt = -1; // # 1 Save ContentItem to DataBase ContentItemController content = new ContentItemController(); content.CreateContentItem(album, tabid); // # 2 Store Album to DataBase rt = int.Parse(SqlServerDb.GetInstance().Insert(album).ToString()); // # 3 Store Cache return rt; }
/// <summary> /// Handles any content item/taxonomy updates, then deals with cache clearing. /// </summary> /// <param name="objAlbum"></param> /// <param name="tabId"></param> private static void CompleteQuestionUpdate(AlbumInfo objAlbum, int tabId) { var cntTaxonomy = new ContentItemController(); cntTaxonomy.UpdateContentItem(objAlbum, tabId); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.HomeQuestionsCacheKey + objAlbum.ModuleID); //if (objAlbum.ParentId >= 1) return; DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.HomeTermsCacheKey + objAlbum.ModuleID); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.ModuleTermsCacheKey + objAlbum.ModuleID); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.ModuleQuestionsCacheKey + objAlbum.ModuleID); DataCache.RemoveCache(Constants.ModuleCacheKey + Constants.ContentTermsCacheKey + objAlbum.ContentItemId); }
/// <summary> /// Cleanup any taxonomy related items. /// </summary> /// <param name="contentItemID"></param> private static void CompleteQuestionDelete(int contentItemID) { var cntTaxonomy = new ContentItemController(); cntTaxonomy.DeleteContentItem(contentItemID); }
/// <summary> /// This completes the things necessary for creating a content item in the data store. /// </summary> /// <param name="objPost">The PostInfo entity we just created in the data store.</param> /// <param name="tabId">The page we will associate with our content item.</param> /// <returns>The ContentItemId primary key created in the Core ContentItems table.</returns> private static int CompleteQuestionCreation(AlbumInfo objPost, int tabId) { var cntTaxonomy = new ContentItemController(); var objContentItem = cntTaxonomy.CreateContentItem(objPost, tabId); return objContentItem.ContentItemId; }
/// <summary> /// Cleanup any taxonomy related items. /// </summary> /// <param name="contentItemID"></param> private static void CompleteQuestionDelete(int contentItemID) { var cntTaxonomy = new ContentItemController(); cntTaxonomy.DeleteContentItem(contentItemID); }