public void SetUp() { ForumId = Guid.Empty; Result = null; Controller = null; Topic = null; Forums = null; Forum = null; TopicRepository = null; ForumRepository = null; _input = null; }
public ActionResult Create(TopicInput input) { if (ModelState.IsValid) { var topic = new InputToTopicMapper(_topicRepository, _forumRepository).Map(input); _topicRepository.Save(topic); TempData["Message"] = string.Format("Topic {0} created successfully", topic.Title); return RedirectToAction("Details", new {topic.Id}); } TempData["Message"] = "Failed to create topic"; return RedirectToAction("Create", new {input.ForumId}); }
private void _InputFor_Topic([BooleanParameterFormat("valid", "invalid")] bool valid, [BooleanParameterFormat("existing", "new")] bool exists) { if (valid) { Forum = ForumFixtures.ForumWithNoTopics(1); Topic = TopicFixtures.TopicWithNoPostsAndNoAttachments(1); Topic.Forum = Forum; _input = new TopicInput { Title = Topic.Title, Body = Topic.Body, Closed = false, Sticky = true, ForumId = Forum.Id, Forums = new SelectList(ForumRepository.All().ToArray(), "Id", "Name") }; } else { _input = new TopicInput { Title = string.Empty, Body = string.Empty, ForumId = Guid.Empty }; Controller.ModelState.AddModelError("Title", "Title is required"); Controller.ModelState.AddModelError("Body", "Body is required"); Controller.ModelState.AddModelError("ForumId", "Forum is required"); } if (exists) { _input.Id = Guid.NewGuid(); } }