public void CloneRemovesCollections() { var cloner = new EntityCloner<Post>(new TestConfiguration()); var post = new Post() { PostId = 1, Title = "Foo", Comments = new List<Comment> { new Comment { CommentId = 1, Post = new Post() { PostId = 1 }} }}; var clone = cloner.Clone(post); Assert.True(clone.Comments == null || !clone.Comments.Any()); }
public void GetReturnsClone() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post = new Post { Title = "Foo" }; table.Insert(post); var returnedPost = table.Get(1); Assert.NotNull(returnedPost); Assert.Equal("Foo", returnedPost.Title); Assert.False(post == returnedPost); Assert.True(post.Equals(returnedPost)); }
public void IgnoredPropDoesNotGetCloned() { var cloner = new EntityCloner<Post>(new TestConfiguration()); var post = new Post() { PostId = 1, Title = "Foo", DoNotMap = true }; var clone = cloner.Clone(post); Assert.False(clone.DoNotMap); }
public void UpdateWorks() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post1 = new Post() { Title = "Foo" }; table.Insert(post1); post1.Title = "Bar"; table.Update(post1); var updatedPost = table.Get(1); Assert.False(post1 == updatedPost); Assert.True(post1.Equals(updatedPost)); Assert.Equal("Bar", updatedPost.Title); }
public void QueryWorks() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post1 = new Post() { Title = "Foo" }; var post2 = new Post() { Title = "Bar" }; table.Insert(post1); table.Insert(post2); var posts = table.Query().ToArray(); Assert.Equal(2, posts.Length); Assert.True(post1.Equals(posts[0])); Assert.True(post2.Equals(posts[1])); }
public void NoFetchReturnsEntityWithOnlyPrimaryKey() { var cloner = new FetchCloner(new TestConfiguration()); var query = (new SelectQuery<Post>(new NonExecutingSelectQueryExecutor())); var post = new Post { PostId = 1, Title = "Bar", Blog = new Blog { BlogId = 2, Description = "Foo" } }; var clone = cloner.Clone(query, post); Assert.False(ReferenceEquals(post, clone)); Assert.False(ReferenceEquals(post.Blog, clone.Blog)); Assert.False(ReferenceEquals(post.Title, clone.Title)); Assert.Equal(1, clone.PostId); Assert.Equal("Bar", clone.Title); Assert.Equal(2, clone.Blog.BlogId); Assert.Null(clone.Blog.Description); }
public void CloneWorks() { var cloner = new EntityCloner<Post>(new TestConfiguration()); var post = new Post() { PostId = 1, Title = "Foo", Blog = new Blog { BlogId = 1, Title = "My Blog" }}; var clone = cloner.Clone(post); Assert.False(post == clone); Assert.True(post.Equals(clone)); Assert.False(ReferenceEquals(post.Title, clone.Title)); Assert.Equal(post.PostId, clone.PostId); Assert.True(post.Blog.Equals(clone.Blog)); Assert.False(post.Blog == clone.Blog); Assert.Null(clone.Blog.Title); Assert.Equal("My Blog", post.Blog.Title); }
public void FetchedEntityIsReturned() { var cloner = new FetchCloner(new TestConfiguration()); var query = new SelectQuery<Post>(new NonExecutingSelectQueryExecutor()).Fetch(p => p.Blog) as SelectQuery<Post>; var post = new Post { PostId = 1, Title = "Bar", Blog = new Blog { BlogId = 2, Description = "Foo" } }; var clone = cloner.Clone(query, post); Assert.False(ReferenceEquals(post, clone)); Assert.False(ReferenceEquals(post.Blog, clone.Blog)); Assert.False(ReferenceEquals(post.Title, clone.Title)); Assert.False(ReferenceEquals(post.Blog.Description, clone.Blog.Description)); Assert.Equal(1, clone.PostId); Assert.Equal("Bar", clone.Title); Assert.Equal(2, clone.Blog.BlogId); Assert.Equal("Foo", clone.Blog.Description); }
public void ParentOfParentNotReturnedIfNotFetched() { var cloner = new FetchCloner(new TestConfiguration()); var query = new SelectQuery<Post>(new NonExecutingSelectQueryExecutor()).Fetch(p => p.Blog) as SelectQuery<Post>; var post = new Post { PostId = 1, Title = "Bar", Blog = new Blog { BlogId = 2, Description = "Foo", Owner = new User { UserId = 4, Username = "******" } } }; var clone = cloner.Clone(query, post); Assert.False(ReferenceEquals(post, clone)); Assert.False(ReferenceEquals(post.Blog, clone.Blog)); Assert.False(ReferenceEquals(post.Title, clone.Title)); Assert.False(ReferenceEquals(post.Blog.Description, clone.Blog.Description)); Assert.False(ReferenceEquals(post.Blog.Owner, clone.Blog.Owner)); Assert.Equal(1, clone.PostId); Assert.Equal("Bar", clone.Title); Assert.Equal(2, clone.Blog.BlogId); Assert.Equal("Foo", clone.Blog.Description); Assert.Equal(4, clone.Blog.Owner.UserId); Assert.Null(clone.Blog.Owner.Username); }
public void DeleteWorks() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post1 = new Post() { Title = "Foo" }; table.Insert(post1); table.Delete(post1); Assert.Empty(table.Query()); }
public void DeleteReturns0ForNonExistant() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post1 = new Post() { Title = "Foo" }; Assert.Equal(0, table.Delete(post1)); }
public void InsertReturns1() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post = new Post() { Title = "Foo" }; Assert.Equal(1, table.Insert(post)); }
public void InsertReturnsPrimaryKey() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post = new Post() { Title = "Foo" }; table.Insert(post); Assert.Equal(1, post.PostId); }