public HttpResponseMessage PostTopic(Topic topic) { List <TopicAdmin> topics = null; int result = 0; try { if (ModelState.IsValid) { topics = _bltopic.CreateTopic(topic); if (topics != null) { return(Request.CreateResponse(HttpStatusCode.Created, topics)); } else { log.Error("Topic failed to create"); return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } } else { log.Error("Invalid model state encountered."); return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { log.Error(ex); return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } }
public void IsTopicAdded() { validation.CreateTopic(topicList[0]).Returns(topicListAdmin); topicController.Request = new HttpRequestMessage(); topicController.Configuration = new HttpConfiguration(); var actionResult = topicController.PostTopic(topicList[0]); Assert.AreEqual(HttpStatusCode.Created, actionResult.StatusCode); }