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); }
public void TestUpdateAsync_SurveyresponseCodeIsNull_Throws() { var target = new NfieldSurveyResponseCodesService(); Assert.Throws <ArgumentNullException>( () => UnwrapAggregateException(target.UpdateAsync("sruveyId", null))); }
public void TestUpdateAsync_ValidSurveyResponseCode_CallsCorrectUrl() { // 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(new SurveyResponseCode())))); var target = new NfieldSurveyResponseCodesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); // Act target.UpdateAsync(surveyId, responseCodeToUpdate).Wait(); // Assert mockedHttpClient.Verify(hc => hc.PatchAsJsonAsync( It.Is <string>( url => url.EndsWith(string.Format("Surveys/{0}/ResponseCodes/{1}", surveyId, code))), It.IsAny <UpdateSurveyResponseCode>()), Times.Once()); }
public void TestUpdateAsync_SurveyIdIsEmptyString_Throws() { var target = new NfieldSurveyResponseCodesService(); Assert.Throws <ArgumentNullException>( () => UnwrapAggregateException(target.UpdateAsync(string.Empty, new SurveyResponseCode()))); }