コード例 #1
0
        public void SetUp()
        {
            ForumId = Guid.Empty;
            Result = null;
            Controller = null;
            Topic = null;
            Forums = null;
            Forum = null;
            TopicRepository = null;
            ForumRepository = null;

            _input = null;
        }
コード例 #2
0
        public ActionResult Create(PostInput input)
        {
            if (ModelState.IsValid)
            {
                var post = new InputToPostMapper(_postRepository, _topicRepository).Map(input);

                _postRepository.Save(post);

                TempData["Message"] = string.Format("Post {0} created successfully", post.Id);

                return RedirectToAction("Details", new {post.Id});
            }

            TempData["Message"] = "Failed to create post";

            return RedirectToAction("Create", new {input.TopicId});
        }
コード例 #3
0
        private void _InputFor_Post_Parent([BooleanParameterFormat("valid", "invalid")] bool valid,
            [BooleanParameterFormat("existing", "new")] bool exists, 
            [BooleanParameterFormat("with", "without")] bool belongs)
        {
            if (valid)
            {
                Forum = ForumFixtures.ForumWithNoTopics(1);

                Topic = TopicFixtures.TopicWithNoPostsAndNoAttachments(1);
                Topic.Forum = Forum;

                if (belongs)
                {
                    Parent = PostFixtures.RootPostWithNoChildren(1);
                    Parent.Topic = Topic;

                    Post = PostFixtures.BranchPostWithNoChildren(1);
                    Post.Topic = Topic;
                    Post.Parent = Parent;

                    _input = new PostInput
                    {
                        Body = Post.Body,
                        ParentId = Post.Parent.Id,
                        TopicId = Topic.Id
                    };                    
                }
                else
                {
                    Post = PostFixtures.RootPostWithNoChildren(1);
                    Post.Topic = Topic;

                    _input = new PostInput
                    {
                        Body = Post.Body,
                        ParentId = null,
                        TopicId = Topic.Id
                    };
                }

            }
            else
            {
                _input = new PostInput
                             {
                                 Body = string.Empty,
                                 TopicId = Guid.Empty
                             };

                Controller.ModelState.AddModelError("Title", "Title is required");
                Controller.ModelState.AddModelError("TopicId", "Topic is required");
            }

            if (exists)
            {
                _input.Id = Guid.NewGuid();
            }
        }