예제 #1
0
 public void Delete(Blog blog)
 {
     using (ITransaction transaction = _session.BeginTransaction())
     {
         _session.Delete(blog);
         transaction.Commit();
     }
 }
예제 #2
0
 public Blog Save(Blog blog)
 {
     using (ITransaction transaction = _session.BeginTransaction())
     {
         //session.SaveOrUpdate(blog);
         _session.Save(blog);
         transaction.Commit();
     }
     return blog;
 }
        public void CanSaveOnlyBlogTest()
        {
            //arrange
            IBlogService service = _kernel.Get<IBlogService>();
            Blog blog = new Blog {Name = "unit-test-simple-blog"};

            //act
            Blog actual = service.Save(blog);

            //assert
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Id > 0);
        }
        public void CanSaveBlogTest()
        {
            //arrange
            IBlogService service = _kernel.Get<IBlogService>();

            //act
            Blog expected = new Blog
            {
                Id = 1,
                Name = "unit-test-blog",
                BlogPosts = new List<BlogPost>
                {
                    new BlogPost
                    {
                        Id = 1,
                        BlogSubject	= "blog subject 1-1",
                        BlogContent = "blog content 1-1",
                        Comments = new List<Comment>
                        {
                            new Comment
                            {
                                Id = 1,
                                CommentContent = "comment 1-1",
                                Username = "******"
                            }
                        }
                    },
                    new BlogPost
                    {
                        Id = 2,
                        BlogSubject = "blog subject 1-2",
                        BlogContent = "blog content 1-2",
                    }
                }
            };

            Blog actual = service.Save(expected);

            Assert.IsNotNull(actual);
        }
 public Blog Save(Blog blog)
 {
     IDocumentSession session = _documentStore.OpenSession();
     //code below is for demo purposes only, shows how child collections could get "assigned" an id
     if (blog.BlogPosts != null)
     {
         foreach (BlogPost blogPost in blog.BlogPosts.Where(bp => bp.Id <= 0))
         {
             session.Advanced.Conventions.GenerateDocumentKey(blogPost);
             if (blogPost.Comments != null)
             {
                 foreach (Comment comment in blogPost.Comments.Where(c => c.Id <= 0))
                 {
                     session.Advanced.Conventions.GenerateDocumentKey(comment);
                 }
             }
         }
     }
     session.Store(blog);
     session.SaveChanges();
     return blog;
 }
 public void Delete(Blog blog)
 {
     IDocumentSession session = _documentStore.OpenSession();
     session.Delete(blog);
     session.SaveChanges();
 }
        public void CanSaveBlogWithSpecificIdAndGetItBackByIdTest()
        {
            //arrange
            int blogId = 5;
            IBlogService service = _kernel.Get<IBlogService>();
            Blog expected = new Blog
            {
                Id = blogId,
                Name = "raven-db-unit-test-blog-no-" + blogId
            };

            //act
            Blog saved = service.Save(expected);

            BlogViewModel actual = service.GetBlog(blogId);

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Blog);
        }
예제 #8
0
 public Blog Save(Blog blog)
 {
     return _blogRepository.Save(blog);
 }
예제 #9
0
 public Blog Save(Blog blog)
 {
     blog = _db.Blog.Add(blog);
     _db.SaveChanges();
     return blog;
 }
예제 #10
0
 public void Delete(Blog blog)
 {
     _db.Blog.Remove(blog);
     _db.SaveChanges();
 }