Beispiel #1
0
 public void TestGetHelloWorld()
 {
     try
     {
         //create a constant that will be used to test the output of the helloworldobject response...
         const String HELLO_WORLD_STRING = "Hello world!";
         //init controller
         HelloWorldController helloWorldController = new HelloWorldController();
         //create mock http request
         helloWorldController.Request       = new HttpRequestMessage();
         helloWorldController.Configuration = new HttpConfiguration();
         //get the response
         HttpResponseMessage response = helloWorldController.getHelloWorld();
         //serialize content value to an output string
         string output = JsonConvert.SerializeObject(response.Content);
         //reconstitute the HelloWorldObject with the output
         HelloWorldObject helloWorldResponse = JsonConvert.DeserializeObject <HelloWorldObject>(output);
         //assert the things
         Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
         Assert.AreEqual(helloWorldResponse.text, HELLO_WORLD_STRING);
         Assert.AreEqual(helloWorldResponse.createdDate, DateTime.Today);
     }
     finally{
         //clean up logic would go here
         System.Diagnostics.Debug.WriteLine("Test executed successfully");
     }
 }
        //public web api method to return the string hello world to the user's device
        // GET api/HelloWorld
        public HttpResponseMessage getHelloWorld()
        {
            //get hello world object
            HelloWorldObject helloWorldObject = engine.getHelloWorldObject();

            //print "Hello world!" to the console
            System.Diagnostics.Debug.WriteLine(helloWorldObject.text);
            //return the object in the http response so that anything that calls this can have it
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, helloWorldObject);

            response.Content = new ObjectContent <HelloWorldObject>(helloWorldObject, new JsonMediaTypeFormatter(), "application/json");
            return(response);
        }
 public static void ExecuteMethod_DeleteObject(HelloWorldObject objectToDelete)
 {
     objectToDelete.DeleteInformationObject();
 }