示例#1
0
 /// <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>());
     }
 }
示例#2
0
        public void BestWithSrDetail()
        {
            PostContainer posts = reddit.Models.Listings.Best(new CategorizedSrListingInput(srDetail: true));

            Validate(posts);
            Assert.IsNotNull(posts.Data.Children[0].Data.SrDetail);
        }
示例#3
0
        public PostContainer Validate(PostContainer postContainer, int minResults)
        {
            Assert.IsNotNull(postContainer);
            Assert.IsTrue(postContainer.Data.Children.Count >= minResults);

            return(postContainer);
        }
示例#4
0
 public PostController(PostContainer postcontainer, ReplyContainer replycontainer, ForumContainer forumcontainer, IPostUpdateContext update)
 {
     this.Container      = postcontainer;
     this.replyContainer = replycontainer;
     this.forumContainer = forumcontainer;
     this.postUpdate     = update;
 }
示例#5
0
 public static int DeletePost(int id)
 {
     using (PostContainer ctx = new PostContainer())
     {
         return(ctx.Database.ExecuteSqlCommand("Delete From Post where postid =@p0", id));
     }
 }
示例#6
0
        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);
        }
示例#7
0
 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());
     }
 }
示例#8
0
        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);
        }
示例#10
0
 /// <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);
        }
示例#13
0
 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);
     }
 }
示例#14
0
        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);
            }
        }
示例#15
0
 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);
     }
 }
示例#16
0
 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);
     }
 }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
 // 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);
     }
 }
示例#20
0
        public void PostHistoryOverview()
        {
            PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "overview", new UsersHistoryInput(context: 10));

            Validate(history);
        }
示例#21
0
        public void PostHistoryGilded()
        {
            PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "gilded", new UsersHistoryInput(sort: "top", context: 10));

            Validate(history, true);
        }
示例#22
0
        public void PostHistoryHidden()
        {
            PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "hidden", new UsersHistoryInput(sort: "top", context: 10));

            Validate(history);
        }
示例#23
0
        public void ModQueueEdited()
        {
            PostContainer modQueue = reddit.Models.Moderation.ModQueue(new ModerationModQueueInput(), "edited", testData["Subreddit"]);

            Validate(modQueue, true);
        }
示例#24
0
        public void ModQueueSpam()
        {
            PostContainer modQueue = reddit.Models.Moderation.ModQueue(new ModerationModQueueInput("comments"), "spam", testData["Subreddit"]);

            Validate(modQueue, true);
        }
示例#25
0
        public void PostHistorySubmitted()
        {
            PostContainer history = reddit.Models.Users.PostHistory("KrisCraig", "submitted", new UsersHistoryInput(context: 10));

            Validate(history);
        }
示例#26
0
        public void BestNoCats()
        {
            PostContainer posts = reddit.Models.Listings.Best(new CategorizedSrListingInput(includeCategories: false));

            Validate(posts);
        }
示例#27
0
        public void Controversial()
        {
            PostContainer posts = reddit.Models.Listings.Controversial(new TimedCatSrListingInput(includeCategories: true));

            Validate(posts);
        }
示例#28
0
        public void TopDay()
        {
            PostContainer posts = reddit.Models.Listings.Top(new TimedCatSrListingInput("day", includeCategories: true));

            Validate(posts);
        }
示例#29
0
 public ForumController(ForumContainer forumcontainer, PostContainer postcontainer, AccountContainer accountcontainer)
 {
     this.forumContainer   = forumcontainer;
     this.postContainer    = postcontainer;
     this.accountContainer = accountcontainer;
 }
示例#30
0
        public void GetByNames()
        {
            PostContainer posts = reddit.Models.Listings.GetByNames("t3_9gaze5,t3_9mfizx");

            Validate(posts);
        }