Exemplo n.º 1
0
        public void TestCreateNewThread()
        {
            //Arrange
            var    controller = new MainPageControllerTest();
            string content    = "Test Content TESTING!!!!";
            Syear  inst       = new Syear
            {
                SyearId = 1
            };
            User cur = new User
            {
                UserName = "******",
                Password = "******"
            };
            Thread test_Thread = new Thread
            {
                ThreadName = testingThreadHeader,
                SyearId    = 1,
                ThreadType = "[Question]",
                OwnerId    = 1
            };

            //Act
            controller.CreateNewThread(inst, test_Thread, cur, content);

            //Assert
            using (ContentDal cnt = new ContentDal())
            {
                List <Content> cont =
                    (from x in cnt.Contents
                     where x.threadName == test_Thread.ThreadName
                     select x).ToList();
                Assert.AreEqual(content, cont[0].threadContent);

                //Cleanup
                cnt.Contents.Remove(cont[0]);
                cnt.SaveChanges();
            }

            //Cleanup Remove testing Thread
            //Add test thread to DB
            using (ThreadDal trdDal = new ThreadDal())
            {
                var result = trdDal.Threads.SingleOrDefault(b => b.ThreadName == test_Thread.ThreadName);
                trdDal.Threads.Remove(result);
                trdDal.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void TestNewComment()
        {
            //Arragne
            var    controller = new MainPageControllerTest();
            string content    = "Test Content TESTING!!!!";
            Syear  inst       = new Syear
            {
                SyearId = 1
            };
            User cur = new User
            {
                UserName = "******",
                Password = "******"
            };
            Thread test_Thread = new Thread
            {
                ThreadName = testingThreadHeader,
                SyearId    = 1,
                ThreadType = "[Question]",
                OwnerId    = 1
            };

            ThreadDal tDal = new ThreadDal();

            tDal.Threads.Add(test_Thread); // Add test thread
            tDal.SaveChanges();

            Thread currenthread = tDal.Threads.SingleOrDefault(b => b.ThreadName == testingThreadHeader);

            Content testContent = new Content()
            {
                threadContent = content,
                threadId      = currenthread.ThreadId
            };
            ContentDal cDal = new ContentDal();

            cDal.Contents.Add(testContent);
            cDal.SaveChanges();

            //Act
            controller.addComment(testContent, cur, "TestComment");

            //Assert
            CommentDal comDal = new CommentDal();

            List <Comment> com =
                (from x in comDal.Comments
                 where x.threadId == currenthread.ThreadId
                 select x).ToList();

            Comment ans = com.Find(b => b.commentContent == "TestComment");

            Assert.IsNotNull(ans);

            //CleanUp
            tDal.Threads.Remove(currenthread);
            tDal.SaveChanges();

            cDal.Contents.Remove(testContent);
            cDal.SaveChanges();

            comDal.Comments.Remove(ans);
            comDal.SaveChanges();
        }