Count() public method

Count users of specified criteria. The collection_id/collection_key parameter means that one can use either one of them - collection_id or collection_key.
public Count ( UserQueryRequest request ) : Task
request Syncano.Net.DataRequests.UserQueryRequest User query request object.
return Task
        public async Task Count_WithImageContentFilter_GetsCountOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();
            dataRequest.ProjectId = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.ImageBase64 = TestData.ImageToBase64("smallSampleImage.png");
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Filter = DataObjectContentFilter.Image;

            //when
            var result = await client.Count(request);

            //then
            result.ShouldEqual(1);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.Delete(deleteRequest);
        }
        public async Task Count_WithFolderListName_GetsCountOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();
            dataRequest.ProjectId = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.Folder = TestData.FolderName;
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Folders = new List<string> { TestData.FolderName };

            //when
            var result = await client.Count(request);

            //then
            result.ShouldEqual(1);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.Delete(deleteRequest);
        }
        public async Task Count_WithPendingState_GetsCountOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();
            dataRequest.ProjectId = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.State = DataObjectState.Pending;
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.State = DataObjectState.Pending;

            //when
            var result = await client.Count(request);

            //then
            result.ShouldEqual(1);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.Delete(deleteRequest);
        }
        public async Task Count_WithNullCollectionIdAndCollectionKey_ThrowsException(UserSyncanoClient client)
        {
            //given
            var request = new UserQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = "not null";
            request.CollectionKey = "not null";

            try
            {
                //when
                await client.Count(request);
                throw new Exception("Count should throw an exception.");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task Count_WithInvalidCollectionId_ThrowsException(UserSyncanoClient client)
        {
            //given
            var request = new UserQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = "abcde";

            try
            {
                //when
                await client.Count(request);
                throw new Exception("Count should throw an exception.");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<SyncanoException>();
            }
        }
        public async Task Count_WithTextContentFilter_GetsCountOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();
            dataRequest.ProjectId = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.Text = "sample text content";
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Filter = DataObjectContentFilter.Text;

            //when
            var result = await client.Count(request);

            //then
            result.ShouldEqual(1);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.Delete(deleteRequest);
        }