コード例 #1
0
        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]);
        }
コード例 #2
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();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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);
        }