Ejemplo n.º 1
0
        protected virtual void Validate(Blog expectedBlog, Blog actualBlog)
        {
            Assert.AreEqual(expectedBlog.Posts.Count, actualBlog.Posts.Count);
            for (int i = 0; i < expectedBlog.Posts.Count; i++)
            {
                var expectedPost = expectedBlog.Posts.ElementAt(i);
                var post = actualBlog.Posts.ElementAt(i);

                Assert.AreEqual(expectedPost.Id, post.Id);
                Assert.AreEqual(expectedPost.Comments.Count, post.Comments.Count);

                for (int j = 0; j < expectedPost.Comments.Count; j++)
                {
                    var expectedComment = expectedPost.Comments.ElementAt(j);
                    var comment = post.Comments.ElementAt(j);
                    Assert.AreEqual(expectedComment.Id, comment.Id);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create blog with 4 posts 
        /// 1st post have 0 comments 
        /// 2nd post have 1 comment 
        /// 3rd post have 2 comments 
        /// 4th post have 3 comments
        /// </summary>
        protected override void OnSetUp()
        {
            base.OnSetUp();

            using (var session = OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var blog = new Blog()
                {
                    Blogger = "Blogger",
                    Name = "Blog #1",
                    Posts = new List<Post>()
                };

                for (int i = 1; i <= 4; i++)
                {
                    var post = new Post()
                    {
                        Blog = blog,
                        CtreationDate = DateTime.Now.Subtract(TimeSpan.FromHours(1)).AddMinutes(i*10),
                        Text = "bla bla bla",
                        Comments = new List<Comment>()
                    };
                    blog.Posts.Add(post);

                    for (int j = 1; j < i; j++)
                    {
                        var comment = new Comment()
                        {
                            Post = post,
                            CtreationDate = post.CtreationDate.AddMinutes(j),
                            Blogger = "Blogger #" + j,
                            Text = "bla bla bla " + j
                        };
                        post.Comments.Add(comment);
                    }
                }

                session.SaveOrUpdate(blog);

                tx.Commit();

                expected = blog;
            }
        }