Exemple #1
0
 public void CreateResponse_NullRequest()
 {
     System.Web.HttpContext.Current = new HttpContext(new HttpRequest("blank", "http://localhost", "blank"),
                                                      new HttpResponse(new System.IO.StringWriter()));
     var request  = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
     var response = new APIResponseMessage();
     var message  = response.CreateResponse(System.Net.HttpStatusCode.OK, null);
 }
 // 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"));
     }
 }
Exemple #3
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"));
     }
 }
Exemple #4
0
        public void CreateResponse()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");

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

            response.Links = new List <LinkModel>();
            var message = response.CreateResponse(HttpStatusCode.OK, null);

            Assert.AreEqual(message.StatusCode, HttpStatusCode.OK);

            var testObject = new TestObject()
            {
                TestId   = 1,
                TestData = "asdf",
            };

            message = response.CreateResponse(HttpStatusCode.OK, testObject);
            var data = ((APICommon.APIResponse)(((System.Net.Http.ObjectContent)(message.Content)).Value)).Data;

            Assert.AreEqual(data.ReturnModel, testObject);
        }