Nfield.Services.Implementation.NfieldMediaFilesService.GetAsync C# (CSharp) 메소드

GetAsync() 공개 메소드

public GetAsync ( string surveyId, string fileName ) : Task
surveyId string
fileName string
리턴 Task
        public Task<byte[]> GetAsync(string surveyId, string fileName)
        {
            if (string.IsNullOrEmpty(surveyId))
            {
                throw new ArgumentNullException("surveyId");
            }

            return Client.GetAsync(MediaFilesApi(surveyId, fileName).AbsoluteUri)
                .ContinueWith(responseMessageTask => responseMessageTask.Result.Content.ReadAsByteArrayAsync())
                .ContinueWith(b => b.Result.Result)
                .FlattenExceptions();
        }

Usage Example

        public void TestGetAsync_Always_ReturnsExpectedResult()
        {
            const string surveyId = "SurveyId";
            const string fileName = "MyFileName";
            var expected = Encoding.UTF8.GetBytes("content");

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

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

            var task = target.GetAsync(surveyId, fileName);
            task.Wait();
            var actual = task.Result;

            Assert.Equal(expected, actual);
        }