public void CanSaveAndReadBlog() { var blog = new Blog{Title = "title", Body = "Body"}; blogRepository.Session.Save(blog); reset(); var fromDb=blogRepository.Blogs.Single(b=>b.Id==blog.Id); Assert.AreEqual(blog.Title,fromDb.Title); }
public ActionResult Create(Blog blog) { try { db.Session.Save(blog); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(long id,Blog blog) { try { db.Session.Save(blog); TempData["message"] = blog.Title + " has been saved."; return RedirectToAction("Index"); } catch { return View("Create", blog); } }
public void CanSaveAndReadBlogWithComments() { var blog = new Blog { Title = "title", Body = "Body" }; blog.AddComment(new Comment(){Author = "Marcel",Body="Body"}); blogRepository.Session.Save(blog); reset(); Debug.WriteLine("Before Getting Blog"); var fromDb = blogRepository.Blogs.Single(b=>b.Id==blog.Id); Debug.WriteLine("Before reading Blog property"); Assert.AreEqual("title",fromDb.Title); Debug.WriteLine("Before reading comments"); Assert.AreEqual(1, fromDb.Comments.ToList().Count); }
public void Populate() { var session=this.Session; using(var transaction = session.BeginTransaction()) { for (int i = 0; i < 100; i++) { var blog = new Blog{Body = "Body" + i, Title = "Title" + i}; for (int j = 0; j < 5; j++) { var comment = new Comment {Author = "Fredek" + j, Body = "Comment Body" + j, Blog = blog}; blog.AddComment(comment); } session.Save(blog); } transaction.Commit(); } session.Close(); }