Example #1
0
        public async Task RunAsync(IRestContext context)
        {
            /*
             * Get random bytes as hex string from random.org
             */

            const string url = "https://www.random.org/cgi-bin/randbyte?nbytes=16&format=h";
            IHttpRequest request = new HttpRequest(HttpMethod.Get, url, new HttpHeaders());
            IHttpFacade httpFacade = new UnirestHttpFacade();

            Console.WriteLine("Sending GET request: {0}", url);
            IHttpResponse response = await httpFacade.RequestAsync(request);

            Console.WriteLine("Response CODE = {0}, BODY = {1}", response.Code, response.Body.Trim());
        }
        public void ShouldSendGetRequest()
        {
            // Arrange
            const string url = TestAddress + "a/b/c";
            ManualResetEventSlim stopServerEvent = StartWebServer(url, "GET");

            IHttpFacade httpFacade = new UnirestHttpFacade();
            IHttpRequest request = new HttpRequest(HttpMethod.Get, url, new HttpHeaders());

            // Act
            IHttpResponse response = httpFacade.RequestAsync(request).Result;

            // Assert
            response.Code.ShouldBe(200);

            stopServerEvent.Set();
        }
        public void ShouldSendPatchRequest()
        {
            // Arrange
            const string url = TestAddress + "a/b/c";
            ManualResetEventSlim stopServerEvent = StartWebServer(url, "PATCH");

            IHttpFacade httpFacade = new UnirestHttpFacade();
            IHttpRequest request = new HttpRequest(HttpMethod.Patch, url, new HttpHeaders(), "body");

            // Act
            IHttpResponse response = httpFacade.RequestAsync(request).Result;

            // Assert
            response.Code.ShouldBe(200);
            response.Body.ShouldContain("body");

            stopServerEvent.Set();
        }