Ejemplo n.º 1
0
        public void Patch()
        {
            HttpWebServer aHttpListener = new HttpWebServer("http://127.0.0.1:8094/");

            try
            {
                object aLock            = new object();
                string aReceivedRequest = null;

                aHttpListener.StartListening(x =>
                {
                    if (x.Request.HttpMethod == "PATCH")
                    {
                        lock (aLock)
                        {
                            aReceivedRequest = x.GetRequestMessageStr();
                        }

                        x.SendResponseMessage("blabla");
                    }
                    else
                    {
                        x.Response.StatusCode = 404;
                    }
                });

                HttpWebResponse aWebResponse = HttpWebClient.Patch(new Uri("http://127.0.0.1:8094/hello/"), "abcd");
                Assert.AreEqual(HttpStatusCode.OK, aWebResponse.StatusCode);

                string aResponseMessage = aWebResponse.GetResponseMessageStr();

                Assert.AreEqual("abcd", aReceivedRequest);
                Assert.AreEqual("blabla", aResponseMessage);
            }
            finally
            {
                aHttpListener.StopListening();
            }
        }