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

SamplingPointImageAddAsync() public method

INfieldSurveysService.SamplingPointImageAddAsync(string, string, string)
public SamplingPointImageAddAsync ( string surveyId, string samplingPointId, string filePath ) : Task
surveyId string
samplingPointId string
filePath string
return Task
        public Task<string> SamplingPointImageAddAsync(string surveyId, string samplingPointId, string filePath)
        {
            if(!File.Exists(filePath))
                throw new FileNotFoundException(filePath);

            var byteArrayContent = new ByteArrayContent(File.ReadAllBytes(filePath));
            return SamplingPointImageAddAsync(surveyId, samplingPointId, Path.GetFileName(filePath), byteArrayContent);
        }

Same methods

NfieldSurveysService::SamplingPointImageAddAsync ( string surveyId, string samplingPointId, string filename, System.Net.Http.ByteArrayContent byteArrayContent ) : Task
NfieldSurveysService::SamplingPointImageAddAsync ( string surveyId, string samplingPointId, string filename, byte content ) : Task

Usage Example

        public void TestSamplingPointImageAddAsync_ServerAcceptsSamplingPointImage_ReturnsFilename()
        {
            const string surveyId = "SurveyId";
            const string samplingPointId = "SamplingPointId";
            const string fileName = "1.jpg";
            string filePath = Path.Combine(Directory.GetCurrentDirectory(), "Resources", fileName);

            var content = new ByteArrayContent(File.ReadAllBytes(filePath));

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

            mockedHttpClient.Setup(client => client.PostAsync(It.IsAny<string>(), It.IsAny<ByteArrayContent>()))
                                    .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(fileName))));

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

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

            Assert.Equal(fileName, result);
        }