Esempio n. 1
0
        public void TestExceptionFree1()
        {
            AddTestData();

            string[] errors         = null;
            string   exceptionTrace = null;

            posts       _posts       = null;
            tags        _tags        = null;
            poststotags _poststotags = null;

            //add post
            _posts                = new posts();
            _posts.posts_title    = "Post1";
            _posts.posts_text     = "test text 1";
            _posts.posts_username = "******";
            _posts.posts_email    = "*****@*****.**";

            Assert.IsFalse(samplemodel.Posts.Add(ref errors, ref exceptionTrace, _posts));
            Assert.That(errors.Length, Is.EqualTo(0));
            Assert.IsTrue(!String.IsNullOrEmpty(exceptionTrace));

            _posts.blogs_id = samplemodel.Blogs.FirstOrDefault(a => a.blogs_title == "Blog1").blogs_id;
            Assert.IsTrue(samplemodel.Posts.Add(ref errors, ref exceptionTrace, _posts));
            Assert.That(errors.Length, Is.EqualTo(0));
            Assert.IsTrue(String.IsNullOrEmpty(exceptionTrace));

            //add tags
            _tags           = new tags();
            _tags.tags_name = "Tag1";
            samplemodel.Tags.Add(_tags);

            _tags           = new tags();
            _tags.tags_name = "Tag2";
            samplemodel.Tags.Add(_tags);

            //edit post1
            _posts          = samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1");
            _posts.blogs_id = -1;
            Assert.IsFalse(samplemodel.Posts.Update(ref errors, ref exceptionTrace, _posts));
            Assert.That(errors.Length, Is.EqualTo(0));
            Assert.IsTrue(!String.IsNullOrEmpty(exceptionTrace));

            _posts.blogs_id = samplemodel.Blogs.FirstOrDefault(a => a.blogs_title == "Blog1").blogs_id;
            Assert.IsTrue(samplemodel.Posts.Update(ref errors, ref exceptionTrace, _posts));
            Assert.That(errors.Length, Is.EqualTo(0));
            Assert.IsTrue(String.IsNullOrEmpty(exceptionTrace));

            //add poststotags
            _poststotags                      = new poststotags();
            _poststotags.posts_id             = samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_id;
            _poststotags.poststotags_comments = "123x";
            Assert.IsFalse(samplemodel.PostsToTags.Add(ref errors, ref exceptionTrace, _poststotags));
            Assert.That(errors.Length, Is.AtLeast(1));
            Assert.IsTrue(String.IsNullOrEmpty(exceptionTrace));

            _poststotags.tags_id = samplemodel.Tags.FirstOrDefault(a => a.tags_name == "Tag1").tags_id;
            Assert.IsTrue(samplemodel.PostsToTags.Add(ref errors, ref exceptionTrace, _poststotags));
            Assert.That(errors.Length, Is.EqualTo(0));
            Assert.IsTrue(String.IsNullOrEmpty(exceptionTrace));

            //edit poststotags
            _poststotags         = samplemodel.PostsToTags.FirstOrDefault(a => a.poststotags_comments == "123x");
            _poststotags.tags_id = -1;
            Assert.IsFalse(samplemodel.PostsToTags.Update(ref errors, ref exceptionTrace, _poststotags));
            Assert.That(errors.Length, Is.AtLeast(1));
            Assert.IsTrue(String.IsNullOrEmpty(exceptionTrace));

            _poststotags.tags_id = samplemodel.Tags.FirstOrDefault(a => a.tags_name == "Tag1").tags_id;
            Assert.IsTrue(samplemodel.PostsToTags.Update(ref errors, ref exceptionTrace, _poststotags));
            Assert.That(errors.Length, Is.EqualTo(0));
            Assert.IsTrue(String.IsNullOrEmpty(exceptionTrace));
        }
Esempio n. 2
0
        public void Test1()
        {
            AddTestData();

            posts       _posts       = null;
            comments    _comments    = null;
            tags        _tags        = null;
            poststotags _poststotags = null;

            //add post
            _posts = new posts();
            Assert.IsFalse(samplemodel.Posts.CanAdd(_posts));

            _posts.blogs_id       = samplemodel.Blogs.FirstOrDefault(a => a.blogs_title == "Blog1").blogs_id;
            _posts.posts_title    = "Post1";
            _posts.posts_text     = "test text 1";
            _posts.posts_username = "******";
            _posts.posts_email    = "*****@*****.**";

            _posts.posts_title = "Post1<"; //invalid title
            Assert.IsFalse(samplemodel.Posts.CanAdd(_posts));

            _posts.posts_title = "Post1";
            Assert.IsTrue(samplemodel.Posts.CanAdd(_posts));
            samplemodel.Posts.Add(_posts);

            Assert.That(samplemodel.Posts.Count(), Is.EqualTo(1));

            //edit post1
            _posts                = samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1");
            _posts.blogs_id       = samplemodel.Blogs.FirstOrDefault(a => a.blogs_title == "Blog1").blogs_id;
            _posts.posts_title    = "Post1";
            _posts.posts_text     = "test text 2";
            _posts.posts_username = "******";
            _posts.posts_email    = "*****@*****.**";
            samplemodel.Posts.Update(_posts);

            Assert.That(samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_text, Is.EqualTo("test text 2"));

            Assert.That(samplemodel.Posts.Find(samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_id).posts_id, Is.EqualTo(samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_id));

            //edit post1
            _posts                = samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1");
            _posts.blogs_id       = samplemodel.Blogs.FirstOrDefault(a => a.blogs_title == "Blog1").blogs_id;
            _posts.posts_title    = "Post1";
            _posts.posts_text     = "test text 3";
            _posts.posts_username = "******";
            _posts.posts_email    = "*****@*****.**";

            Assert.That(samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_text, Is.Not.EqualTo("test text 3"));

            samplemodel.Posts.Update(_posts);

            Assert.That(samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_text, Is.EqualTo("test text 3"));

            //add tags
            _tags           = new tags();
            _tags.tags_name = "Tag1";
            samplemodel.Tags.Add(_tags);

            _tags           = new tags();
            _tags.tags_name = "Tag2";
            samplemodel.Tags.Add(_tags);

            Assert.That(samplemodel.Tags.Count(), Is.EqualTo(2));

            //add poststotags
            _poststotags          = new poststotags();
            _poststotags.posts_id = samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_id;
            _poststotags.tags_id  = samplemodel.Tags.FirstOrDefault(a => a.tags_name == "Tag1").tags_id;
            samplemodel.PostsToTags.Add(_poststotags);

            _poststotags          = new poststotags();
            _poststotags.posts_id = samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_id;
            _poststotags.tags_id  = samplemodel.Tags.FirstOrDefault(a => a.tags_name == "Tag2").tags_id;
            samplemodel.PostsToTags.Add(_poststotags);

            //add comments
            _comments                   = new comments();
            _comments.posts_id          = samplemodel.Posts.FirstOrDefault(a => a.posts_title == "Post1").posts_id;
            _comments.comments_text     = "test text 1";
            _comments.comments_username = "******";
            _comments.comments_email    = "*****@*****.**";
            samplemodel.Comments.Add(_comments);
        }