Exemplo n.º 1
0
        public void ShouldFailPostLikeAlreadyLiked()
        {
            PostLike like = new PostLike(Guid.NewGuid());

            Post post = GetNewSimplePost();

            post.AddLike(like);
            Assert.AreEqual(1, post.Likes.Count);
            post.AddLike(like);

            Assert.IsFalse(post.IsValid);
            Assert.AreEqual("Você já curtiu essa publicação uma vez.", post.GetNotifications().FirstOrDefault().Description);
        }
Exemplo n.º 2
0
        public void ShouldAddPostLike()
        {
            PostLike like = new PostLike(Guid.NewGuid());

            Post post = GetNewSimplePost();

            post.AddLike(like);

            Assert.IsTrue(post.IsValid);
            Assert.AreEqual(1, post.Likes.Count);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            bool repeat = true;

            while (repeat == true)
            {
                Console.Write("Insert a title of post: ");
                string title = Console.ReadLine();
                Console.Write("Insert a content of post: ");
                string   content = Console.ReadLine();
                DateTime moment  = DateTime.Now;
                Console.Write("Insert a number of likes: ");
                int likes = int.Parse(Console.ReadLine());

                Post post = new Post(moment, title, content);
                for (int i = 0; i < likes; i++)
                {
                    Console.WriteLine("Your post received a like!");
                    post.AddLike();
                }

                Console.WriteLine("Insert a number of comments: ");
                int     ncomments = int.Parse(Console.ReadLine());
                Comment comment;
                for (int i = 0; i < ncomments; i++)
                {
                    Console.WriteLine("Insert text of comment: ");
                    string text = Console.ReadLine();
                    comment = new Comment(text, DateTime.Now);
                    post.AddComment(comment, DateTime.Now);
                }

                Console.WriteLine(post.ToString());

                Console.WriteLine("Do you want to do another post: (Y/N)");
                char r = char.Parse(Console.ReadLine().ToUpper());
                if (r == 'Y')
                {
                    repeat = true;
                }
                else
                {
                    repeat = false;
                }
            }
        }
Exemplo n.º 4
0
        static void LikeOrDislikePost(int option)
        {
            if (Posts.Count == 0)
            {
                Console.WriteLine($"There's no post to {(option == 1 ? "Like" : "Unlike")}.");
                return;
            }

            Post post = SelectPost();

            Console.WriteLine();

            if (option == 1)
            {
                post.AddLike();
                return;
            }

            post.ReduceLikes();
        }
Exemplo n.º 5
0
        public async Task <CommandResult> Handle(AddLikeCommand request, CancellationToken cancellationToken)
        {
            Post post = await _postRepository.GetByIdAsync(request.PostId);

            bool canModify = await CanModifyPost(post);

            if (!canModify)
            {
                return(FailureDueToPostNotFound());
            }

            PostLike postLike = new PostLike(_currentProfileId);

            post.AddLike(postLike);
            if (!post.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(post));
            }

            await _postRepository.UpdateAsync(post);

            return(await CommitAndPublishDefaultAsync());
        }
Exemplo n.º 6
0
        static void ProgramaDois()
        {
            int         numberOfPosts, numberOfComments;
            string      title, content, text;
            char        checkLikes;
            Comment     comment;
            List <Post> posts = new List <Post>()
            {
            };

            //ENTRADA DE DADOS
            Console.WriteLine("PROGRAMA DOIS \n----------\n\n");
            Console.Write("Quantidade de Posts: ");
            numberOfPosts = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfPosts; i++)
            {
                Console.WriteLine($"POST #{i + 1}");

                Console.Write("Título: ");
                title = Console.ReadLine();

                Console.Write("Conteúdo: ");
                content = Console.ReadLine();

                Post post = new Post(title, DateTime.Now, content);

                Console.Write("Você gostou do post? ");
                checkLikes = Char.Parse(Console.ReadLine());
                if (checkLikes == 's' ||
                    checkLikes == 'S')
                {
                    post.AddLike();
                }

                for (int k = 0; k < 6; k++)
                {
                    post.AddLike();
                }

                Console.Write("Quantidade de Comentários: ");
                numberOfComments = int.Parse(Console.ReadLine());

                for (int j = 0; j < numberOfComments; j++)
                {
                    Console.WriteLine($"POST {i + 1} COMENTÁRIO #{j + 1}");

                    Console.WriteLine("Comentário: ");
                    text = Console.ReadLine();

                    comment = new Comment(text)
                    {
                        Text = text
                    };
                    post.AddComment(comment);
                }

                posts.Add(post);
            }

            Console.WriteLine("Imprimindo Posts e Comentários: \n\n");

            foreach (Post p in posts)
            {
                Console.WriteLine(p);
            }
        }