コード例 #1
0
        public ActionResult CreatePost(Post post)
        {
            var manager = new AdminManager();
            var postCount = manager.GetAllPosts().Count;
            post.PostCategory.CategoryName = manager.GetCategoryByID(post.PostCategory.CategoryID).CategoryName;

            post.PostDate = DateTime.Now;
            post.Status = ApprovalStatus.Pending;
            if (postCount == 0)
            {
                post.PostID = 1;
            }
            else
                post.PostID = manager.GetAllPosts().Count + 1;
            manager.AddPost(post);
            return RedirectToAction("SubordinateIndex", "Subordinate");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: alexgrbach/Projects
        public void CanAddPost()
        {
            var manager = new AdminManager();
            var postCount = manager.GetAllPosts().Count;

            var toAdd = new Post();
            toAdd.PostCategory = new Category();

            toAdd.PostID = postCount + 1;
            toAdd.PostTitle = "Test Title";
            toAdd.PostBody = "Post body";
            toAdd.PostCategory.CategoryID = 1;
            toAdd.Status = ApprovalStatus.Approved;
            toAdd.PostDate = DateTime.Now;
            toAdd.PostTags = new List<Tag>();
            toAdd.User = new User();

            manager.AddPost(toAdd);

            var manager2 = new AdminManager();
            var postCount2 = manager2.GetAllPosts().Count;

            Assert.AreEqual(postCount + 1, postCount2);
        }