/// <summary> /// Returnez toate Post-urile si Comment-urile corespunzatoare /// </summary> /// <returns></returns> public static List <Post> GetAllPosts() { using (PostContainer ctx = new PostContainer()) { return(ctx.Posts.Include("Comments").ToList <Post>()); } }
public void BestWithSrDetail() { PostContainer posts = reddit.Models.Listings.Best(new CategorizedSrListingInput(srDetail: true)); Validate(posts); Assert.IsNotNull(posts.Data.Children[0].Data.SrDetail); }
public PostContainer Validate(PostContainer postContainer, int minResults) { Assert.IsNotNull(postContainer); Assert.IsTrue(postContainer.Data.Children.Count >= minResults); return(postContainer); }
public PostController(PostContainer postcontainer, ReplyContainer replycontainer, ForumContainer forumcontainer, IPostUpdateContext update) { this.Container = postcontainer; this.replyContainer = replycontainer; this.forumContainer = forumcontainer; this.postUpdate = update; }
public static int DeletePost(int id) { using (PostContainer ctx = new PostContainer()) { return(ctx.Database.ExecuteSqlCommand("Delete From Post where postid =@p0", id)); } }
public List <Post> GetPosts(PostContainer postContainer, Dispatch dispatch, out List <LinkPost> linkPosts, out List <SelfPost> selfPosts) { linkPosts = new List <LinkPost>(); selfPosts = new List <SelfPost>(); if (postContainer == null || postContainer.Data == null || postContainer.Data.Children == null) { return(null); } List <Post> posts = new List <Post>(); foreach (PostChild postChild in postContainer.Data.Children) { if (postChild.Data != null) { if (postChild.Data.IsSelf) { SelfPost selfPost = new SelfPost(dispatch, postChild.Data); posts.Add(selfPost); selfPosts.Add(selfPost); } else { LinkPost linkPost = new LinkPost(dispatch, postChild.Data); posts.Add(linkPost); linkPosts.Add(linkPost); } } } return(posts); }
public static Comment GetCommentById(int id) { using (PostContainer ctx = new PostContainer()) { var items = from c in ctx.Comments where (c.CommentId == id) select c; return(items.Include(p => p.Post).SingleOrDefault()); } }
public ActionResult GetComments(int id, int forumid) { ForumContainer forumContainer = new ForumContainer(connectionstring); PostContainer postContainer = new PostContainer(); ForumPostViewModel forumPostViewModel = new ForumPostViewModel(forumContainer.GetForumById(forumid), postContainer.GetPostById(id)); return(View(forumPostViewModel)); }
public void GetPostByIdTest_NotNull_ReturnEqual() { //Arrange PostContainer postcontainer = new PostContainer(); //Act Post post = postcontainer.GetPostById(2); //Assert Assert.IsNotNull(post.Posttitel); }
/// <summary> /// Returnez un Post si toate Comment-urile asociate lui /// </summary> /// <param name="id"></param> /// <returns></returns> public static Post GetPostById(int id) { using (PostContainer ctx = new PostContainer()) { var items = from p in ctx.Posts where (p.PostId == id) select p; if (items != null) { return(items.Include(c => c.Comments).SingleOrDefault()); } return(null); } }
public void GetAllPostsByForumIdDescTest_Null_ReturnEqual() { //Arrange PostContainer postcontainer = new PostContainer(); List <Post> expectedpsots = new List <Post>(); //Act postcontainer.GetAllPostsByForumId(100); List <Post> posts = postcontainer.Posts; //Assert CollectionAssert.AreEquivalent(expectedpsots, posts); }
public void GetAllPostsByForumIdDescTest_NotNull_ReturnEqual() { //Arrange PostContainer postcontainer = new PostContainer(); List <Post> expectedpsots = new List <Post>(); //Act postcontainer.GetAllPostsByForumId(6); List <Post> posts = postcontainer.Posts; //Assert Assert.IsTrue(posts.Count == 3); }
public static bool AddPost(Post post) { using (PostContainer ctx = new PostContainer()) { bool bResult = false; if (post.PostId == 0) { var it = ctx.Entry <Post>(post).State = EntityState.Added; ctx.SaveChanges(); bResult = true; } return(bResult); } }
public void Validate(PostContainer postContainer, bool allowEmpty = false) { Assert.IsNotNull(postContainer); Assert.IsNotNull(postContainer.Data); Assert.IsNotNull(postContainer.Data.Children); Assert.IsTrue(postContainer.Kind.Equals("Listing")); if (!allowEmpty) { Assert.IsTrue(postContainer.Data.Children.Count > 0); Assert.IsTrue(postContainer.Data.Children[0].Kind.Equals("t3")); Assert.IsNotNull(postContainer.Data.Children[0].Data); } }
public static Post UpdatePost(Post newPost) { using (PostContainer ctx = new PostContainer()) { // Ce e in bd. PK nu poate fi modificata Post oldPost = ctx.Posts.Find(newPost.PostId); if (oldPost == null) // nu exista in bd { return(null); } oldPost.Description = newPost.Description; oldPost.Domain = newPost.Domain; oldPost.Date = newPost.Date; ctx.SaveChanges(); return(oldPost); } }
public static Comment UpdateComment(Comment newComment) { using (PostContainer ctx = new PostContainer()) { Comment oldComment = ctx.Comments.Find(newComment.CommentId); if (newComment.Text != null) { oldComment.Text = newComment.Text; } if ((oldComment.PostPostId != newComment.PostPostId) && (newComment.PostPostId != 0)) { oldComment.PostPostId = newComment.PostPostId; } ctx.SaveChanges(); return(oldComment); } }
public void GetCommentsWithContext() { List <(PostContainer, CommentContainer)> res = reddit.Models.Listings.GetComments("8gmf99", new ListingsGetCommentsInput(8, true, true, "top", true, 0, "dyd2vtc"), "FloridaMan"); Assert.IsNotNull(res); Assert.IsTrue(res.Count == 1); PostContainer post = res[0].Item1; CommentContainer comments = res[0].Item2; Validate(post); Assert.IsFalse(post.Data.Children[0].Data.IsSelf); Assert.IsTrue(post.Data.Children[0].Data.Id.Equals("8gmf99")); Assert.IsTrue(post.Data.Children[0].Data.Author.Equals("KrisCraig")); Assert.IsTrue(post.Data.Children[0].Data.Subreddit.Equals("FloridaMan")); Assert.IsTrue(post.Data.Children[0].Data.Title.Equals("Florida man with handlebar mustache assaults woman on plane, starts a fight with several passengers, " + "yells at police to tase him and \"you'll see what happens\", then gets tased 10 times.")); Validate(comments); }
public void GetComments() { List <(PostContainer, CommentContainer)> res = reddit.Models.Listings.GetComments("9gaze5", new ListingsGetCommentsInput(0, false, false, "top", true, 0)); Assert.IsNotNull(res); Assert.IsTrue(res.Count == 1); PostContainer post = res[0].Item1; CommentContainer comments = res[0].Item2; Validate(post); Assert.IsTrue(post.Data.Children[0].Data.Approved); Assert.IsFalse(post.Data.Children[0].Data.IsSelf); Assert.IsTrue(post.Data.Children[0].Data.Id.Equals("9gaze5")); Assert.IsTrue(post.Data.Children[0].Data.Author.Equals("KrisCraig")); Assert.IsTrue(post.Data.Children[0].Data.Subreddit.Equals("StillSandersForPres")); Assert.IsTrue(post.Data.Children[0].Data.Title.Equals("Reports of Widespread Voter Suppression in New York State Democratic Primary")); Validate(comments); }
// Comment table public static bool AddComment(Comment comment) { using (PostContainer ctx = new PostContainer()) { bool bResult = false; if (comment == null || comment.PostPostId == 0) { return(bResult); } if (comment.CommentId == 0) { ctx.Entry <Comment>(comment).State = EntityState.Added; Post p = ctx.Posts.Find(comment.PostPostId); ctx.Entry <Post>(p).State = EntityState.Unchanged; ctx.SaveChanges(); bResult = true; } return(bResult); } }
public void PostHistoryOverview() { PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "overview", new UsersHistoryInput(context: 10)); Validate(history); }
public void PostHistoryGilded() { PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "gilded", new UsersHistoryInput(sort: "top", context: 10)); Validate(history, true); }
public void PostHistoryHidden() { PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "hidden", new UsersHistoryInput(sort: "top", context: 10)); Validate(history); }
public void ModQueueEdited() { PostContainer modQueue = reddit.Models.Moderation.ModQueue(new ModerationModQueueInput(), "edited", testData["Subreddit"]); Validate(modQueue, true); }
public void ModQueueSpam() { PostContainer modQueue = reddit.Models.Moderation.ModQueue(new ModerationModQueueInput("comments"), "spam", testData["Subreddit"]); Validate(modQueue, true); }
public void PostHistorySubmitted() { PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "submitted", new UsersHistoryInput(context: 10)); Validate(history); }
public void BestNoCats() { PostContainer posts = reddit.Models.Listings.Best(new CategorizedSrListingInput(includeCategories: false)); Validate(posts); }
public void Controversial() { PostContainer posts = reddit.Models.Listings.Controversial(new TimedCatSrListingInput(includeCategories: true)); Validate(posts); }
public void TopDay() { PostContainer posts = reddit.Models.Listings.Top(new TimedCatSrListingInput("day", includeCategories: true)); Validate(posts); }
public ForumController(ForumContainer forumcontainer, PostContainer postcontainer, AccountContainer accountcontainer) { this.forumContainer = forumcontainer; this.postContainer = postcontainer; this.accountContainer = accountcontainer; }
public void GetByNames() { PostContainer posts = reddit.Models.Listings.GetByNames("t3_9gaze5,t3_9mfizx"); Validate(posts); }