Beispiel #1
0
        public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithSettings()
        {
            var expectedSettings = new SurveySetting[]
            { new SurveySetting {
                  Name = "X", Value = "X Value"
              },
              new SurveySetting {
                  Name = "Y", Value = "Y Value"
              } };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.GetAsync(ServiceAddress + "Surveys/" + SurveyId + "/Settings"))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedSettings))));

            var target = new NfieldSurveySettingsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualSettings = target.QueryAsync(SurveyId).Result.ToArray();;

            Assert.Equal(expectedSettings[0].Name, actualSettings[0].Name);
            Assert.Equal(expectedSettings[1].Name, actualSettings[1].Name);
            Assert.Equal(2, actualSettings.Length);
        }
        /// <summary>
        /// See <see cref="INfieldSurveySettingsService.AddOrUpdateAsync"/>
        /// </summary>
        public Task <SurveySetting> AddOrUpdateAsync(string surveyId, SurveySetting setting)
        {
            CheckSurveyId(surveyId);

            if (setting == null)
            {
                throw new ArgumentNullException("setting");
            }

            return(Client.PostAsJsonAsync(SettingsApi(surveyId, null), setting)
                   .ContinueWith(task => task.Result.Content.ReadAsStringAsync().Result)
                   .ContinueWith(task => JsonConvert.DeserializeObject <SurveySetting>(task.Result))
                   .FlattenExceptions());
        }
Beispiel #3
0
        public void TestAddOrUpdateAsync_ServerAcceptsSetting_ReturnsSetting()
        {
            var setting = new SurveySetting {
                Name = "Setting X"
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(setting));

            mockedHttpClient
            .Setup(client => client.PostAsJsonAsync(ServiceAddress + "Surveys/" + SurveyId + "/Settings", setting))
            .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveySettingsService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.AddOrUpdateAsync(SurveyId, setting).Result;

            Assert.Equal(setting.Name, actual.Name);
        }
Beispiel #4
0
 /// <summary>
 /// A synchronous version of <see cref="INfieldSurveySettingsService.AddOrUpdateAsync"/>
 /// </summary>
 public static SurveySetting AddOrUpdate(this INfieldSurveySettingsService settingsService, string surveyId, SurveySetting setting)
 {
     return(settingsService.AddOrUpdateAsync(surveyId, setting).Result);
 }