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

SamplingPointImageGetAsync() public method

public SamplingPointImageGetAsync ( string surveyId, string samplingPointId ) : Task
surveyId string
samplingPointId string
return Task
        public Task<SamplingPointImage> SamplingPointImageGetAsync(string surveyId, string samplingPointId)
        {
            var uri = GetSamplingPointImageUri(surveyId, samplingPointId, null);

            return Client.GetAsync(uri)
                .ContinueWith(
                    responseMessageTask => new SamplingPointImage
                    {
                        Content = responseMessageTask.Result.Content.ReadAsByteArrayAsync().Result,
                        FileName = responseMessageTask.Result.Content.Headers.ContentDisposition.FileName
                    })
                .FlattenExceptions();
        }

Usage Example

        public void TestSamplingPointImageGetAsync_ServerAcceptsGet_ReturnsFilename()
        {
            const string surveyId = "SurveyId";
            const string samplingPointId = "SamplingPointId";
            const string fileName = "1.jpg";

            var getContent = new ByteArrayContent(new byte[] { 1 });
            getContent.Headers.ContentDisposition =
                new ContentDispositionHeaderValue("attachment")
                {
                    FileName = fileName
                };

            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient.Setup(client => client.GetAsync(It.IsAny<string>()))
                                    .Returns(CreateTask(HttpStatusCode.OK, getContent));

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

            var result = target.SamplingPointImageGetAsync(surveyId, samplingPointId).Result;

            Assert.Equal(fileName, result.FileName);
        }