Class with DataObject management api.
        public async Task AddChild_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);

            //when
            var result =
                await
                    client.AddChild(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.ShouldNotBeEmpty();
            getResult.Children[0].Id.ShouldEqual(childObject.Id);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task Get_ByCollectionId_WithStateModerated(DataObjectSyncanoClient client)
        {
            //given
            var newRequest = new DataObjectDefinitionRequest();
            newRequest.ProjectId = TestData.ProjectId;
            newRequest.CollectionId = TestData.CollectionId;
            newRequest.State = DataObjectState.Moderated;
            var dataObject = await client.New(newRequest);

            var getRequest = new DataObjectRichQueryRequest();
            getRequest.ProjectId = TestData.ProjectId;
            getRequest.CollectionId = TestData.CollectionId;
            getRequest.State = DataObjectState.Moderated;

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

            //then
            result.ShouldNotBeNull();
            result.Any(d => d.Id == dataObject.Id).ShouldBeTrue();

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

            request.UserName = TestData.UserName;

            //when
            var result = await client.Update(request, dataObject.Id);

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.User.Name.ShouldEqual(request.UserName);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
        }
        public async Task New_ByCollectionKey_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionKey = TestData.CollectionKey;

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

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
        }
        public async Task Get_Data2_OrderBy(DataObjectSyncanoClient client)
        {
            //given
            var newData1 = new DataObjectDefinitionRequest();
            newData1.ProjectId = TestData.ProjectId;
            newData1.CollectionId = TestData.CollectionId;
            newData1.DataTwo = 1;

            var newData2 = new DataObjectDefinitionRequest();
            newData2.ProjectId = TestData.ProjectId;
            newData2.CollectionId = TestData.CollectionId;
            newData2.DataTwo = 2;

            var dataObject1 = await client.New(newData1);
            var dataObject2 = await client.New(newData2);

            var getRequest = new DataObjectRichQueryRequest();
            getRequest.ProjectId = TestData.ProjectId;
            getRequest.CollectionId = TestData.CollectionId;
            getRequest.OrderBy = DataObjectOrderBy.DataOne;
            getRequest.Order = DataObjectOrder.Ascending;
            getRequest.AddDataFieldFilter(DataObjectSpecialField.DataTwo, DataObjectOperator.LowerThanOrEquals, 2);
            getRequest.AddDataFieldFilter(DataObjectSpecialField.DataTwo, DataObjectOperator.GreaterThanOrEquals, 1);

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

            //then
            result.ShouldNotBeNull();
            result.Count.ShouldEqual(2);
            result[0].Id.ShouldEqual(dataObject1.Id);
            result[1].Id.ShouldEqual(dataObject2.Id);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task Update_ByCollectionId_DeleteImage_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.ImageBase64 = TestData.ImageToBase64("smallSampleImage.png");
            var dataObject = await client.New(request);

            request.ImageBase64 = null;

            //when
            var result = await client.Update(request, dataObject.Id);

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.Image.ShouldBeNull();

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
        }
        public async Task Update_ByCollectionId_WithFolderName_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var folderClient =
                new FolderSyncanoClient(new SyncanoHttpClient(TestData.InstanceName, TestData.BackendAdminApiKey));
            var newFolder = await folderClient.New(TestData.ProjectId, "NewFolder", TestData.CollectionId);
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            var dataObject = await client.New(request);
            await client.New(request);

            request.Folder = newFolder.Name;

            //when
            var result = await client.Update(request, dataObject.Id);

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(newFolder.Name);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
            await folderClient.Delete(TestData.ProjectId, newFolder.Name, TestData.CollectionId);
        }
        public async Task Merge_ByCollectionId_WithStateModerated_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var link = "custom link";
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Link = link;
            var dataObject = await client.New(request);

            request.State = DataObjectState.Moderated;
            request.Link = null;

            //when
            var result = await client.Merge(request, dataObject.Id);

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.State.ShouldEqual(request.State);
            result.Link.ShouldEqual(link);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
        }
 public async Task GetOne_WithToBigLimit_ThrowsException(DataObjectSyncanoClient client)
 {
     try
     {
         //when
         await client.GetOne(TestData.ProjectId, collectionId: TestData.CollectionId, childrenLimit: DataObjectSyncanoClient.MaxVauluesPerRequest + 1);
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentException>();
     }
 }
 public async Task GetOne_WithNullCollectionIdAndCollectionKey_ThrowsException(DataObjectSyncanoClient client)
 {
     try
     {
         //when
         await client.GetOne(TestData.ProjectId);
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentNullException>();
     }
 }
        public async Task Merge_ByCollectionId_WithLink_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var title = "title";
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Title = title;
            var dataObject = await client.New(request);

            request.Link = "dataObject link";
            request.Title = null;

            //when
            var result = await client.Merge(request, dataObject.Id);

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.Link.ShouldEqual(request.Link);
            result.Title.ShouldEqual(title);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
        }
        public async Task Copy_WithNullProjectId_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            var dataObject = await client.New(request);

            var copyRequest = new CopyDataObjectRequest();
            copyRequest.ProjectId = null;
            copyRequest.CollectionId = TestData.CollectionId;
            copyRequest.DataId = dataObject.Id;

            try
            {
                //when
                await client.Copy(copyRequest);
                throw new Exception("New should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentNullException>();
            }

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task Update_WithTooLongAdditionalValue_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Additional = new Dictionary<string, string>();
            request.Additional.Add("additional key", new String('a', DataObjectSyncanoClient.MaxAdditionalValueLenght + 1));

            try
            {
                //when
                await client.Update(request);
                throw new Exception("Update should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task Copy_ByCollectionId_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            var dataObject = await client.New(request);
            var copyRequest = new CopyDataObjectRequest();
            copyRequest.ProjectId = TestData.ProjectId;
            copyRequest.CollectionId = TestData.CollectionId;
            copyRequest.DataId = dataObject.Id;

            //when
            var result = await client.Copy(copyRequest);

            //then
            result.ShouldNotBeNull();
            result[0].Folder.ShouldEqual(request.Folder);
            result[0].Id.ShouldNotEqual(dataObject.Id);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task Copy_DataIdsListAndDataIdUsed_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            var dataObject = await client.New(request);
            var dataIds = new List<string>();
            dataIds.Add(dataObject.Id);
            dataObject = await client.New(request);
            
            var copyRequest = new CopyDataObjectRequest();
            copyRequest.ProjectId = TestData.ProjectId;
            copyRequest.CollectionId = TestData.CollectionId;
            copyRequest.DataIds = dataIds;
            copyRequest.DataId = dataObject.Id;

            //when
            var result = await client.Copy(copyRequest);

            //then
            result.ShouldNotBeNull();
            result.Count.ShouldEqual(2);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task Move_WithToMuchFolders_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectSimpleQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Folders = new List<string>();
            for (int i = 0; i < DataObjectSyncanoClient.MaxVauluesPerRequest; ++i)
                request.Folders.Add("abc");
            request.Folder = "abc";

            try
            {
                //when
                await client.Move(request);
                throw new Exception("Move should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task Move_WithToBigLimit_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectSimpleQueryRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Limit = DataObjectSyncanoClient.MaxVauluesPerRequest + 1;

            try
            {
                //when
                await client.Move(request);
                throw new Exception("Move should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task Move_WithNullCollectionIdAndCollectionKey_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectSimpleQueryRequest();
            request.ProjectId = TestData.ProjectId;

            try
            {
                //when
                await client.Move(request);
                throw new Exception("Move should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentNullException>();
            }
        }
        public async Task Update_WithNullCollectionIdAndKey_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;

            try
            {
                //when
                await client.Update(request, "dataId");
                throw new Exception("Update should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentNullException>();
            }
        }
        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 Update_WithTooMuchAdditionals_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Additional = new Dictionary<string, string>();
            for (int i = 0; i < DataObjectSyncanoClient.MaxAdditionalsCount + 5; ++i)
                request.Additional.Add(i.ToString(CultureInfo.InvariantCulture), "additional value");

            try
            {
                //when
                await client.Update(request);
                throw new Exception("Update should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
 public async Task GetOne_WithInvalidProjectId_ThrowsException(DataObjectSyncanoClient client)
 {
     try
     {
         //when
         await client.GetOne("abc", collectionId: TestData.CollectionId);
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
        public async Task Update_WithTooLongText_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Text = new String('a', DataObjectSyncanoClient.MaxTextLenght + 1);

            try
            {
                //when
                await client.Update(request);
                throw new Exception("Update should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task GetOne_ByCollectionId_IncludeChildren_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;

            var parentRequest = new DataObjectDefinitionRequest();
            parentRequest.ProjectId = TestData.ProjectId;
            parentRequest.CollectionId = TestData.CollectionId;
            var parentResult = await client.New(parentRequest);

            request.ParentId = parentResult.Id;
            var childResult = await client.New(request);

            //when
            var result =
                await
                    client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: parentResult.Id,
                        includeChildren: true);

            //then
            result.ShouldNotBeNull();
            result.Id.ShouldEqual(parentResult.Id);
            result.Children.ShouldNotBeEmpty();
            result.Children.Any(d => d.Id == childResult.Id).ShouldBeTrue();

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

            var parentDeleteRequest = new DataObjectSimpleQueryRequest();
            parentDeleteRequest.ProjectId = TestData.ProjectId;
            parentDeleteRequest.CollectionId = TestData.CollectionId;
            parentDeleteRequest.DataId = parentResult.Id;
            await client.Delete(parentDeleteRequest);
        }
        public async Task Merge_ByCollectionId_WithAdditionals_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var additionals = new Dictionary<string, string>();
            additionals.Add("param1", "value1");
            additionals.Add("param2", "value2");
            additionals.Add("param3", "value3");
            var link = "custom link";
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Link = link;
            var dataObject = await client.New(request);

            request.Link = null;
            request.Additional = additionals;

            //when
            var result = await client.Merge(request, dataObject.Id);

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.Link.ShouldEqual(link);
            result.Additional.ShouldNotBeNull();
            result.Additional.Count.ShouldEqual(additionals.Count);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
        }
        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 Merge_ByCollectionId_WithImage_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var link = "custom link";
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Link = link;
            var dataObject = await client.New(request);

            request.ImageBase64 = TestData.ImageToBase64("smallSampleImage.png");
            request.Link = null;

            //when
            var result = await client.Merge(request, dataObject.Id);

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.Image.ShouldNotBeNull();
            result.Image.ImageWidth.ShouldEqual(300);
            result.Image.ImageHeight.ShouldEqual(300);
            result.Link.ShouldEqual(link);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId = result.Id;
            await client.Delete(deleteRequest);
        }
        public async Task Merge_WithInvalidCollectionId_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = "abcde";

            try
            {
                //when
                await client.Merge(request, "dataId");
                throw new Exception("Merge should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<SyncanoException>();
            }
        }
        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 Move_ByCollectionKey_WithFolderAndState(DataObjectSyncanoClient client)
        {
            //given
            var folderClient =
                new FolderSyncanoClient(new SyncanoHttpClient(TestData.InstanceName, TestData.BackendAdminApiKey));
            var folderOne = await folderClient.New(TestData.ProjectId, "folderOne", TestData.CollectionId);
            var folderTwo = await folderClient.New(TestData.ProjectId, "folderTwo", TestData.CollectionId);
            var newRequest = new DataObjectDefinitionRequest();
            newRequest.ProjectId = TestData.ProjectId;
            newRequest.CollectionKey = TestData.CollectionKey;
            newRequest.Folder = folderOne.Name;
            newRequest.State = DataObjectState.Pending;
            var dataObject = await client.New(newRequest);

            var moveRequest = new DataObjectSimpleQueryRequest();
            moveRequest.ProjectId = TestData.ProjectId;
            moveRequest.CollectionKey = TestData.CollectionKey;
            moveRequest.DataId = dataObject.Id;

            //when
            var result = await client.Move(moveRequest, folderTwo.Name, DataObjectState.Moderated);
            var resultObject =
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: dataObject.Id);

            //then
            result.ShouldBeTrue();
            resultObject.Folder.ShouldEqual(folderTwo.Name);

            //cleanup
            await client.Delete(moveRequest);
            await folderClient.Delete(TestData.ProjectId, folderOne.Name, TestData.CollectionId);
            await folderClient.Delete(TestData.ProjectId, folderTwo.Name, TestData.CollectionId);
        }