public void TestUploadInterviewerInstructionsAsync_FileDoesNotExist_ThrowsFileNotFoundException() { var target = new NfieldSurveysService(); Assert.Throws <FileNotFoundException>( () => UnwrapAggregateException(target.UploadInterviewerFileInstructionsAsync("NotExistingFile.pdf", "surveyId"))); }
public void TestUploadInterviewerInstructionsAsync_FileExists_FileUpload() { const string surveyId = "SurveyId"; const string fileName = "asp.net-web-api-poster.pdf"; var file = Path.Combine(Directory.GetCurrentDirectory(), "Resources", fileName); var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient.Setup(client => client.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldSurveysService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); target.UploadInterviewerFileInstructionsAsync(file, surveyId); mockedHttpClient.Verify( hc => hc.PostAsync(It.Is <string>(uri => uri.Contains(fileName) && uri.Contains(surveyId)), It.IsAny <HttpContent>()), Times.Once()); }
public void TestUploadInterviewerInstructionsAsync_ValidByteArray_FileUpload() { const string surveyId = "SurveyId"; const string fileName = "instructions.pdf"; var fileContent = Encoding.Unicode.GetBytes("Interviewer Instructions"); var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient.Setup(client => client.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldSurveysService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); target.UploadInterviewerFileInstructionsAsync(fileContent, fileName, surveyId); mockedHttpClient.Verify( hc => hc.PostAsync(It.Is <string>(uri => uri.Contains(fileName) && uri.Contains(surveyId)), It.IsAny <HttpContent>()), Times.Once()); }