public void TestSamplingPointQuotaTargetUpdateAsync_SamplingPointQuotaTargetExists_ReturnsSamplingPointQuotaTarget() { const string levelId = "LevelId"; const string surveyId = "SurveyId"; const string samplingPointId = "SamplingPointId"; var samplingPointQuotaTarget = new SamplingPointQuotaTarget { LevelId = levelId, Target = 10 }; var mockedNfieldConnection = new Mock<INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup( client => client.PatchAsJsonAsync<UpdateSamplingPointQuotaTarget>( string.Format("{0}surveys/{1}/samplingpoints/{2}/quotatargets/{3}", ServiceAddress, surveyId, samplingPointId, levelId), It.IsAny<UpdateSamplingPointQuotaTarget>())) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(samplingPointQuotaTarget)))); var target = new NfieldSurveysService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.SamplingPointQuotaTargetUpdateAsync(surveyId,samplingPointId,samplingPointQuotaTarget).Result; Assert.Equal(samplingPointQuotaTarget.Target, actual.Target); }
/// <summary> /// See <see cref="INfieldSurveysService.SamplingPointQuotaTargetUpdateAsync"/> /// </summary> public Task<SamplingPointQuotaTarget> SamplingPointQuotaTargetUpdateAsync(string surveyId, string samplingPointId, SamplingPointQuotaTarget samplingPointQuotaTarget) { if (samplingPointQuotaTarget == null) { throw new ArgumentNullException("samplingPointQuotaTarget"); } var updatedSamplingPointQuotaTarget = new UpdateSamplingPointQuotaTarget { Target = samplingPointQuotaTarget.Target }; string uri = string.Format(@"{0}{1}/{2}/{3}/{4}/{5}", SurveysApi.AbsoluteUri, surveyId, SamplingPointsControllerName, samplingPointId, SamplingPointsQuotaControllerName, samplingPointQuotaTarget.LevelId); return Client.PatchAsJsonAsync(uri, updatedSamplingPointQuotaTarget) .ContinueWith( responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result) .ContinueWith( stringTask => JsonConvert.DeserializeObject<SamplingPointQuotaTarget>(stringTask.Result)) .FlattenExceptions(); }
public void TestSamplingPointQuotaTargetsQueryAsync_ServerReturnsQuery_ReturnsListWithSamplingPointQuotaTargets() { var expectedSamplingPointQuotaTarget = new SamplingPointQuotaTarget[] { new SamplingPointQuotaTarget { LevelId = "TestLevel" }, new SamplingPointQuotaTarget { LevelId = "AnotherTestLevel" } }; var mockedNfieldConnection = new Mock<INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(ServiceAddress + "surveys/1/samplingpoints/1/quotatargets")) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedSamplingPointQuotaTarget)))); var target = new NfieldSurveysService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actualSamplingPointQuotaTarget = target.SamplingPointQuotaTargetsQueryAsync("1","1").Result; Assert.Equal(expectedSamplingPointQuotaTarget[0].LevelId, actualSamplingPointQuotaTarget.ToArray()[0].LevelId); Assert.Equal(expectedSamplingPointQuotaTarget[1].LevelId, actualSamplingPointQuotaTarget.ToArray()[1].LevelId); Assert.Equal(2, actualSamplingPointQuotaTarget.Count()); }