public void Assign_ShouldAssignIdOfPost()
        {
            // Arrange
            var post = new Post { Id = 0 };

            // Act
            target.Assign(post);

            // Assert
            post.Id.Should().Be(seedNumber + 1);
        }
        public void ShouldPopulateCollectionBasedReference()
        {
            var context = new InMemoryDataContext();

            var child = new Post();
            var blog = new Blog("Test");
            child.Blog = blog;

            context.Add(child);
            context.Commit();

            Assert.AreEqual(1, blog.Posts.Count(x => x == child));
        }
        public void ShouldPopulateSingleReference()
        {
            var context = new InMemoryDataContext();

            var child = new Post();
            var blog = new Blog("Test");
            blog.Posts.Add(child);

            context.Add(blog);
            context.Commit();

            Assert.IsNotNull(child.Blog);
        }
        public void ShouldPopulateBackReferenceCollections()
        {
            // Arrange
            var context = new InMemoryDataContext();
            var blog = new Blog();
            var post = new Post { Blog = blog };
            context.Add(post);
            context.Commit();

            // Act
            var fetchedBlog = context.AsQueryable<Blog>().First();

            // Assert
            fetchedBlog.Posts.Count().Should().Be(1);
        }
        public void Add_ShouldUseIdentityForType()
        {
            //Arrange
            _context.RegisterIdentityStrategy(new IntegerIdentityStrategy<Post>(x => x.Id));
            var post = new Post {Id = 0};

            //Act
            _context.Add(post);

            //Assert
            post.Id.Should().NotBe(0);
        }
        public void Commit_ShouldRemoveOrphanedCollectionMembersWhenWholeCollectionRemoved()
        {
            // Arrange
            var post1 = new Post();
            var post2 = new Post();
            var blog = new Blog
            {
                Posts = new List<Post> {post1, post2}
            };
            _context.Add(blog);
            _context.Commit();
            blog.Posts = null;

            // Act
            _context.Commit();

            // Assert
            _context.AsQueryable<Post>().Should().NotContain(post1);
            _context.AsQueryable<Post>().Should().NotContain(post2);
            _context.AsQueryable<Post>().Count().Should().Be(0);
        }
        public void Remove_ShouldRemoveFromParentButNotDeleteChildObjectsThatAreReferencedMoreThanOne()
        {
            //arrange 

            var post1 = new Post();
            var post2 = new Post();
            var blog1 = new Blog
            {
                Posts = new List<Post> {post1, post2}
            };
            var blog2 = new Blog
            {
                Posts = new List<Post> {post1}
            };
            var site = new Site
            {
                Blog = blog2
            };
            _context.Add(blog1);
            _context.Add(site);

            // Act
            _context.Remove(blog2);

            // Assert
            _context.AsQueryable<Post>().Count().Should().Be(2);
            _context.AsQueryable<Post>().First().Should().BeSameAs(post1);
            _context.AsQueryable<Blog>().Single().Posts.Count().Should().Be(2);
            site.Blog.Should().BeNull();
        }
        public void Remove_ShouldNotRemoveIfReferencedByAnotherCollection()
        {
            // Arrange
            var post1 = new Post();
            var post2 = new Post();
            var blog1 = new Blog
            {
                Posts = new List<Post> {post1, post2}
            };
            var blog2 = new Blog
            {
                Posts = new List<Post> {post1}
            };
            _context.Add(blog1);
            _context.Add(blog2);

            // Act
            _context.Remove(post2);

            // Assert
            _context.AsQueryable<Post>().Count().Should().Be(1);
            _context.AsQueryable<Post>().First().Should().BeSameAs(post1);
            _context.AsQueryable<Blog>().Where(b => b.Posts.Count > 1).Count().Should().Be(0);
        }
        public void Remove_ShouldRemoveDependentGraphOnBranchRemoval()
        {
            //arrange 
            var post = new Post();
            var blog = new Blog
            {
                Posts = new List<Post> {new Post(), post}
            };
            var site = new Site
            {
                Blog = blog
            };
            _context.Add(site);

            //act
            _context.Remove(blog);

            //assert
            IQueryable<Post> posts = _context.AsQueryable<Post>();
            posts.Count().Should().Be(0);
        }
        public void Remove_ShouldRemoveObjectFromRelatedCollection()
        {
            //arrange 
            var post = new Post();
            var blog = new Blog {Posts = new List<Post> {post}};
            _context.Add(blog);

            //act
            _context.Remove(post);

            //assert
            _context.AsQueryable<Blog>().Count().Should().Be(1);
            _context.AsQueryable<Blog>().First().Posts.Count().Should().Be(0);
            _context.AsQueryable<Post>().Count().Should().Be(0);
        }
        public void Add_ShouldNotAddAnItemTwiceForMultipleReferences()
        {
            //arrange 
            var post = new Post();
            var blog = new Blog
            {
                Posts = new List<Post> {post, new Post()}
            };
            var blog2 = new Blog
            {
                Posts = new List<Post> {post}
            };
            _context.Add(blog);

            //act
            _context.Add(blog2);

            //assert
            _context.AsQueryable<Post>().Count().Should().Be(2);
        }
Example #12
0
 public void Post(string title, Post post)
 {
     var blog = _repo.Find(new FindBlogByTitle(title));
     blog.Posts.Add(post);
     _repo.Context.Commit();
 }