public void TestQueryAsync_WhenFilePresent_ReturnsCorrectName() { const string surveyId = "SurveyId"; const string fileName = "MyFileName"; var expected = new List <string>() { fileName }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/MediaFiles/"))) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expected)))); var target = new NfieldMediaFilesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.QueryAsync(surveyId).Result.ToList(); Assert.Equal(1, actual.Count); Assert.Equal(fileName, actual[0]); }
public void TestRemoveAsync_Always_DoesNotThrow() { const string surveyId = "SurveyId"; const string fileName = "MyFileName"; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.DeleteAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/MediaFiles/?fileName=" + fileName))) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldMediaFilesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); target.RemoveAsync(surveyId, fileName).Wait(); }
public void TestGetCountAsync_Always_ReturnsCorrectCount() { const string surveyId = "SurveyId"; const int expectedCount = 4; var uri = new Uri(ServiceAddress, "Surveys/" + surveyId + "/MediaFiles/Count"); var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(uri)) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(expectedCount.ToString()))); var target = new NfieldMediaFilesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.GetCountAsync(surveyId).Result; Assert.Equal(expectedCount, actual); }
public void TestAddOrUpdateAsync_Always_DoesNotThrow() { const string surveyId = "SurveyId"; const string fileName = "MyFileName"; byte[] content = new byte[] { 1, 2, 3, 4, 5 }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.PutAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/MediaFiles/?fileName=" + fileName), It.IsAny <HttpContent>())) .Returns(CreateTask(HttpStatusCode.OK)); var target = new NfieldMediaFilesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); target.AddOrUpdateAsync(surveyId, fileName, content).Wait(); }
public void TestGetAsync_Always_ReturnsExpectedResult() { const string surveyId = "SurveyId"; const string fileName = "MyFileName"; var expected = Encoding.UTF8.GetBytes("content"); var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/MediaFiles/?fileName=" + fileName))) .Returns(CreateTask(HttpStatusCode.OK, new ByteArrayContent(expected))); var target = new NfieldMediaFilesService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var task = target.GetAsync(surveyId, fileName); task.Wait(); var actual = task.Result; Assert.Equal(expected, actual); }