Esempio n. 1
0
        public void When_AddingBlog_Should_AddToListOfBlogs()
        {
            Blog blog = new Blog("Sharon2");
            _blogRepository.AddBlog(blog);

            _context.Verify(o => o.SaveChanges(), Times.Once);
        }
        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_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);
        }
        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);
        }
Esempio n. 5
0
 public Domain.BlogPost GetBlogPost(Domain.Blog blog, int authorId)
 {
     return(new Domain.BlogPost()
     {
         BlogId = blog.BlogId,
         Title = Title,
         AuthorId = authorId,
         Message = Message
     });
 }
Esempio n. 6
0
        public void AddBlog(Blog blog)
        {
            if (blog == null)
            {
                throw new ArgumentNullException("blog");
            }

            using (_context = _contextFactory.CreateContext())
            {
                _context.Blogs.Add(blog);
                _context.SaveChanges();
            }
        }
        public void When_AddingBlog_Should_AddToDB()
        {
            Blog blog = new Blog("Sharon");

            _repository.AddBlog(blog);

            using (_context = new TestBlogContext())
            {
                IEnumerable<Blog> blogs = _context.Blogs;
                blog = blogs.SingleOrDefault(b => b.BlogId == blog.BlogId);
            }

            Assert.That(blog, Is.Not.Null);
        }
        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"));
            }
        }
Esempio n. 9
0
        public void When_GettingBlogs_Should_ReturnBlogs()
        {
            _blog = new Blog("Sharon")
            {
                BlogId = 1
            };

            _blog.AddEntry(new Entry("title", "body")
            {
                EntryId = 1
            });

            _blogs.Add(_blog);
            _blogRepository.Setup(o => o.GetBlogs()).Returns(_blogs);
            _entryRepository.Setup(o => o.GetEntries(_blog.BlogId)).Returns(_blog.Entries);

            IEnumerable<BlogDto> blogs = _blogService.GetBlogs().ToList();
            BlogDto blog = blogs.Single(o => o.BlogId == _blog.BlogId);

            Assert.That(blogs, Is.Not.Null);
            Assert.That(blog.Author == "Sharon");
            Assert.That(blog.Entries.Count(), Is.EqualTo(1));
        }
        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"));
        }
Esempio n. 13
0
 public Domain.Blog UpdateBlog(Domain.Blog blog)
 {
     blog.Name     = Name;
     blog.HeadLine = HeadLine;
     return(blog);
 }
Esempio n. 14
0
        public void AddBlog(BlogDto blogDto)
        {
            Blog blog = new Blog(blogDto.Author);

            _blogRepository.AddBlog(blog);
        }