public Task DistributeAsync(string surveyId, SurveyInterviewerDistributeModel model) { if (string.IsNullOrEmpty(surveyId)) { throw new ArgumentNullException("surveyId"); } if (model == null) { throw new ArgumentNullException("model"); } var uri = SurveyDistributeUrl(surveyId); return Client.PostAsJsonAsync(uri, model).FlattenExceptions(); }
public void TestDistributeAsync_ValidSurveyResponseCode_CallsCorrectUrl() { // Arrange const string surveyId = "surveyId"; var mockedNfieldConnection = new Mock<INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient.Setup(client => client.PostAsJsonAsync(It.IsAny<string>(), It.IsAny<SurveyInterviewerDistributeModel>())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldSurveyInterviewerWorkpackageDistributionService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); // Act var model = new SurveyInterviewerDistributeModel(); target.DistributeAsync(surveyId, model).Wait(); // Assert mockedHttpClient.Verify(hc => hc.PostAsJsonAsync( It.Is<string>(url => url.EndsWith("Surveys/" + surveyId + "/Distribute/")), It.Is<SurveyInterviewerDistributeModel>(m => m == model)), Times.Once()); }