Ejemplo n.º 1
0
        public async Task GetHistory()
        {
            using (var client = new Client())
            {
                const string symbol = "MSFT";
                const string type = "daily";
                const string startDate = "20140831000000";

                var urlSuffix = string.Format("?key={0}&symbol={1}&type={2}&startDate={3}", _key, symbol, type, startDate);
                var history = await client.GetHistory(urlSuffix);

                Assert.IsNotNull(history);
                Assert.IsNotNull(history.Results);
                Assert.IsNotNull(history.Status);
            }
        }
        public async Task CheckInternalServerErrorResponseHandling()
        {
            var mockHttpMessageHandler = new MockHttpMessageHandler
            {
                Response = { StatusCode = HttpStatusCode.InternalServerError }
            };

            var client = new Client(new HttpClient(mockHttpMessageHandler));
            var uri = new Uri("http://unittest");

            try
            {
                await client.HttpGetAsync(uri);
            }
            catch (HttpRequestException httpRequestException)
            {
                Assert.AreEqual(httpRequestException.Message, "Response status code does not indicate success: 500 (Internal Server Error).");

                throw;
            }
        }
        public async Task CheckOkResponseHandling()
        {
            const string expectedResponse = "response";

       

            var mockHttpMessageHandler = new MockHttpMessageHandler
            {
                Response =
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new StringContent(expectedResponse)
                }
            };

            var client = new Client(new HttpClient(mockHttpMessageHandler));
            var uri = new Uri("http://unittest");
            var response = await client.HttpGetAsync(uri);

            Assert.IsNotNullOrEmpty(response);
            Assert.AreEqual(expectedResponse, response);
        }