Nfield.Services.Implementation.NfieldAddressesService.GetCountAsync C# (CSharp) Method

GetCountAsync() public method

public GetCountAsync ( string surveyId, string samplingPointId ) : Task
surveyId string
samplingPointId string
return Task
        public Task<int> GetCountAsync(string surveyId, string samplingPointId)
        {
            CheckSurveyIdAndSamplingPointId(surveyId, samplingPointId);

            var uri = $"{AddressesApi(surveyId, samplingPointId, null).AbsoluteUri}/Count";
            return Client.GetAsync(uri)
                .ContinueWith(rmt => int.Parse(rmt.Result.Content.ReadAsStringAsync().Result))
                .FlattenExceptions();
        }

Usage Example

        public void TestGetCountAsync_ServerReturnsCount_ReturnsNumberOfAddresses()
        {
            var uri = $"{ServiceAddress}Surveys/{SurveyId}/SamplingPoints/{SamplingPointId}/Addresses/Count";
            var expectedCount = 8;

            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 NfieldAddressesService();
            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualCount = target.GetCountAsync(SurveyId, SamplingPointId).Result;
            Assert.Equal(expectedCount, actualCount);
        }