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

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

            // Act
            target.AddAsync(surveyId, responseCodeToAdd).Wait();

            // Assert
            mockedHttpClient.Verify( hc =>
                    hc.PostAsJsonAsync(It.Is<string>(url => url.EndsWith("Surveys/" + surveyId + "/ResponseCodes/")), responseCodeToAdd),
                    Times.Once());
        }
        /// <summary>
        /// <see cref="INfieldSurveyResponseCodesService.AddAsync"/>
        /// </summary>
        public Task<SurveyResponseCode> AddAsync(string surveyId, SurveyResponseCode responseCode)
        {
            if (string.IsNullOrEmpty(surveyId))
            {
                throw new ArgumentNullException("surveyId");
            }

            if (responseCode == null)
            {
                throw new ArgumentNullException("responseCode");
            }
            var uri = SurveyResponseCodeUrl(surveyId, null);

            return Client.PostAsJsonAsync(uri, responseCode)
                .ContinueWith(task => task.Result.Content.ReadAsStringAsync().Result)
                .ContinueWith(task => JsonConvert.DeserializeObjectAsync<SurveyResponseCode>(task.Result).Result)
                .FlattenExceptions();
        }
        /// <summary>
        /// <see cref="INfieldSurveyResponseCodesService.UpdateAsync"/>
        /// </summary>
        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.DeserializeObjectAsync<SurveyResponseCode>(stringTask.Result).Result)
                    .FlattenExceptions();
        }
        public void TestAddAsync_ValidSurveyResponseCode_ReturnsAddedResponseCode()
        {
            // Arrange
            const string surveyId = "surveyId";
            var mockedNfieldConnection = new Mock<INfieldConnectionClient>();
            var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection);

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

            // Act
            var result = target.AddAsync(surveyId, responseCodeToAdd).Result;

            // Assert
            Assert.Equal(responseCodeToAdd.ResponseCode, result.ResponseCode);
            Assert.Equal(responseCodeToAdd.Description, result.Description);
            Assert.Equal(responseCodeToAdd.IsDefinite, result.IsDefinite);
            Assert.Equal(responseCodeToAdd.AllowAppointment, result.AllowAppointment);
            Assert.Equal(responseCodeToAdd.IsSelectable, result.IsSelectable);
        }