Esempio n. 1
0
		public void Update(Blog blog)
		{
			using(ISession session = sessionManager.OpenSession())
			{
				session.Update(blog);
			}
		}
		public void CreateNewPostAndObtainPosts()
		{
			ResetDatabase();

			AccountService account = (AccountService) 
				Container[ typeof(AccountService) ];
			BlogService maintenance = (BlogService) 
				Container[ typeof(BlogService) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);

			account.CreateAccountAndBlog(blog);
			
			Post post = maintenance.CreateNewPost( 
				blog, new Post("title", "contents", DateTime.Now) );

			Post comparisson = maintenance.ObtainPost( blog, post.Id );
			Assert.AreEqual( post.Id, comparisson.Id );
			Assert.AreEqual( post.Title, comparisson.Title );
			Assert.AreEqual( post.Contents, comparisson.Contents );

			IList posts = maintenance.ObtainPosts(blog);
			Assert.AreEqual( 1, posts.Count );
		}
		public Post ObtainPost( Blog blog, long postId )
		{
			try
			{
				Post post = _postDao.Find(postId);

				if (post != null)
				{
					if (post.Blog.Id != blog.Id)
					{
						throw new ApplicationException("The post requested belongs " + 
							"to a different blog");
					}
				}

				return post;
			}
			catch(ApplicationException ex)
			{
				throw ex;
			}
			catch(Exception ex)
			{
				throw new ApplicationException("Could not find post", ex);
			}
		}
Esempio n. 4
0
		public void Create()
		{
			ResetDatabase();

			AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
			BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];
			PostDao postDao = (PostDao) Container[ typeof(PostDao) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);
			
			Post post = new Post("My first entry", "This is my first entry", DateTime.Now);
			post.Blog = blog;

			authorDao.Create( author );
			blogDao.Create( blog );
			postDao.Create( post );

			IList posts = postDao.Find();
			Assert.AreEqual( 1, posts.Count );

			Post comparisson = (Post) posts[0];
			Assert.AreEqual( post.Title, comparisson.Title );
			Assert.AreEqual( post.Contents, comparisson.Contents );
		}
Esempio n. 5
0
		public void FindAll()
		{
			ResetDatabase();

			AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
			BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);

			authorDao.Create( author );
			blogDao.Create( blog );

			Post post1 = new Post("My first entry", "This is my first entry", DateTime.Now);
			post1.Blog = blog;
			Post post2 = new Post("My second entry", "This is my second entry", DateTime.Now);
			post2.Blog = blog;

			PostDao postDao = (PostDao) Container[ typeof(PostDao) ];
			postDao.Create(post1);
			postDao.Create(post2);

			IList posts = postDao.Find();
			Assert.AreEqual( 2, posts.Count );
		}
Esempio n. 6
0
		public virtual void CreateAccountAndBlog( Blog blog )
		{
			_authorDao.Create( blog.Author );
			_blogDao.Create( blog );

			if (EventPublisher != null) EventPublisher.NotifyBlogAdded( blog );
		}
Esempio n. 7
0
		public IList Find(Blog blog)
		{
			using(ISession session = sessionManager.OpenSession())
			{
				IList list = session.Find(
					"from Post as a where a.Blog.Id=:name", blog.Id, NHibernateUtil.Int64);

				return list;
			}
		}
Esempio n. 8
0
		public Post CreateNewPost(Blog blog, Post post)
		{
			try
			{
				post.Blog = blog;
				return _postDao.Create(post);
			}
			catch(Exception ex)
			{
				throw new ApplicationException("Could not create post", ex);
			}
		}
Esempio n. 9
0
		public Blog Create(Blog blog)
		{
			using(ISession session = sessionManager.OpenSession())
			{
				if (blog.Posts == null)
				{
					blog.Posts = new ArrayList();
				}

				session.Save(blog);
			}

			return blog;
		}
Esempio n. 10
0
		public void UpdatePost(Blog blog, long postId, Post post)
		{
			try
			{
				Post originalPost = ObtainPost(blog, postId);

				originalPost.Title = post.Title;
				originalPost.Contents = post.Contents;
			
				_postDao.Update(originalPost);
			}
			catch(Exception ex)
			{
				throw new ApplicationException("Could not update post", ex);
			}
		}
Esempio n. 11
0
		public void CreateAuthorAndBlog()
		{
			ResetDatabase();

			AccountService service = (AccountService) Container[ typeof(AccountService) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog = new Blog("hammett's blog", "Description", "default", author);

			service.CreateAccountAndBlog( blog );

			AuthorDao dao = (AuthorDao) Container[ typeof(AuthorDao) ];
			Assert.AreEqual( 1, dao.Find().Count );
			BlogDao blogdao = (BlogDao) Container[ typeof(BlogDao) ];
			Assert.AreEqual( 1, blogdao.Find().Count );
		}
Esempio n. 12
0
		public void FindAll()
		{
			ResetDatabase();

			AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
			BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog1 = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);
			Blog blog2 = new Blog("hammett's personal blog", "more thoughts.. ugh!", "default", author);

			authorDao.Create( author );
			blogDao.Create( blog1 );
			blogDao.Create( blog2 );

			IList blogs = blogDao.Find();
			Assert.AreEqual( 2, blogs.Count );
		}
Esempio n. 13
0
		public void CreateAccount(String login, String name, String email,
		                      String pwd, String pwd2, String blogname,
		                      String blogdesc, String theme)
		{
			// Perform some simple validation
			if (!IsValid(login, name, email, pwd, pwd2, blogname, blogdesc, theme))
			{
				RenderView("new");
				return;
			}
 
			Author author = new Author(name, login, pwd);
			Blog blog = new Blog(blogname, blogdesc, theme, author);

			_accountService.CreateAccountAndBlog( blog );

			// Done, now lets log on into the system
			PerformLogin(login, pwd);
		}
Esempio n. 14
0
		public void Create()
		{
			ResetDatabase();

			AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
			BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];

			Author author = new Author("hamilton verissimo", "hammett", "mypass");
			Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);

			authorDao.Create( author );
			blogDao.Create( blog );

			IList blogs = blogDao.Find();
			Assert.AreEqual( 1, blogs.Count );

			Blog comparisson = (Blog) blogs[0];
			Assert.AreEqual( blog.Name, comparisson.Name );
			Assert.AreEqual( blog.Description, comparisson.Description );
			Assert.AreEqual( blog.Theme, comparisson.Theme );
		}
Esempio n. 15
0
		public IList ObtainPosts(Blog blog)
		{
			return _postDao.Find(blog);
		}
		public void OnBlogAdded(Blog blog)
		{
			_controllerTree.AddController(String.Empty, blog.Author.Login, "blogs.controller");
		}
Esempio n. 17
0
		public virtual void UpdateBlog( Blog blog )
		{
			_blogDao.Update( blog );
		}
		public void OnBlogRemoved(Blog blog)
		{
		}