Exemple #1
0
        public void FindBlogPosts()
        {
            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(blog);

            Assert.AreEqual(2, posts.Count);
        }
Exemple #2
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);
        }
Exemple #3
0
        private void saveButton_Click(object sender, System.EventArgs e)
        {
            if (SelectedBlog != null)
            {
                if (titleBox.Text.Trim().Length == 0)
                {
                    MessageBox.Show("At least you must fill the title for your post.",
                                    "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (SelectedPost == null)
                {
                    _postDao.Create(new Post(SelectedBlog, titleBox.Text, contentsBox.Text));
                }
                else
                {
                    SelectedPost.Title    = titleBox.Text;
                    SelectedPost.Contents = contentsBox.Text;

                    _postDao.Update(SelectedPost);
                }

                RefreshView();
            }
        }
Exemple #4
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);
     }
 }