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

QueryAsync() public method

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

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

Usage Example

        public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithPublicIds()
        {
            var expectedPublicIds = new []
            { new SurveyPublicId {  LinkType = "X Type", Active = false, Url = "X Url" },
              new SurveyPublicId {  LinkType = "Y Type", Active = true, Url = "Y Url" }
            };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.GetAsync(ServiceAddress + "Surveys/" + SurveyId + "/PublicIds"))
                .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedPublicIds))));

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

            var actualPublicIds = target.QueryAsync(SurveyId).Result.ToArray(); ;
            Assert.Equal(expectedPublicIds[0].LinkType, actualPublicIds[0].LinkType);
            Assert.Equal(expectedPublicIds[0].Active, actualPublicIds[0].Active);
            Assert.Equal(expectedPublicIds[0].Url, actualPublicIds[0].Url);
            Assert.Equal(expectedPublicIds[1].LinkType, actualPublicIds[1].LinkType);
            Assert.Equal(expectedPublicIds[1].Active, actualPublicIds[1].Active);
            Assert.Equal(expectedPublicIds[1].Url, actualPublicIds[1].Url);
            Assert.Equal(2, actualPublicIds.Length);
        }
All Usage Examples Of Nfield.Services.Implementation.NfieldSurveyPublicIdsService::QueryAsync