public HttpResponseMessage GetTopic(int id) { Topic topic; try { if (ModelState.IsValid) { topic = _bltopic.GetTopicDetails(id); if (topic == null) { log.Error("Requested data not found"); return(Request.CreateResponse(HttpStatusCode.NotFound)); } else { return(Request.CreateResponse(HttpStatusCode.OK, topic)); } } 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 TopicGetDetails() { validation.GetTopicDetails(topicList[0].TopicID).Returns(topicList[0]); topicController.Request = new HttpRequestMessage(); topicController.Configuration = new HttpConfiguration(); var actionResult = topicController.GetTopic(topicList[0].TopicID); Assert.AreEqual(HttpStatusCode.OK, actionResult.StatusCode); }