Beispiel #1
0
        public void MBlogRepository_InsertOrUpdatePost_ShouldInsertPost()
        {
            var context = new TestDbContext();
            var repo = new MBlogRepository(context);
            var post = new Post()
            {
                Title = "Test Title",
            };

            repo.AddPost(post);

            Assert.AreEqual(1, context.Posts.Count());
        }
Beispiel #2
0
        public void MBlogRepository_InsertOrUpdatePost_ShouldUpdatePost()
        {
            var context = new TestDbContext();
            var repo = new MBlogRepository(context);
            var newTitle = "NewTitle";
            var post = new Post()
            {
                Title = "Test Title",
            };
            var post2 = post;
            post2.Title = newTitle;

            repo.AddPost(post);
            repo.AddPost(post2);

            Assert.AreEqual(1, context.Posts.Count());
            Assert.AreEqual(newTitle, context.Posts.ToArray()[0].Title);
        }
Beispiel #3
0
 public void AddPost(Post post)
 {
     db.Posts.Add(post);
     db.SaveChanges();
 }
Beispiel #4
0
 public ActionResult Create(Post post)
 {
     post.PublishDate = DateTime.UtcNow;
     repo.AddPost(post);
     return RedirectToAction("Index");
 }