예제 #1
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 + "/ScriptFragments/" + fileName)))
            .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldSurveyScriptFragmentService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            target.RemoveAsync(surveyId, fileName).Wait();
        }
예제 #2
0
        public void TestGetAsync_WhenFileNameContainsAmpersand_ReturnsExpectedResult()
        {
            const string surveyId = "SurveyId";
            const string fileName = "MyFileName&";
            const string script   = "*END";

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.GetAsync(new Uri(ServiceAddress, "Surveys/" + surveyId + "/ScriptFragments/MyFileName%26")))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(script)));

            var target = new NfieldSurveyScriptFragmentService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var task   = target.GetAsync(surveyId, fileName);
            var actual = task.Result;

            Assert.Equal(script, actual);
        }
예제 #3
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 + "/ScriptFragments/")))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expected))));

            var target = new NfieldSurveyScriptFragmentService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.QueryAsync(surveyId).Result.ToList();

            Assert.Equal(1, actual.Count);
            Assert.Equal(fileName, actual[0]);
        }