Esempio n. 1
0
        [TestMethod]//ok
        public void DeleteComTest()
        {
            //firstly, add user to add him post
            var user = new Users
            {
                Nickname = Guid.NewGuid().ToString().Substring(10),
                Username = Guid.NewGuid().ToString().Substring(10),
                Info     = Guid.NewGuid().ToString().Substring(10)
            };
            var dataLayer = new DataLayer.Sql.DataLayer(ConnectionString);

            user = dataLayer.AddUser(user);
            //add post to user
            var post = new Posts
            {
                UserId = user.UserId,
                Date   = DateTime.Now,
                Photo  = Guid.NewGuid().ToString().Substring(10)
            };

            post = dataLayer.AddPost(post);
            //add com to post
            var com = new Comments()
            {
                Date   = DateTime.Now,
                FromId = user.UserId,
                PostId = post.PostId,
                Text   = Guid.NewGuid().ToString().Substring(10)
            };

            dataLayer.AddCommentToPost(post.PostId, com);
            dataLayer.DeleteComment(com.ComId);
            Assert.AreEqual(dataLayer.IsComment(com.ComId), false);
        }
        public void ShouldAddGetDeleteComment()
        {
            //arrange
            var comment = new Comment
            {
                UserId      = Guid.Parse("3c8fddae-8ebc-4cd4-9eb2-30ce678d6c23") /*Guid.NewGuid()*/,
                PostId      = Guid.Parse("82243a65-d1e6-440c-a906-5dffb9cd653c") /*Guid.NewGuid()*/,
                Date        = DateTime.Now,
                CommentText = "This is my comment"/*Guid.NewGuid().ToString()*/
            };
            //act
            var dataLayer  = new DataLayer.Sql.DataLayer(_connectionString);
            var addComment = dataLayer.AddComment(comment);
            var dataLayer1 = new DataLayer.Sql.DataLayer(_connectionString);
            var getComment = dataLayer1.GetComment(addComment.CommentId);
            var dataLayer2 = new DataLayer.Sql.DataLayer(_connectionString);
            int isDeleted  = dataLayer2.DeleteComment(getComment.CommentId);

            //asserts
            Assert.AreEqual(addComment.CommentId, getComment.CommentId);
            Assert.AreEqual(addComment.UserId, getComment.UserId);
            Assert.AreEqual(addComment.PostId, getComment.PostId);
            //Assert.AreEqual(addComment.Date, getComment.Date);
            Assert.AreEqual(addComment.CommentText, getComment.CommentText);
            Assert.IsNotNull(isDeleted);
        }
        public void ShouldDeleteComment()
        {
            //arrange
            var user = GenerateUser();

            //act
            var dataLayer = new DataLayer.Sql.DataLayer(ConnectionSql);

            dataLayer.AddUser(user);

            var photo = GeneratePhoto(user.Id);

            dataLayer.AddPhoto(photo);

            var comment = GenerateComment(user.Id, photo.Id);

            dataLayer.AddComment(comment);
            dataLayer.DeleteComment(comment.Id);

            var resComment = dataLayer.GetComment(comment.Id);

            //assert
            Assert.AreNotEqual(resComment.Id, comment.Id);
        }