Nfield.Services.Implementation.NfieldSurveyRelocationsService.UpdateAsync C# (CSharp) Method

UpdateAsync() public method

See INfieldSurveyRelocationsService.UpdateAsync
public UpdateAsync ( string surveyId, SurveyRelocation relocation ) : System.Threading.Tasks.Task
surveyId string
relocation Nfield.Models.SurveyRelocation
return System.Threading.Tasks.Task
        public Task UpdateAsync(string surveyId, SurveyRelocation relocation)
        {
            CheckSurveyId(surveyId);

            if (relocation == null)
            {
                throw new ArgumentNullException(nameof(relocation));
            }

            return Client.PutAsJsonAsync(RelocationsApi(surveyId).AbsoluteUri, relocation)
                         .ContinueWith(task => task.Result.Content.ReadAsStringAsync().Result)
                         .ContinueWith(task => JsonConvert.DeserializeObject<SurveyRelocation>(task.Result))
                         .FlattenExceptions();
        }

Usage Example

        public void TestPutAsync_Always_CallsCorrectURI()
        {
            var relocation = new SurveyRelocation { Reason = "reason X", Url = "url X" };
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);
            mockedHttpClient
                .Setup(client => client.PutAsJsonAsync(It.IsAny<string>(), It.IsAny<SurveyRelocation>()))
                .Returns(CreateTask(HttpStatusCode.OK,
                    new StringContent(JsonConvert.SerializeObject(It.IsAny<SurveyRelocation>()))));

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

            target.UpdateAsync(SurveyId, relocation).Wait();

            mockedHttpClient
                .Verify(
                    client =>
                        client.PutAsJsonAsync(ServiceAddress + "Surveys/" + SurveyId + "/Relocations", It.IsAny<SurveyRelocation>()),
                    Times.Once());
        }
All Usage Examples Of Nfield.Services.Implementation.NfieldSurveyRelocationsService::UpdateAsync