public void Add_ValidInputData_ShouldSucceed()
        {
            Blog blog = new Blog
            {
                Url = "www.instagram.com"
            };
            Post post = new Post
            {
                Title   = "How summer activities changed how we think about death",
                Content = "lksahfpwqohavskjlsbatuwqhaps;vddsah",
                Blog    = blog
            };
            int beforeInsertCount;

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                dbContext.Blogs.Add(blog);
                dbContext.SaveChangesAsync();
                beforeInsertCount = dbContext.Posts.Count();
            }

            int result;

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                PostService service = new PostService(dbContext);
                result = service.Add(post.Title, post.Content, blog.Url);
            }

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                Assert.AreEqual(1, result);
                Assert.AreEqual(beforeInsertCount + 1, dbContext.Posts.Count());
                var newlyAddedPost = dbContext.Posts
                                     .Include(p => p.Blog)
                                     .Where(p => p.Title.Contains("How summer activities changed how we think about death"))
                                     .Single();
                Assert.AreEqual(post.Title, newlyAddedPost.Title);
                Assert.AreEqual(post.Content, newlyAddedPost.Content);
                Assert.IsNotNull(newlyAddedPost.Blog);
                Assert.AreEqual(post.Blog.Url, newlyAddedPost.Blog.Url);
            }
        }
        public void UpdateTitle_Always_ShouldSucceed()
        {
            Blog facebook;
            Post post;

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                facebook = dbContext.Blogs
                           .Where(b => b.Url.Contains("facebook"))
                           .Single();
                post = new Post
                {
                    Title   = "Why game jobs are killing you",
                    Content = "ouvaisdhvsa",
                    Blog    = facebook
                };
                dbContext.Posts.AddRange(post);
                dbContext.SaveChangesAsync();
            }

            string newTitle = "Why hybrid supercars are afraid of the truth";

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                PostService service = new PostService(dbContext);
                service.UpdateTitle(
                    post.Title,
                    newTitle
                    );
            }

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                var updatedPost = dbContext.Posts
                                  .Include(p => p.Blog)
                                  .Where(p => p.Title == newTitle)
                                  .Single();
                Assert.AreEqual(post.Content, updatedPost.Content);
                Assert.AreEqual(post.PostId, updatedPost.PostId);
                Assert.AreEqual(post.BlogId, updatedPost.BlogId);
                Assert.AreEqual(post.Blog.Url, updatedPost.Blog.Url);
            }
        }
        public void UpdateUrl_Always_ShouldSucceed()
        {
            Blog instagram = new Blog
            {
                Url = "www.instagram.com"
            };
            Post existingPost;

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                dbContext.Blogs.Add(instagram);
                dbContext.SaveChangesAsync();
                existingPost = dbContext.Posts
                               .OrderBy(p => Guid.NewGuid().ToString())
                               .First();
            }

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                PostService service = new PostService(dbContext);
                service.UpdateUrl(
                    existingPost.Title,
                    instagram.Url
                    );
            }

            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                var updatedPost = dbContext.Posts
                                  .Include(p => p.Blog)
                                  .Where(p => p.Title == existingPost.Title)
                                  .Single();
                Assert.AreEqual(existingPost.Content, updatedPost.Content);
                Assert.AreEqual(existingPost.PostId, updatedPost.PostId);
                Assert.AreEqual(instagram.Url, updatedPost.Blog.Url);
            }
        }
        private void SeedData()
        {
            using (var dbContext = new BloggingDbContext(_contextOptions))
            {
                dbContext.Database.EnsureCreatedAsync();

                Blog google = new Blog {
                    Url = "www.google.com"
                };
                Blog facebook = new Blog {
                    Url = "www.facebook.com"
                };
                Blog lttStore = new Blog {
                    Url = "www.lttstore.com"
                };

                //adding blogs
                dbContext.Blogs.AddRangeAsync(
                    google,
                    facebook,
                    lttStore
                    );

                dbContext.Posts.AddRangeAsync(
                    new Post
                {
                    Title   = "How to be unpopular in the business insurance world",
                    Content = "fslahfsdakjfds",
                    Blog    = google
                },
                    new Post
                {
                    Title   = "Why your accessory never works out the way you plan",
                    Content = "fslahfsdakjfds",
                    Blog    = google
                },
                    new Post
                {
                    Title   = "The 17 worst songs about special olympic world games",
                    Content = "fslahfsdakjfds",
                    Blog    = google
                },
                    new Post
                {
                    Title   = "The 8 worst home tech gadgets in history",
                    Content = "fslahfsdakjfds",
                    Blog    = facebook
                },
                    new Post
                {
                    Title   = "14 things your boss expects you know about football highlights",
                    Content = "fslahfsdakjfds",
                    Blog    = facebook
                },
                    new Post
                {
                    Title   = "10 things your boss expects you know about popular songs",
                    Content = "fslahfsdakjfds",
                    Blog    = facebook
                },
                    new Post
                {
                    Title   = "Why you'll never succeed at vaccination schedules",
                    Content = "fslahfsdakjfds",
                    Blog    = lttStore
                },
                    new Post
                {
                    Title   = "Why celebrity cruises will change your life",
                    Content = "fslahfsdakjfds",
                    Blog    = lttStore
                },
                    new Post
                {
                    Title   = "Why hairstyles are killing you",
                    Content = "fslahfsdakjfds",
                    Blog    = lttStore
                }
                    );
                dbContext.SaveChangesAsync();
            }
        }