Exemplo n.º 1
0
        public void CreateErrorResponse()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");

            request.SetConfiguration(new HttpConfiguration());
            var response = new APIResponseMessage(request);

            response.Links = new List <LinkModel>();
            string errorMessage = "Error message";
            var    message      = response.CreateErrorResponse(HttpStatusCode.Conflict, "", errorMessage);
            var    data         = ((APICommon.APIResponse)(((System.Net.Http.ObjectContent)(message.Content)).Value)).Data;

            Assert.AreEqual(data.ErrorMessage, errorMessage);
        }
Exemplo n.º 2
0
 // GET: api/Intructors
 public HttpResponseMessage Get()
 {
     try
     {
         apiResponse.Request = Request;
         var instructors = _controller.Get(_organization);
         if (instructors != null)
         {
             apiResponse.Links = Helper.SetLinks(Url, ROUTENAME, "Instructors?organzation", "Get");
             return(apiResponse.CreateResponse(HttpStatusCode.OK, instructors));
         }
         else
         {
             return(apiResponse.CreateErrorResponse(HttpStatusCode.BadRequest, "", "No instructors found"));
         }
     }
     catch (Exception ex)
     {
         // log your exception
         return(apiResponse.CreateErrorResponse(HttpStatusCode.InternalServerError, "", "An exception has occurred"));
     }
 }
Exemplo n.º 3
0
 // GET: api/Classes
 public HttpResponseMessage Get()
 {
     try
     {
         apiResponse.Request = Request;
         var classes = _controller.Get(_organization);
         if (classes != null)
         {
             apiResponse.Links = Helper.SetLinks(Url, ROUTENAME, "Classes", "Get");
             return(apiResponse.CreateResponse(HttpStatusCode.OK, classes));
         }
         else
         {
             return(apiResponse.CreateErrorResponse(HttpStatusCode.OK, "", "No classes found"));
         }
     }
     catch (Exception ex)
     {
         // log your exception
         return(apiResponse.CreateErrorResponse(HttpStatusCode.Conflict, "", "An exception has occurred"));
     }
 }