NOODB: The Walkthrough

This unit test demonstrates the current functionality of NOODB:

        public void Walkthrough()
                // register some types.
                // they should auto register, bu that's currently broken.
                IClient client = new Client(new Server(TestUtility.DefaultUnityContainer));
                client.SetObjectRule<Author>("SaveWhenNested", "0");
                client.SetObjectRule<Movie>("SaveWhenNested", "0");

                // create some authors
                // the key is Author.Name.
                // note the typo in the second one.
                // authors are ICloneable, so make sure we end up with 3 of those too
                client.Save(new Author { Name = "Jay", Title = "Some Random Guy" });
                client.Save(new Author { Name = "Gene", Title = "World Fzzamous" });
                client.Save(new Author { Name = "Roger", Title = "Guy from tv" });
                Assert.AreEqual(3, client.GetObjects<Author>().Count);
                Assert.AreEqual(3, client.GetObjects<ICloneable>().Count);

                // fix the typo. there will be 3 authors.
                client.Save(new Author { Name = "Gene", Title = "World Famous" });
                Assert.AreEqual(3, client.GetObjects<Author>().Count);

                // we can't query yet, so let's just get them all and validate
                Collection<Author> authors = client.GetObjects<Author>();
                Assert.AreEqual("World Famous", (from author in authors where author.Name == "Gene" select author.Title).Single());

                // create 4 movies
                // the key is Movie.Name
                client.Save(new Movie { Name = "Die Hard", Director = "John McTiernan" });
                client.Save(new Movie { Name = "Die Hard 2: Die Harder", Director = "Renny Harlin" });
                client.Save(new Movie { Name = "Die Hard With a Vengeance", Director = "John McTiernan" });
                client.Save(new Movie { Name = "Live Free or Die Hard", Director = "Len Wiseman" });
                Assert.AreEqual(4, client.GetObjects<Movie>().Count);

                // let's create a review.
                    new MovieReview
                        // These are defined in "MovieReview".
                        // the key is name, so that's all we need to specify. (anything else will be ignored due to SaveIfNested=0)
                        Movie = new Movie { Name = "Die Hard" },

                        // these are defined "Review", which is the base class of "MovieReview".
                        // the key is Id.
                        Author = new Author { Name = "Jay" },
                        Rating = 5,
                        Comments = "80's action classic!",
                        Id = Guid.NewGuid()

                // the author and movie count haven't changed
                Assert.AreEqual(3, client.GetObjects<Author>().Count);
                Assert.AreEqual(4, client.GetObjects<Movie>().Count);

                // there is 1 MovieReview. Since a MovieReview is also a Review, there is also 1 review.
                Assert.AreEqual(1, client.GetObjects<MovieReview>().Count);
                Assert.AreEqual(1, client.GetObjects<Review>().Count);

                // now let's add a book review
                    new BookReview
                        // these are defined in "BookReview". There should be a book object, but not yet.
                        BookTitle = "Wednesdays With Morrie's Paperboy",
                        ISBN = "ISBN",
                        // these are defined in "Review" which is the base class of "BookReview".
                        // the key is Id.
                        Comments = "like a movie, but with more reading",
                        // title is temporary
                        Author = new Author { Name = "Gene" },
                        Rating = 3,
                        Id = Guid.NewGuid()

                // 1 movie, 1 book
                // BookReview implements an interface called IBookReview, so there should be one of those too
                Assert.AreEqual(2, client.GetObjects<Review>().Count);
                Assert.AreEqual(1, client.GetObjects<BookReview>().Count);
                Assert.AreEqual(1, client.GetObjects<MovieReview>().Count);
                Assert.AreEqual(1, client.GetObjects<IBookReview>().Count);


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: