Пример #1
0
        static void Main()
        {
            var client = new JsonHttpClient("http://localhost:8080");


            var responseDto = client.Get((dynamic) new WorksPointGetDto {
                PointId = 3
            });

            Console.WriteLine($"This works and returned a DTO with name = {responseDto.Name}.");


            responseDto = client.Get((dynamic) new WhyDoesThisWorkPointGetDto {
                PointId = 3
            });
            Console.WriteLine($"Why does this work?  It also returned a DTO with name = {responseDto.Name}.");


            // This throws a "Bad Request" exception.
            responseDto = client.Get((dynamic) new WhyDoesThisNotWorkPointGetDto {
                PointId = 3
            });
            Console.WriteLine($"Returned DTO with name {responseDto.Name}.");


            Console.WriteLine("\n\nPress any key to exit.");
            Console.ReadKey();
        }
Пример #2
0
        public void Load_test_GetFactorialSync_HttpClient_sync()
        {
            var client = new JsonHttpClient(Config.ListeningOn);

            for (var i = 0; i < NoOfTimes; i++)
            {
                var response = client.Get(new GetFactorialSync {
                    ForNumber = 3
                });
                if (i % 100 == 0)
                {
                    "{0}: {1}".Print(i, response.Result);
                }
            }
        }
        public void ResponseFilterIShouldHaveVaryFilterTest()
        {
            using (var client = new JsonHttpClient(Config.ListeningOn))
            {
                client.ResponseFilter = message =>
                {
                    var headers = message.Headers.Vary.Join(",");
                    Assert.That(headers, Is.EqualTo("accept,origin,authorization"));
                    Assert.That(message.Headers.CacheControl.ToString(), Is.EqualTo("no-cache"));
                };

                var response = client.Get(new ResponseFilterWithVaryRequest());
                Assert.That(response, Is.EqualTo("Should have vary headers."));
            }
        }
Пример #4
0
        public void Does_handle_304_NotModified_Response_JsonHttpClient()
        {
            var client = new JsonHttpClient(BaseUrl);

            try
            {
                var response = client.Get(new EchoCustomResponse
                {
                    StatusCode        = (int)HttpStatusCode.NotModified,
                    StatusDescription = "NotModified",
                    Body = "NOT MODIFIED"
                });

                Assert.Fail("304 Throws");
            }
            catch (WebServiceException ex)
            {
                Assert.That(ex.ErrorCode, Is.EqualTo("NotModified"));
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            Example    example;
            string     json;
            HttpClient httpClient = new HttpClient()
            {
            };

            //1 Examples - JsonHttpClient<T>
            //1.1
            example = new JsonHttpClient <Example>("http://www.example.com").Deserialize();

            //1.2
            example = new JsonHttpClient <Example>("http://www.example.com", new HttpClient()).Deserialize();

            //1.3
            example = new JsonHttpClient <Example>("http://www.example.com", new HttpClient()
            {
            }).Deserialize();

            //1.4
            example = new JsonHttpClient <Example>().Deserialize("http://www.example.com");

            //1.5
            example = new JsonHttpClient <Example>().Deserialize("http://www.example.com", httpClient);

            //1.6
            example = new JsonHttpClient <Example>()
            {
                Url        = "http://www.example.com",
                HttpClient = httpClient
            }.Deserialize();

            //1.7
            JsonHttpClient <Example> jsonHttpClient = new JsonHttpClient <Example>("http://www.example.com");

            jsonHttpClient.DeserializeInside();

            int    uid       = jsonHttpClient.Object.Uid;
            string property1 = jsonHttpClient.Object.Property1;
            bool   property2 = jsonHttpClient.Object.Property2;


            //2 Examples - JsonHttpClient
            //2.1
            example = JsonHttpClient.Deserialize <Example>("http://www.example.com");

            //2.2
            //example = JsonHttpClient.Deserialize<Example>("http://www.example.com", httpClient);

            //2.3
            example = JsonHttpClient.DeserializeString <Example>("....JSON....");

            //2.4
            json = JsonHttpClient.Get("http://www.example.com");

            //2.5
            json = JsonHttpClient.Get("http://www.example.com", new HttpClient()
            {
            });

            //2.6
            json = JsonHttpClient.Serialize(new Example()
            {
                Uid       = 756,
                Property1 = "sim756",
                Property2 = true
            });
        }
Пример #6
0
 //Auth
 public Task <APIResponses.Gateway> GetWebSocket()
 => _http.Get <APIResponses.Gateway>(Endpoints.Gateway);