Nfield.Services.Implementation.NfieldSurveySettingsService.QueryAsync C# (CSharp) Method

QueryAsync() public method

See INfieldSurveySettingsService.QueryAsync
public QueryAsync ( string surveyId ) : Task>
surveyId string
return Task>
        public Task<IQueryable<SurveySetting>> QueryAsync(string surveyId)
        {
            CheckSurveyId(surveyId);

            return Client.GetAsync(SettingsApi(surveyId, null).AbsoluteUri)
                         .ContinueWith(
                             responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                         .ContinueWith(
                             stringTask =>
                             JsonConvert.DeserializeObject<List<SurveySetting>>(stringTask.Result).AsQueryable())
                         .FlattenExceptions();
        }

Usage Example

        public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithSettings()
        {
            var expectedSettings = new SurveySetting[]
            { new SurveySetting{ Name = "X", Value = "X Value" },
              new SurveySetting{ Name = "Y", Value = "Y Value" }
            };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.GetAsync(ServiceAddress + "Surveys/" + SurveyId + "/Settings"))
                .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedSettings))));

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

            var actualSettings = target.QueryAsync(SurveyId).Result.ToArray(); ;
            Assert.Equal(expectedSettings[0].Name, actualSettings[0].Name);
            Assert.Equal(expectedSettings[1].Name, actualSettings[1].Name);
            Assert.Equal(2, actualSettings.Length);
        }
All Usage Examples Of Nfield.Services.Implementation.NfieldSurveySettingsService::QueryAsync