Reverted accidental checkin
[castle.git] / Samples / MindDump / Castle.Applications.MindDump.Tests / PostTestCase.cs
blobb81de2942191be27543816eedea79d3508d013c9
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Applications.MindDump.Tests
17 using System;
18 using System.Collections;
20 using Castle.Applications.MindDump.Dao;
21 using Castle.Applications.MindDump.Model;
23 using NUnit.Framework;
26 [TestFixture]
27 public class PostTestCase : BaseMindDumpTestCase
29 [Test]
30 public void Create()
32 ResetDatabase();
34 AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
35 BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];
36 PostDao postDao = (PostDao) Container[ typeof(PostDao) ];
38 Author author = new Author("hamilton verissimo", "hammett", "mypass");
39 Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);
41 Post post = new Post("My first entry", "This is my first entry", DateTime.Now);
42 post.Blog = blog;
44 authorDao.Create( author );
45 blogDao.Create( blog );
46 postDao.Create( post );
48 IList posts = postDao.Find();
49 Assert.AreEqual( 1, posts.Count );
51 Post comparisson = (Post) posts[0];
52 Assert.AreEqual( post.Title, comparisson.Title );
53 Assert.AreEqual( post.Contents, comparisson.Contents );
56 [Test]
57 public void FindAll()
59 ResetDatabase();
61 AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
62 BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];
64 Author author = new Author("hamilton verissimo", "hammett", "mypass");
65 Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);
67 authorDao.Create( author );
68 blogDao.Create( blog );
70 Post post1 = new Post("My first entry", "This is my first entry", DateTime.Now);
71 post1.Blog = blog;
72 Post post2 = new Post("My second entry", "This is my second entry", DateTime.Now);
73 post2.Blog = blog;
75 PostDao postDao = (PostDao) Container[ typeof(PostDao) ];
76 postDao.Create(post1);
77 postDao.Create(post2);
79 IList posts = postDao.Find();
80 Assert.AreEqual( 2, posts.Count );
83 [Test]
84 public void FindBlogPosts()
86 ResetDatabase();
88 AuthorDao authorDao = (AuthorDao) Container[ typeof(AuthorDao) ];
89 BlogDao blogDao = (BlogDao) Container[ typeof(BlogDao) ];
91 Author author = new Author("hamilton verissimo", "hammett", "mypass");
92 Blog blog = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);
94 authorDao.Create( author );
95 blogDao.Create( blog );
97 Post post1 = new Post("My first entry", "This is my first entry", DateTime.Now);
98 post1.Blog = blog;
99 Post post2 = new Post("My second entry", "This is my second entry", DateTime.Now);
100 post2.Blog = blog;
102 PostDao postDao = (PostDao) Container[ typeof(PostDao) ];
103 postDao.Create(post1);
104 postDao.Create(post2);
106 IList posts = postDao.Find(blog);
107 Assert.AreEqual( 2, posts.Count );