RemoveChild() публичный Метод

Removes a child (or children) from data with specified data_id. The collection_id/collection_key parameter means that one can use either one of them - collection_id or collection_key. User API key usage permitted. Data Object that child is removed from is required to be in a container with an update_data permission or (or update_own_data if it is associated with current user). Also, child itself is required to be in a container with a (read_data permission or read_own_data if it is associated with current user).
public RemoveChild ( string projectId, string dataId, string childId = null, string collectionId = null, string collectionKey = null ) : Task
projectId string Project id.
dataId string Data Object id.
childId string Child id to remove. If not specified, will remove all Data Object children.
collectionId string Collection id defining collection containing data.
collectionKey string Collection key defining collection containing data.
Результат Task
        public async Task RemoveChild_WithInvalidChildId_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var newParentRequest = new DataObjectDefinitionRequest();
            newParentRequest.ProjectId = TestData.ProjectId;
            newParentRequest.CollectionId = TestData.CollectionId;
            var parentObject = await client.New(newParentRequest);

            var newChildRequest = new DataObjectDefinitionRequest();
            newChildRequest.ProjectId = TestData.ProjectId;
            newChildRequest.CollectionId = TestData.CollectionId;
            var childObject = await client.New(newChildRequest);

            await client.AddChild(TestData.ProjectId, parentObject.Id, childObject.Id, TestData.CollectionId);

            try
            {
                //when
                await client.RemoveChild(TestData.ProjectId, parentObject.Id, "abc", TestData.CollectionId);
                throw new Exception("RemoveChild should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<SyncanoException>();
            }
            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task RemoveChild_ByCollectionKey_WithOtherChildren(DataObjectSyncanoClient client)
        {
            //given
            var newParentRequest = new DataObjectDefinitionRequest();
            newParentRequest.ProjectId = TestData.ProjectId;
            newParentRequest.CollectionId = TestData.CollectionId;
            var parentObject = await client.New(newParentRequest);

            var newOtherRequest = new DataObjectDefinitionRequest();
            newOtherRequest.ProjectId = TestData.ProjectId;
            newOtherRequest.CollectionId = TestData.CollectionId;
            newOtherRequest.ParentId = parentObject.Id;
            var otherObject = await client.New(newOtherRequest);

            var newChildRequest = new DataObjectDefinitionRequest();
            newChildRequest.ProjectId = TestData.ProjectId;
            newChildRequest.CollectionId = TestData.CollectionId;
            var childObject = await client.New(newChildRequest);

            await client.AddChild(TestData.ProjectId, parentObject.Id, childObject.Id, TestData.CollectionId);

            //when
            var result =
                await
                    client.RemoveChild(TestData.ProjectId, parentObject.Id, childObject.Id,
                        TestData.CollectionId);

            var getResult =
                await
                    client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: parentObject.Id,
                        includeChildren: true);

            //then
            result.ShouldBeTrue();
            getResult.Children.ShouldNotBeEmpty();
            getResult.Children.Count.ShouldEqual(1);
            getResult.Children.Any(d => d.Id == otherObject.Id).ShouldBeTrue();
            getResult.Children.Any(d => d.Id == childObject.Id).ShouldBeFalse();

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task RemoveChild_WithNullChildId_RemovesAllChildren(DataObjectSyncanoClient client)
        {
            //given
            var newParentRequest = new DataObjectDefinitionRequest();
            newParentRequest.ProjectId = TestData.ProjectId;
            newParentRequest.CollectionId = TestData.CollectionId;
            var parentObject = await client.New(newParentRequest);

            var newChildRequest = new DataObjectDefinitionRequest();
            newChildRequest.ProjectId = TestData.ProjectId;
            newChildRequest.CollectionId = TestData.CollectionId;
            var childObject = await client.New(newChildRequest);

            await client.AddChild(TestData.ProjectId, parentObject.Id, childObject.Id, TestData.CollectionId);

            //when
            var result = await client.RemoveChild(TestData.ProjectId, parentObject.Id, collectionId: TestData.CollectionId);

            //then
            result.ShouldBeTrue();

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task RemoveChild_ByCollectionKey(DataObjectSyncanoClient client)
        {
            //given
            var newParentRequest = new DataObjectDefinitionRequest();
            newParentRequest.ProjectId = TestData.ProjectId;
            newParentRequest.CollectionId = TestData.CollectionId;
            var parentObject = await client.New(newParentRequest);

            var newChildRequest = new DataObjectDefinitionRequest();
            newChildRequest.ProjectId = TestData.ProjectId;
            newChildRequest.CollectionId = TestData.CollectionId;
            var childObject = await client.New(newChildRequest);

            await client.AddChild(TestData.ProjectId, parentObject.Id, childObject.Id, TestData.CollectionId);

            //when
            var result =
                await
                    client.RemoveChild(TestData.ProjectId, parentObject.Id, childObject.Id,
                        collectionKey: TestData.CollectionKey);

            var getResult =
                await
                    client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: parentObject.Id,
                        includeChildren: true);

            //then
            result.ShouldBeTrue();
            getResult.Children.ShouldBeNull();

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }