Example #1
0
        public void EditPost()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var PostLogic = new PostLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new UserDTO("Liza", UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");
            PostLogic.Add(new PostDTO("Title", "Content", "Tag", "CategoryName"));

            var Post = PostLogic.GetAll().ToList()[0];

            Assert.AreEqual(PostLogic.GetAll().Count(), 1);
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Title, "Title");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Content, "Content");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Tags, "Tag");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].CategoryName, "CategoryName");

            Post.Title        = "Programming";
            Post.CategoryName = "C#";

            PostLogic.EditPost(Post.Id, Post);

            Post = PostLogic.GetAll().ToList()[0];

            Assert.AreEqual(PostLogic.GetAll().Count(), 1);
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Title, "Programming");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Content, "Content");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Tags, "Tag");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].CategoryName, "C#");
        }
Example #2
0
        public void SearchByTag()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var PostLogic = new PostLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new UserDTO("Liza", UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");
            PostLogic.Add(new PostDTO("Title", "Content", "Tag", "CategoryName"));
            PostLogic.Add(new PostDTO("Title1", "Content1", "Tag1", "CategoryName1"));
            PostLogic.Add(new PostDTO("Title2", "Content2", "Tag2", "CategoryName2"));
            PostLogic.Add(new PostDTO("Title3", "Content3", "Tag3", "CategoryName3"));
            PostLogic.Add(new PostDTO("Title4", "Content4", "Tag4", "CategoryName4"));

            Assert.IsTrue(PostLogic.GetAll().Count() == 5);

            Assert.AreEqual(PostLogic.SearchByTag("Tag1").ToList()[0].Tags, "Tag1");
            Assert.AreEqual(PostLogic.SearchByTag("Tag4").ToList()[0].Tags, "Tag4");
        }
Example #3
0
        public void FindByCategory()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var PostLogic = new PostLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new UserDTO("Liza", UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");
            PostLogic.Add(new PostDTO("Title", "Content", "Tag", "C#"));
            PostLogic.Add(new PostDTO("Title1", "Content1", "Tag1", "C++"));
            PostLogic.Add(new PostDTO("Title2", "Content2", "Tag2", "Java"));
            PostLogic.Add(new PostDTO("Title3", "Content3", "Tag3", "Python"));
            PostLogic.Add(new PostDTO("Title4", "Content4", "Tag4", "JS"));

            Assert.IsTrue(PostLogic.GetAll().Count() == 5);

            Assert.AreEqual(PostLogic.FindByCategory("C#").ToList()[0].CategoryName, "C#");
            Assert.AreEqual(PostLogic.FindByCategory("C++").ToList()[0].CategoryName, "C++");
            Assert.AreEqual(PostLogic.FindByCategory("JS").ToList()[0].CategoryName, "JS");
            Assert.AreEqual(PostLogic.FindByCategory("Java").ToList()[0].CategoryName, "Java");
        }
Example #4
0
        public void AddCommentToPost()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var PostLogic = new PostLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new UserDTO("Liza", UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");
            PostLogic.Add(new PostDTO("Title", "Content", "Tag", "CategoryName"));
            PostLogic.AddComment(PostLogic.GetAll().ToList()[0].Id, new CommentsDTO("Great Post", 0, true));

            Assert.AreEqual(UoW.Object.Comments.GetAll().Count(), 1);
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Comments[0].Comment_Content, "Great Post");
            Assert.IsTrue(PostLogic.GetAll().ToList()[0].Comments[0].Publish == true);
            Assert.IsTrue(PostLogic.GetAll().ToList()[0].Comments[0].Post.Id == PostLogic.GetAll().ToList()[0].Id);
        }
Example #5
0
        public void DeletePost()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var PostLogic = new PostLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new UserDTO("Liza", UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");
            PostLogic.Add(new PostDTO("Title", "Content", "Tag", "CategoryName"));

            Assert.AreEqual(PostLogic.GetAll().Count(), 1);
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Title, "Title");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Content, "Content");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Tags, "Tag");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].CategoryName, "CategoryName");

            PostLogic.DeletePost(1);

            Assert.IsTrue(PostLogic.GetAll().Count() == 0);
            Assert.IsTrue(UoW.Object.Post.GetAll().Count == 0);
        }