Ejemplo n.º 1
0
        public async Task<GetConnetionResponse> GetConnectionsAsync(CancellationToken token)
        {
            var request = GetBaseRequest("connections");
            var response = await _restClient.ExecuteTaskAsync(request, token);

            HandleRestErrors(response);

            var result = new GetConnetionResponse();
            var jsonSettings = new JsonSerializerSettings
            {
                ContractResolver = new LowercaseContractResolver()
            };

            var desResult =
                JsonConvert.DeserializeObject<Dictionary<string, GetConnetionResponse.TotalDetails>>(response.Content,
                    jsonSettings);

            result.Total = desResult.Single(x => x.Key == "total").Value;
            result.AvailableConnections = desResult.Count;

            return result;
        }
        private static void AssertGetConnectionsRequest(GetConnetionResponse response)
        {
            // total sub object
            Assert.IsNotNull(response.Total);

            var total = response.Total;

            if (total == null) return;

            // total.At property
            DateTime dummy;
            Assert.IsTrue(DateTime.TryParse(total.At.ToLongTimeString(), out dummy));
            Assert.IsNotNull(dummy);

            // total.InBytesTotal property
            Assert.IsTrue(total.InBytesTotal >= 0);

            // total.OutBytesTotal property
            Assert.IsTrue(total.OutBytesTotal >= 0);
        }
Ejemplo n.º 3
0
        public GetConnetionResponse GetConnetions()
        {
            var customRestClient = GetRestClient();

            var request = GetBaseRequest("connections");
            var response = customRestClient.Execute(request);

            HandleRestErrors(response);

            var result = new GetConnetionResponse();
            var jsonSettings = new JsonSerializerSettings
            {
                ContractResolver = new LowercaseContractResolver()
            };

            var desResult =
                JsonConvert.DeserializeObject<Dictionary<string, GetConnetionResponse.TotalDetails>>(response.Content,
                    jsonSettings);

            result.Total = desResult.Single(x => x.Key == "total").Value;
            result.AvailableConnections = desResult.Count - 1;

            return result;
        }