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 <Uri>(), 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 <Uri>(url => url.AbsolutePath.EndsWith("Surveys/" + surveyId + "/Distribute/")), It.Is <SurveyInterviewerDistributeModel>(m => m == model)), Times.Once()); }
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()); }