Example #1
0
		public async Task Can_Handle_Uncompressed_Content()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => Handlers.EchoValue(request.Path) ))
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("uncompressed.json.txt");
				var response = await client.ExecuteAsync(request);

                Assert.AreEqual("This is some sample content", response.Content);
			}
		}
Example #2
0
        public async Task Handles_GET_Request_404_Error()
        {
            const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => UrlToStatusCodeHandler(request.Path) ))
            {
                var client = new RestClient(baseUrl);
                var request = new RestRequest("404");
                var response = await client.ExecuteAsync(request);

                Assert.AreEqual((int)HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Example #3
0
		public async Task Can_Handle_Deflate_Compressed_Content()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => DeflateEchoValue(request.Path)))
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("deflate.json.txt");
				var response = await client.ExecuteAsync(request);

                System.Diagnostics.Debug.WriteLine("CONTENT: " + response.Content);

                Assert.AreEqual("This is some deflated content", response.Content);
			}
		}
Example #4
0
		public async Task Can_Authenticate_With_Basic_Http_Auth()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => UsernamePasswordEchoHandler(request) ))
			{
				var client = new RestClient(baseUrl);
				client.Authenticator = new HttpBasicAuthenticator("testuser", "testpassword");

				var request = new RestRequest("basicAuth.json.txt");
				var response = await client.ExecuteAsync(request);

				Assert.AreEqual("testuser|testpassword", response.Content);
			}
		}
Example #5
0
		public async Task Can_Perform_GET_Async()
		{
			const string baseUrl = "http://localhost:8080/";
			const string val = "Basic async test";
			var resetEvent = new ManualResetEvent(false);
			//using (SimpleServer.Create(baseUrl, Handlers.EchoValue(val)))
            using (HttpServer server = new HttpServer(8080, request => Handlers.EchoValue(request.Path)))
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("");

                var response = await client.ExecuteAsync(request);
                
                Assert.IsNotNull(response.Content);
                Assert.AreEqual(val, response.Content);
			}
		}
Example #6
0
		public async Task Handles_Binary_File_Download()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080))
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("Koala.jpg");

                var response = await client.DownloadDataAsync(request);

                // Look in the Data subdirectory of the app package
                string filePath = "Data\\Koala.jpg";
                StorageFolder LocalFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

                var file = await LocalFolder.GetFileAsync(filePath);
                Stream s = await file.OpenStreamForReadAsync();
                byte[] expected = new byte[s.Length];
                await s.ReadAsync(expected, 0, expected.Length);

                var actual = response.Cast<byte>().ToArray();
                Assert.IsTrue(actual.SequenceEqual(expected));
			}
		}
Example #7
0
        public async Task Handles_Default_Root_Element_On_No_Error()
		{
			const string baseUrl = "http://localhost:8080/";
            using (HttpServer server = new HttpServer(8080, request => ResponseHandler(request.Path)) )
			{
				var client = new RestClient(baseUrl);
				var request = new RestRequest("success.json.txt");

                var response = await client.ExecuteAsync(request);

                var deserializer = new RestRT.Deserializers.JsonDeserializer();
                deserializer.RootElement = "Success";

                if (response.StatusCode == (int)HttpStatusCode.NotFound)
                {
                    deserializer.RootElement = "Error";
                }
                var result = (Response)deserializer.Deserialize(response, typeof(Response));

                Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode);
                Assert.AreEqual("Works!", result.Message);
			}
		}