Request object for methods adding and deleting collection tags.
コード例 #1
0
        public async Task DeleteTag_MultipleTagVersion_WithEmptyTags_ThrowsException(CollectionSyncanoClient client)
        {
            //given
            var tagRequest = new ManageCollactionTagsRequest();
            tagRequest.ProjectId = TestData.ProjectId;
            tagRequest.CollectionId = TestData.CollectionId;
            tagRequest.Tags = new List<string>();

            try
            {
                //when
                await client.DeleteTag(tagRequest);
                throw new Exception("DeleteTag should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
コード例 #2
0
        public async Task Get_MultipleTagVersion_WithTagsAndTag(CollectionSyncanoClient client)
        {
            //given
            var tags = new List<string> { "abc", "def", "ghi", "jkl" };
            var collection = await client.New(TestData.ProjectId, "Get test");
            var tagRequest = new ManageCollactionTagsRequest();
            tagRequest.ProjectId = TestData.ProjectId;
            tagRequest.Tags = tags;
            tagRequest.CollectionId = collection.Id;
            await client.AddTag(tagRequest);
            var request = new GetCollectionRequest();
            request.ProjectId = TestData.ProjectId;
            request.Tags = new List<string> {tags[0], tags[1], tags[2]};
            request.Tag = tags[3];
            request.Status = CollectionStatus.Inactive;

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

            //then
            result.ShouldNotBeEmpty();

            //cleanup
            await client.Delete(TestData.ProjectId, collection.Id);
        }
コード例 #3
0
        public async Task DeleteTag_MultipleTagVersion_ByCollectionKey_WithWeightAndRemoveOther(CollectionSyncanoClient client)
        {
            //given
            string collectionName = "NewCollection test " + DateTime.Now.ToLongTimeString() + " " +
                                    DateTime.Now.ToShortDateString();
            const string collectionKey = "qwert";
            var tags = new[] { "abc", "def", "ghi" };

            var collection =
                await client.New(TestData.ProjectId, collectionName, collectionKey);
            await client.Activate(TestData.ProjectId, collection.Id, true);

            var tagRequest = new ManageCollactionTagsRequest();
            tagRequest.ProjectId = TestData.ProjectId;
            tagRequest.Tags = new List<string>(tags);
            tagRequest.CollectionKey = collectionKey;

            await client.AddTag(tagRequest, 10.84, true);

            //when
            var result = await client.DeleteTag(tagRequest);
            var request = new GetCollectionRequest();
            request.ProjectId = TestData.ProjectId;
            request.Tag = tags[0];
            var array = await client.Get(request);

            //then
            result.ShouldBeTrue();
            array.ShouldBeEmpty();

            //cleanup
            await client.Delete(TestData.ProjectId, collection.Id);
        }
コード例 #4
0
        public async Task DeleteTag_MultipleTagVersion_WithInvalidProjectId_ThrowsException(CollectionSyncanoClient client)
        {
            //given
            var tags = new[] { "abc", "def", "ghi" };
            var tagRequest = new ManageCollactionTagsRequest();
            tagRequest.ProjectId = "abcde";
            tagRequest.Tags = new List<string>(tags);
            tagRequest.CollectionId = TestData.CollectionId;

            try
            {
                //when
                await client.DeleteTag(tagRequest);
                throw new Exception("DeleteTag should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<SyncanoException>();
            }
        }
コード例 #5
0
        public async Task DeleteTag_SingleTagVersion_WithInvalidCollectionKey_ThrowsException(CollectionSyncanoClient client)
        {
            //given
            var request = new ManageCollactionTagsRequest();
            request.ProjectId = TestData.ProjectId;
            request.Tag = "tag";
            request.CollectionKey = "abcde";

            try
            {
                //when
                await client.DeleteTag(request);

                throw new Exception("DeleteTag should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<SyncanoException>();
            }
        }
コード例 #6
0
        public async Task DeleteTag_SingleTagVersion_WithNullTag_ThrowsException(CollectionSyncanoClient client)
        {
            //given
            var request = new ManageCollactionTagsRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Tag = null;

            try
            {
                //when
                await client.DeleteTag(request);
                throw new Exception("DeleteTag should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
コード例 #7
0
        public async Task AddTag_RemoveOtherTest(CollectionSyncanoClient client)
        {
            //given
            string collectionName = "NewCollection test " + DateTime.Now.ToLongTimeString() + " " +
                                    DateTime.Now.ToShortDateString();
            const string collectionKey = "qwert";
            var tags = new[] { "abc", "def", "ghi" };
            var tag = "jkl";

            var collection =
                await client.New(TestData.ProjectId, collectionName, collectionKey);

            var tagRequest = new ManageCollactionTagsRequest();
            tagRequest.ProjectId = TestData.ProjectId;
            tagRequest.CollectionId = collection.Id;
            tagRequest.Tag = tag;
            await client.AddTag(tagRequest);

            tagRequest.Tags = new List<string>(tags);
            tagRequest.Tag = null;

            //when
            var result = await client.AddTag(tagRequest, 10.84, true);
            var request = new GetCollectionRequest();
            request.ProjectId = TestData.ProjectId;
            request.Tags = new List<string>(tags);
            var array = await client.Get(request);

            //then
            result.ShouldBeTrue();
            array.ShouldNotBeEmpty();
            array.Any(c => c.Tags.Count == tags.Length).ShouldBeTrue();

            //cleanup
            await client.Delete(TestData.ProjectId, collection.Id);
        }
コード例 #8
0
        public async Task DeleteTag_SingleTagVersion_ByCollectionKey_WithWeightAndRemoveOther(CollectionSyncanoClient client)
        {
            //given
            string collectionName = "NewCollection test " + DateTime.Now.ToLongTimeString() + " " +
                                    DateTime.Now.ToShortDateString();
            string collectionKey = "qwert";
            string tag = "abcde";

            var collection =
                await client.New(TestData.ProjectId, collectionName, collectionKey);
            await client.Activate(TestData.ProjectId, collection.Id);

            var request = new ManageCollactionTagsRequest();
            request.ProjectId = TestData.ProjectId;
            request.Tag = tag;
            request.CollectionKey = collectionKey;

            await client.AddTag(request, 3.5, true);

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

            //then
            result.ShouldBeTrue();

            //cleanup
            await client.Delete(TestData.ProjectId, collection.Id);
        }
コード例 #9
0
        public async Task AddTag_MultipleTagVersion_NoTags_ThrowsException(CollectionSyncanoClient client)
        {
            //given
            var request = new ManageCollactionTagsRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionKey = TestData.CollectionKey;

            try
            {
                //when
                await
                    client.AddTag(request, 10.84, true);
                throw new Exception("AddTag should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
コード例 #10
0
        public async Task Get_OneTagVersion_WithTagAndStatus(CollectionSyncanoClient client)
        {
            //given
            string tag = "qwert";
            var collection = await client.New(TestData.ProjectId, "Get test");
            var tagRequest = new ManageCollactionTagsRequest();
            tagRequest.ProjectId = TestData.ProjectId;
            tagRequest.Tag = tag;
            tagRequest.CollectionId = collection.Id;
            await client.AddTag(tagRequest);
            var request = new GetCollectionRequest();
            request.ProjectId = TestData.ProjectId;
            request.Tag = tag;
            request.Status = CollectionStatus.Inactive;

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

            //then
            result.ShouldNotBeEmpty();

            //cleanup
            await client.Delete(TestData.ProjectId, collection.Id);
        }
コード例 #11
0
        public async Task AddTag_MultipleTagVersion_WithNullKeyAndId_ThrowsException(CollectionSyncanoClient client)
        {
            //given
            var tags = new[] {"abc", "def", "ghi"};
            var tagRequest = new ManageCollactionTagsRequest();
            tagRequest.ProjectId = TestData.ProjectId;
            tagRequest.Tags = new List<string>(tags);

            try
            {
                //when
                await client.AddTag(tagRequest);
                throw new Exception("AddTag should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentNullException>();
            }
        }
コード例 #12
0
        /// <summary>
        /// Delete a tag or tags from specified collection.
        /// <remarks>Note: tags are case sensitive.</remarks>
        /// </summary>
        /// <param name="request">Tags manage request.</param>
        /// <returns>Boolen value indicating success of method.</returns>
        public Task<bool> DeleteTag(ManageCollactionTagsRequest request)
        {
            if (request.CollectionId == null && request.CollectionKey == null)
                throw new ArgumentNullException();

            if (request.ProjectId == null)
                throw new ArgumentNullException();

            var tagsList = request.Tags == null ? new List<string>() : new List<string>(request.Tags);
            if (request.Tag != null)
                tagsList.Add(request.Tag);
            var tags = tagsList.Count == 0 ? null : tagsList.ToArray();

            if (tags == null)
                throw new ArgumentException();

            if (tags.Any(t => t == ""))
                throw new ArgumentException();

            return _syncanoClient.GetAsync("collection.delete_tag",
                new
                {
                    project_id = request.ProjectId,
                    collection_id = request.CollectionId,
                    collection_key = request.CollectionKey,
                    tags,
                });
        }
コード例 #13
0
        /// <summary>
        /// Add a tag to specific event.
        /// <remarks>Note: tags are case sensitive.</remarks>
        /// </summary>
        /// <param name="request">Tags manage request.</param>
        /// <param name="weight">Tag(s) weight. Default value: 1.</param>
        /// <param name="removeOther">If true, will remove all other tags of specified collection. Default value: False.</param>
        /// <returns>Boolen value indicating success of method.</returns>
        public Task<bool> AddTag(ManageCollactionTagsRequest request, double weight = 1.0, bool removeOther = false)
        {
            if(request.CollectionId == null && request.CollectionKey == null)
                throw new ArgumentNullException();

            if(request.ProjectId == null)
                throw new ArgumentNullException();

            var tagsList = request.Tags == null ? new List<string>() : new List<string>(request.Tags);
            if (request.Tag != null)
                tagsList.Add(request.Tag);
            var tags = tagsList.Count == 0 ? null : tagsList.ToArray();

            if (tags == null)
                throw new ArgumentException();

            if(tags.Any(t => t == ""))
                throw new ArgumentException();

            return _syncanoClient.GetAsync("collection.add_tag",
                new
                {
                    project_id = request.ProjectId,
                    collection_id = request.CollectionId,
                    collection_key = request.CollectionKey,
                    tags = tags.ToArray(),
                    weight = weight.ToString(CultureInfo.InvariantCulture),
                    remove_other = removeOther
                });
        }