public void When_GettingBlogs_Should_GetFromDB()
        {
            Blog blog = new Blog("Sharon");

            Entry entry = new Entry("title", "body");

            using (_context = new TestBlogContext())
            {
                _context.Blogs.Add(blog);
                _context.SaveChanges();

                blog.AddEntry(entry);
                _context.Entries.Add(entry);

                _context.SaveChanges();
            }

            IList<Blog> blogs = _repository.GetBlogs();
            Blog dbBlog = blogs.Single(b => b.BlogId == blog.BlogId);

            Assert.That(blogs, Is.Not.Null);
            Assert.That(blogs.Count(), Is.GreaterThan(0));
            Assert.That(dbBlog, Is.Not.Null);
            Assert.That(dbBlog.Entries.Count(), Is.EqualTo(1));
            Assert.That(dbBlog.Entries.FirstOrDefault(o => o.EntryId == entry.EntryId), Is.Not.Null);
        }
        public void When_EditingEntry_Should_SaveToDB()
        {
            Blog blog = new Blog("Sharon");

            Entry entry = new Entry("title", "body");

            blog.AddEntry(entry);
            using (_context = new TestBlogContext())
            {
                _context.Blogs.Add(blog);
                _context.Entries.Add(entry);
                _context.SaveChanges();
            }

            _repository.EditEntry(entry.EntryId, "new title", "new body");

            using (_context = new TestBlogContext())
            {
                entry = _context.Entries.Single(e => e.EntryId == entry.EntryId);
            }

            Assert.That(entry, Is.Not.Null);
            Assert.That(entry.Title, Is.EqualTo("new title"));
            Assert.That(entry.Body, Is.EqualTo("new body"));
        }
        public void When_AddingEntry_Should_SaveToDB()
        {
            using (_context = new TestBlogContext())
            {
                _context.Blogs.Add(_blog);
                _context.SaveChanges();
            }

            _repository.AddEntry(_blog.BlogId, "title", "body");

            using (_context = new TestBlogContext())
            {
                _blog = _context.Blogs.Include(b => b.Entries).Single(b => b.BlogId == _blog.BlogId);

                Assert.That(_blog.Entries.Count, Is.EqualTo(1));
                Assert.That(_blog.Entries.First().Title, Is.EqualTo("title"));
            }
        }
        public void When_GettingEntries_Should_GetFromDB()
        {
            Blog blog = new Blog("Sharon");

            Entry entry = new Entry("title", "body");

            using (_context = new TestBlogContext())
            {
                _context.Blogs.Add(blog);
                _context.SaveChanges();

                blog.AddEntry(entry);
                _context.Entries.Add(entry);

                _context.SaveChanges();
            }

            IEnumerable<Entry> entries = _repository.GetEntries(blog.BlogId);

            Assert.That(entries.Count(), Is.EqualTo(1));
        }
        public void When_RemovingEntry_Should_RemoveFromBlog()
        {
            Blog blog = new Blog("Sharon");

            Entry entry = new Entry("title", "body");

            using (_context = new TestBlogContext())
            {
                _context.Blogs.Add(blog);
                _context.SaveChanges();

                blog.AddEntry(entry);
                _context.Entries.Add(entry);

                _context.SaveChanges();
            }

            _repository.RemoveEntry(blog.BlogId, entry.EntryId);

            using (_context = new TestBlogContext())
            {
                _blog = _context.Blogs.Single(b => b.BlogId == _blog.BlogId);

                Assert.That(_blog.Entries.Count, Is.EqualTo(0));
            }
        }
        public void When_GettingEntry_Should_GetFromDB()
        {
            Blog blog = new Blog("Sharon");

            Entry entry = new Entry("title", "body");

            blog.AddEntry(entry);
            using (_context = new TestBlogContext())
            {
                _context.Blogs.Add(blog);
                _context.Entries.Add(entry);
                _context.SaveChanges();
            }

            entry = _repository.GetEntry(entry.EntryId);

            Assert.That(entry, Is.Not.Null);
            Assert.That(entry.Title, Is.EqualTo("title"));
        }
        public void When_RemovingBlog_Should_RemoveFromDB()
        {
            Blog blog = new Blog("Sharon");

            Entry entry = new Entry("title", "body");

            using (_context = new TestBlogContext())
            {
                _context.Blogs.Add(blog);
                _context.SaveChanges();

                blog.AddEntry(entry);
                _context.Entries.Add(entry);

                _context.SaveChanges();
            }

            _repository.RemoveBlog(blog.BlogId);

            using (_context = new TestBlogContext())
            {
                entry = _context.Entries.SingleOrDefault(e => e.BlogId == blog.BlogId);
                blog = _context.Blogs.SingleOrDefault(b => b.BlogId == blog.BlogId);
            }

            Assert.That(blog, Is.Null);
            Assert.That(entry, Is.Null);
        }