Example #1
0
        public Post DeletePost(Post post)
        {
            Post dbEntry = context.Posts.Find(post.PostId);
            if(dbEntry != null)
            {
                context.Posts.Remove(dbEntry);
                context.SaveChanges();
            }

            return dbEntry;
        }
Example #2
0
        public void CreateDoesNotAddPost()
        {
            //Arrange
            Post post = new Post { PostId = 1, Blog = new Blog { BlogId = 1, BlogTitel = "First test-blog", Closed = false }, PostTitle = "Post #1", Text = "First test-post", Date = new DateTime() };
            var controller = new PostController(_repository.Object, _manager);
            controller.ModelState.AddModelError("error", "error");

            //Act
            ActionResult result = controller.Edit(post);

            //Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Example #3
0
        public void CreateAddsPost()
        {
            //Arrange
            Post post = new Post { PostId = 1, Blog = new Blog { BlogId = 1, BlogTitel = "First test-blog", Closed = false }, PostTitle = "Post #1", Text = "First test-post", Date = new DateTime() };
            var controller = new PostController(_repository.Object, _manager);

            //Act
            ActionResult result = controller.Edit(post);

            //Assert
            _repository.Verify(b => b.AddPost(post, 1));
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Example #4
0
        public void AddPost(Post post, int blogId)
        {
            if (post.PostId == 0)
            {
                post.Blog = context.Blogs.Find(blogId);
                post.Date = DateTime.Now;
                context.Posts.Add(post);
            }
            else
            {
                Post dbEntry = context.Posts.Find(post.PostId);
                if (dbEntry != null)
                {
                    dbEntry.PostTitle = post.PostTitle;
                    dbEntry.Text = post.Text;
                }
            }

            context.SaveChanges();
        }