Example #1
0
        public void GetAll_WhenCalledWithExistingBlogPosts_ReturnsBlogPosts()
        {
            //Given
            context.Database.EnsureDeleted();
            BlogPost fakeBlogPost1 = new BlogPost {
                Id      = 1,
                Title   = "First Blog Post",
                Author  = "Edith Mendoza",
                Content = "First Blog Post by Edith Mendoza"
            };
            BlogPost fakeBlogPost2 = new BlogPost {
                Id      = 2,
                Title   = "Second Blog Post",
                Author  = "Marcelo Salcedo",
                Content = "First Blog Post by Marcelo Salcedo"
            };

            context.Add(fakeBlogPost1);
            context.Add(fakeBlogPost2);
            context.SaveChanges();
            var service = new InMemoryDataBaseBlogPostService(context);

            //When
            var blogPosts = service.GetAll();

            //Then
            blogPosts.Count.Should().Be(2);
        }
Example #2
0
        public void Insert_WhenCalled_InsertBlogPostToContext()
        {
            //Given
            context.Database.EnsureDeleted();
            BlogPost fakeBlogPost = new BlogPost {
                Title   = "First Blog Post",
                Author  = "Edith Mendoza",
                Content = "First Blog Post by Edith Mendoza"
            };
            var service = new InMemoryDataBaseBlogPostService(context);

            //When
            var newBlogPost = service.Insert(fakeBlogPost);

            //Then
            context.BlogPosts.Find(newBlogPost.Id).Should().BeEquivalentTo(newBlogPost);
        }
Example #3
0
        public void Delete_WhenCalledWithExistingBlogPost_RemovesBlogPostFromContext()
        {
            //Given
            context.Database.EnsureDeleted();
            BlogPost fakeBlogPost = new BlogPost {
                Id      = 1,
                Title   = "First Blog Post",
                Author  = "Edith Mendoza",
                Content = "First Blog Post by Edith Mendoza"
            };
            var newBlogPost = context.Add(fakeBlogPost).Entity;
            var service     = new InMemoryDataBaseBlogPostService(context);

            //When
            service.Delete(newBlogPost);

            //Then
            context.BlogPosts.Find(newBlogPost.Id).Should().BeNull();
        }
Example #4
0
        public void GetById_WhenCalledWithExistingId_ReturnsBlogPost()
        {
            //Given
            context.Database.EnsureDeleted();
            BlogPost fakeBlogPost = new BlogPost {
                Id      = 1,
                Title   = "First Blog Post",
                Author  = "Edith Mendoza",
                Content = "First Blog Post by Edith Mendoza"
            };

            context.Add(fakeBlogPost);
            context.SaveChanges();
            var service = new InMemoryDataBaseBlogPostService(context);
            //When
            var newBlogPost = service.GetById(fakeBlogPost.Id);

            //Then
            newBlogPost.Should().BeEquivalentTo(fakeBlogPost);
        }
Example #5
0
        public void Update_WhenCalledWithExistingBlogPost_UpdatesToValuesGiven()
        {
            //Given
            context.Database.EnsureDeleted();
            BlogPost fakeBlogPost = new BlogPost {
                Id      = 1,
                Title   = "First Blog Post",
                Author  = "Edith Mendoza",
                Content = "First Blog Post by Edith Mendoza"
            };

            context.Add(fakeBlogPost);
            context.SaveChanges();
            var service = new InMemoryDataBaseBlogPostService(context);

            //When
            fakeBlogPost.Title = "First Blog Post Updated";
            service.Update(fakeBlogPost);
            context.SaveChanges();
            //Then
            context.BlogPosts.Find(1L).Title.Should().BeEquivalentTo("First Blog Post Updated");
        }