public void CreatePost_Should_Create_New_Post() { // First check the count of posts IPostDAO dao = new PostSqlDAO(ConnectionString); IList <Post> posts = dao.GetAllPosts(this.NewUserOneId); int count = posts.Count; Assert.AreEqual(count, 3); // Add a post Post post = new Post(); post.UserId = this.NewUserOneId; post.Caption = "A new test post"; post.Image = "http://foo.com"; post = dao.CreatePost(post); // Check that the returned post has an id and a timstamp Assert.AreNotEqual(post.Id, 0); Assert.IsTrue((DateTime.Now - post.DateTimeStamp).Minutes < 1); // Count should be increased posts = dao.GetAllPosts(this.NewUserOneId); Assert.AreEqual(count + 1, posts.Count); }
public void GetFavoritesByUserName_Should_Return_Favorites_For_User_Named() { IPostDAO dao = new PostSqlDAO(ConnectionString); //IList<Post> posts = dao.GetFavoritesByUserName("legoman"); IList <Post> posts = dao.GetFavoritesByUserId(this.NewUserOneId); Assert.AreEqual(1, posts.Count); Assert.AreEqual(true, posts[0].IsFavored); Assert.AreEqual(false, posts[0].IsLiked); }
public void GetPostByPostId_Should_Work() { IPostDAO dao = new PostSqlDAO(ConnectionString); //Post post = dao.GetPostById(NewPostId, "legoman"); Post post = dao.GetPostById(NewPostId, this.NewUserOneId); Assert.AreEqual(NewPostId, post.Id); Assert.AreEqual(1, post.Comments.Count); Assert.AreEqual(1, post.NumberOfLikes); }
public void UnfavorPostByUserId_Unfavored_By_User_Who_Never_Liked_Post_Should_Not_Throw_Exception() { IFavoriteDAO fDao = new FavoriteSqlDAO(ConnectionString); IPostDAO pDao = new PostSqlDAO(ConnectionString); fDao.DisfavorPostByUserId(NewPostId, NewUserOneId); // Only NewUserTwoId liked the post in test-script.sql IList <Post> favorites = pDao.GetFavoritesByUserId(NewUserTwoId); Assert.AreEqual(1, favorites.Count); }
public void UnfavorPostByUserId_Should_Work() { IFavoriteDAO fDao = new FavoriteSqlDAO(ConnectionString); IPostDAO pDao = new PostSqlDAO(ConnectionString); fDao.DisfavorPostByUserId(NewPostId, NewUserTwoId); // NewUserTwoId now unliking post they liked in test-script.sql IList <Post> favorites = pDao.GetFavoritesByUserId(NewUserTwoId); Assert.AreEqual(0, favorites.Count); }
public void FavoredPostByUserId_Favored_Twice_By_Same_User_Should_Not_Throw_Exception() { IFavoriteDAO fDao = new FavoriteSqlDAO(ConnectionString); IPostDAO pDao = new PostSqlDAO(ConnectionString); fDao.FavorPostByUserId(NewPostId, NewUserTwoId); // NewUserTwoId already liked in test-script.sql IList <Post> favorites = pDao.GetFavoritesByUserId(NewUserTwoId); Assert.AreEqual(1, favorites.Count); }
public void FavoredPostByUserId_Should_Work() { IFavoriteDAO fDao = new FavoriteSqlDAO(ConnectionString); IPostDAO pDao = new PostSqlDAO(ConnectionString); fDao.FavorPostByUserId(NewPostId, NewUserOneId); // Post favored their own post IList <Post> favorites = pDao.GetFavoritesByUserId(this.NewUserOneId); Assert.AreEqual(1, favorites.Count); }
public IActionResult Index() { // If there is time, this would be a good opportunity to use to teach the students about DI // the project has two separate data sources to enable us to switch out the DAO //IPostDAO dao = new PostFileDAO(@"DAL/data.csv"); IPostDAO dao = new PostSqlDAO(@"Data Source=.\sqlexpress;Initial Catalog=TEgram;Integrated Security=True"); IList <Post> posts = dao.GetPosts(); return(View(posts)); }
public void GetAllPostsByUserName_Should_Return_All_Posts_For_User_Named() { IPostDAO dao = new PostSqlDAO(ConnectionString); //IList<Post> posts = dao.GetAllPostsByUserName("legoman"); IList <Post> posts = dao.GetAllPostsByUserId(this.NewUserOneId); Assert.AreEqual(2, posts.Count); Assert.AreEqual(1, posts[0].Comments.Count); Assert.AreEqual(1, posts[0].NumberOfLikes); Assert.AreEqual(0, posts[1].Comments.Count); Assert.AreEqual(0, posts[1].NumberOfLikes); }
public void GetAllPostsBy_Should_Return_All_Posts() { IPostDAO dao = new PostSqlDAO(ConnectionString); // IList<Post> posts = dao.GetAllPosts("legoman"); IList <Post> posts = dao.GetAllPosts(this.NewUserOneId); Assert.AreEqual(3, posts.Count); Assert.AreEqual(1, posts[0].Comments.Count); Assert.AreEqual(1, posts[0].NumberOfLikes); Assert.AreEqual(0, posts[2].Comments.Count); Assert.AreEqual(0, posts[2].NumberOfLikes); Assert.AreEqual(true, posts[0].IsFavored); Assert.AreEqual(false, posts[1].IsFavored); Assert.AreEqual(false, posts[2].IsFavored); Assert.AreEqual(false, posts[0].IsLiked); Assert.AreEqual(true, posts[1].IsLiked); Assert.AreEqual(false, posts[2].IsLiked); }
public void DeleteComment_Should_Work() { IPostDAO pDao = new PostSqlDAO(ConnectionString); Post post = pDao.GetPostById(this.NewPostId, this.NewUserOneId); int commentCount = post.Comments.Count; ICommentDAO cDao = new CommentSqlDAO(ConnectionString); cDao.DeleteComment(this.NewCommentId); post = pDao.GetPostById(this.NewPostId, this.NewUserOneId); Assert.AreEqual(post.Comments.Count + 1, commentCount); // Try to delete the comment again. Should not fail, even though // there is no change in the data. cDao.DeleteComment(this.NewCommentId); post = pDao.GetPostById(this.NewPostId, this.NewUserOneId); Assert.AreEqual(post.Comments.Count + 1, commentCount); }
public void CreateComment_Should_CreateComment() { IPostDAO pDao = new PostSqlDAO(ConnectionString); Post post = pDao.GetPostById(this.NewPostId, this.NewUserOneId); int commentCount = post.Comments.Count; ICommentDAO cDao = new CommentSqlDAO(ConnectionString); Comment comment = new Comment(); comment.PostId = this.NewPostId; comment.UserId = this.NewUserOneId; comment.Message = "This is a test comment"; comment = cDao.CreateComment(comment); // Assert that we got a new ID int commentId = comment.Id; Assert.AreNotEqual(0, commentId); // Assert that the post has one more comment than it did. post = pDao.GetPostById(this.NewPostId, this.NewUserOneId); Assert.AreEqual(post.Comments.Count, ++commentCount); // Add a second comment by the same user - should be allowed and should be a new Id comment = new Comment(); comment.PostId = this.NewPostId; comment.UserId = this.NewUserOneId; comment.Message = "This is a SECOND test comment"; comment = cDao.CreateComment(comment); // Assert that we got a new ID, different from the previous one Assert.AreNotEqual(0, comment.Id); Assert.AreNotEqual(commentId, comment.Id); // Assert that the post has one more comment than it did. post = pDao.GetPostById(this.NewPostId, this.NewUserOneId); Assert.AreEqual(post.Comments.Count, ++commentCount); }