Nfield.Services.Implementation.NfieldSurveysService.QuotaQueryAsync C# (CSharp) Method

QuotaQueryAsync() public method

See INfieldSurveysService.QuotaQueryAsync
public QuotaQueryAsync ( string surveyId ) : Task
surveyId string
return Task
        public Task<QuotaLevel> QuotaQueryAsync(string surveyId)
        {
            string uri = string.Format(@"{0}{1}/{2}", SurveysApi.AbsoluteUri, surveyId, QuotaControllerName);

            return Client.GetAsync(uri)
                         .ContinueWith(
                             responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                         .ContinueWith(
                             stringTask =>
                             JsonConvert.DeserializeObject<QuotaLevel>(stringTask.Result))
                         .FlattenExceptions();
        }

Usage Example

        public void TestQuotaQueryAsync_ServerReturnsQuery_ReturnsListWithQuotaLevel()
        {
            const string levelId = "LevelId";
            const string name = "Name";

            var expectedQuotaLevel = new QuotaLevel
            {
                Id = levelId,
                Name = name
            };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.GetAsync(ServiceAddress + "surveys/1/quota"))
                .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedQuotaLevel))));

            var target = new NfieldSurveysService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualQuotaLevel = target.QuotaQueryAsync("1").Result;
            mockedHttpClient.Verify(hc => hc.GetAsync(It.IsAny<string>()), Times.Once());
            Assert.Equal(expectedQuotaLevel.Id, actualQuotaLevel.Id);
            Assert.Equal(expectedQuotaLevel.Name, actualQuotaLevel.Name);
        }