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

QueryAsync() public method

public QueryAsync ( string surveyId ) : Task>
surveyId string
return Task>
        public Task<IQueryable<string>> QueryAsync(string surveyId)
        {
            if (string.IsNullOrEmpty(surveyId))
            {
                throw new ArgumentNullException("surveyId");
            }
            return Client.GetAsync(MediaFilesApi(surveyId, null).AbsoluteUri)
                         .ContinueWith(
                             responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                         .ContinueWith(
                             stringTask =>
                             JsonConvert.DeserializeObject<List<string>>(stringTask.Result).AsQueryable())
                         .FlattenExceptions();
        }

Usage Example

        public void TestQueryAsync_WhenFilePresent_ReturnsCorrectName()
        {
            const string surveyId = "SurveyId";
            const string fileName = "MyFileName";
            var expected = new List<string>() { fileName };

            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.GetAsync(ServiceAddress + "Surveys/" + surveyId + "/MediaFiles/"))
                .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expected))));

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

            var actual = target.QueryAsync(surveyId).Result.ToList();

            Assert.Equal(1, actual.Count);
            Assert.Equal(fileName, actual[0]);
        }