AddAsync() public method

INfieldSurveyResponseCodesService.AddAsync
public AddAsync ( string surveyId, Nfield.Models.SurveyResponseCode responseCode ) : Task
surveyId string
responseCode Nfield.Models.SurveyResponseCode
return Task
        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());
        }
        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);
        }
 public void TestAddAsync_SurveyResponseCodeIdIsNull_Throws()
 {
     var target = new NfieldSurveyResponseCodesService();
     Assert.Throws<ArgumentNullException>(() => UnwrapAggregateException(target.AddAsync("surveyId", null)));
 }
 public void TestAddAsync_SurveyIdIsEmptyString_Throws()
 {
     var target = new NfieldSurveyResponseCodesService();
     Assert.Throws<ArgumentNullException>(
         () => UnwrapAggregateException(target.AddAsync(string.Empty, new SurveyResponseCode())));
 }