public async Task <IActionResult> EditPost(EditForumInputModel input)
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                return(this.Redirect("/Identity/Account/Login"));
            }

            await this.forumsService.EditPost(input);

            return(this.Redirect("/RP/MyForums"));
        }
        public async Task EditPost(EditForumInputModel input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input", "The given input is null!");
            }

            var post = await this.db.Forums.FirstOrDefaultAsync(f => f.ForumId == input.ForumId);

            if (post == null)
            {
                throw new InvalidOperationException("No post found with this id!");
            }

            post.ForumText  = input.Text;
            post.ForumTopic = input.Topic;

            await this.db.SaveChangesAsync();
        }
        public async Task EditPostShouldThrowInvalidOperationExceptionIfGivenInvalidForumId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("forumTestAddPost");
            var db = new ApplicationDbContext(options.Options);

            var service = new ForumsService(db);

            string editedTopic = "EditedTopic";
            string editedText  = "EditedText";

            var editInput = new EditForumInputModel()
            {
                ForumId = "fake_forum_id",
                Topic   = editedTopic,
                Text    = editedText,
            };

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.EditPost(editInput));
        }
        public async Task EditPostShouldEditTheGivenPostWithTheGivenEditForumInputModel()
        {
            int defaultLikes = 0;
            var topic        = "TestTopic";
            var text         = "TestText";

            var forum = new Forum()
            {
                ForumText  = text,
                ForumTopic = topic,
                Likes      = defaultLikes,
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("forumTestAddPost");
            var db = new ApplicationDbContext(options.Options);

            await db.Forums.AddAsync(forum);

            await db.SaveChangesAsync();

            var service = new ForumsService(db);

            string editedTopic = "EditedTopic";
            string editedText  = "EditedText";

            var editInput = new EditForumInputModel()
            {
                ForumId = forum.ForumId,
                Topic   = editedTopic,
                Text    = editedText,
            };

            await service.EditPost(editInput);

            var forumDb = await db.Forums.FirstOrDefaultAsync(f => f.ForumId == forum.ForumId);

            Assert.NotNull(forumDb);
            Assert.Equal(editedTopic, forumDb.ForumTopic);
            Assert.Equal(editedText, forumDb.ForumText);
        }