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

UpdateAsync() public method

INfieldSurveyResponseCodesService.UpdateAsync
public UpdateAsync ( string surveyId, Nfield.Models.SurveyResponseCode responseCode ) : Task
surveyId string
responseCode Nfield.Models.SurveyResponseCode
return Task
        public Task<SurveyResponseCode> UpdateAsync(string surveyId, SurveyResponseCode responseCode)
        {
            if (string.IsNullOrEmpty(surveyId))
            {
                throw new ArgumentNullException("surveyId");
            }

            if(responseCode == null)
            {
                throw new ArgumentNullException("responseCode");
            }

            var updatedresponseCode = new UpdateSurveyResponseCode
            {
                Description = responseCode.Description,
                IsDefinite = responseCode.IsDefinite,
                IsSelectable = responseCode.IsSelectable,
                AllowAppointment = responseCode.AllowAppointment
            };

            return
                Client.PatchAsJsonAsync(SurveyResponseCodeUrl(surveyId, responseCode.ResponseCode), updatedresponseCode)
                    .ContinueWith(
                        responseMessageTask =>
                            responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                    .ContinueWith(
                        stringTask => JsonConvert.DeserializeObject<SurveyResponseCode>(stringTask.Result))
                    .FlattenExceptions();
        }

Usage Example

        public void TestUpdateAsync_ValidSurveyResponseCode_ReturnsModifiedResponseCode()
        {
            // Arrange
            const string surveyId = "surveyId";
            const int code = 10;
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);

            var responseCodeToUpdate = new SurveyResponseCode
            {
                ResponseCode = code,
                Description = "Description",
                IsDefinite = true,
                AllowAppointment = false
            };
            mockedHttpClient.Setup(client => client.PatchAsJsonAsync(It.IsAny<string>(), It.IsAny<UpdateSurveyResponseCode>()))
                .Returns(CreateTask(HttpStatusCode.OK,
                    new StringContent(JsonConvert.SerializeObject(responseCodeToUpdate))));
            var target = new NfieldSurveyResponseCodesService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // Act
            var result = target.UpdateAsync(surveyId, responseCodeToUpdate).Result;

            // Assert
            Assert.Equal(responseCodeToUpdate.ResponseCode, result.ResponseCode);
            Assert.Equal(responseCodeToUpdate.Description, result.Description);
            Assert.Equal(responseCodeToUpdate.IsDefinite, result.IsDefinite);
            Assert.Equal(responseCodeToUpdate.AllowAppointment, result.AllowAppointment);
            Assert.Equal(responseCodeToUpdate.IsSelectable, result.IsSelectable);
        }
All Usage Examples Of Nfield.Services.Implementation.NfieldSurveyResponseCodesService::UpdateAsync