Delete() public method

Permanently delete specified folder and all associated data. The collection_id/collection_key parameter means that one can use either one of them - collection_id or collection_key.
public Delete ( string projectId, string name, string collectionId = null, string collectionKey = null ) : Task
projectId string Project id.
name string Folder name to delete.
collectionId string Collection id defining collection where folder exists.
collectionKey string Collection key defining collection where folder exists.
return Task
        public async Task New_ByCollectionKey(FolderSyncanoClient client)
        {
            //given
            string folderName = "NewFolderTest  " + DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToShortDateString();

            //when
            var folder = await client.New(TestData.ProjectId, folderName,
                collectionKey: TestData.CollectionKey);

            //then
            folder.Id.ShouldNotEqual(null);

            //cleanup
            await client.Delete(TestData.ProjectId, folderName, collectionKey: TestData.CollectionKey);
        }
        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 Delete_ByCollectionKey(FolderSyncanoClient client)
        {
            //given
            string folderName = "Delete test " + DateTime.Now.ToLongTimeString() + " " +
                                DateTime.Now.ToShortDateString();
            await client.New(TestData.ProjectId, folderName, collectionKey: TestData.CollectionKey);

            //when
            var result = await client.Delete(TestData.ProjectId, folderName, collectionKey: TestData.CollectionKey);

            //then
            result.ShouldBeTrue();
        }
        public async Task Deauthorize_ByCollectionKey(FolderSyncanoClient client)
        {
            //given
            string folderName = "Authorize Test " + DateTime.Now.ToLongTimeString() + " " +
                                DateTime.Now.ToShortDateString();

            await client.New(TestData.ProjectId, folderName, collectionKey: TestData.CollectionKey);
            await client.Authorize(TestData.UserApiClientId, Permissions.CreateData, TestData.ProjectId,
                        TestData.FolderName, collectionKey: TestData.CollectionKey);

            //when
            var result = await client.Deauthorize(TestData.UserApiClientId, Permissions.CreateData, TestData.ProjectId,
                        TestData.FolderName, collectionKey: TestData.CollectionKey);

            //then
            result.ShouldBeTrue();

            //cleanup
            await client.Delete(TestData.ProjectId, folderName, collectionKey: TestData.CollectionKey);
        }
        public async Task Update_ByCollectionKey(FolderSyncanoClient client)
        {
            //given
            string folderName = "Test " + DateTime.Now.ToLongTimeString() + " " +
                                DateTime.Now.ToShortDateString();
            string newFolderName = "Update test " + DateTime.Now.ToLongTimeString() + " " +
                                DateTime.Now.ToShortDateString();
            await client.New(TestData.ProjectId, folderName, TestData.CollectionId);

            //when
            var result = await client.Update(TestData.ProjectId, folderName, null, TestData.CollectionKey, newFolderName,
                        "qwerty");

            //then
            result.ShouldBeTrue();

            //cleanup
            await client.Delete(TestData.ProjectId, newFolderName, collectionKey: TestData.CollectionKey);
        }
 public async Task Delete_WithInvalidFolderName_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.Delete(TestData.ProjectId, "abcde", TestData.CollectionId);
         throw new Exception("Delete should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
 public async Task Delete_WithNullProjectId_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.Delete(null, TestData.FolderName, TestData.CollectionId);
         throw new Exception("Delete should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentNullException>();
     }
 }
        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);
        }
        public async Task Count_ByCollectionId_MultipleDataObjects_FilterByFoldersUsingFolderAndFoldersList(DataObjectSyncanoClient client)
        {
            //given
            var folderClient =
                new FolderSyncanoClient(new SyncanoHttpClient(TestData.InstanceName, TestData.BackendAdminApiKey));
            var folderOne =
                await folderClient.New(TestData.ProjectId, "folderOne", collectionId: TestData.CollectionId);
            var folderTwo =
                await folderClient.New(TestData.ProjectId, "folderTwo", collectionId: TestData.CollectionId);
            var folderThree =
                await folderClient.New(TestData.ProjectId, "foldeThree", collectionId: TestData.CollectionId);

            var count = 15;
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;

            request.Folder = folderOne.Name;

            for (int i = 0; i < count; ++i)
                await client.New(request);

            request.Folder = folderTwo.Name;

            for (int i = 0; i < count; ++i)
                await client.New(request);

            request.Folder = folderThree.Name;

            for (int i = 0; i < count; ++i)
                await client.New(request);

            var countRequest = new CountDataObjectRequest();
            countRequest.ProjectId = TestData.ProjectId;
            countRequest.CollectionId = TestData.CollectionId;
            countRequest.Folders = new List<string> { folderOne.Name };
            countRequest.Folder = folderTwo.Name;

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

            //then
            result.ShouldEqual(2 * count);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
            await folderClient.Delete(TestData.ProjectId, folderOne.Name, TestData.CollectionId);
            await folderClient.Delete(TestData.ProjectId, folderTwo.Name, TestData.CollectionId);
            await folderClient.Delete(TestData.ProjectId, folderThree.Name, TestData.CollectionId);
        }
        public async Task Delete_MultipleFolders(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            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 folderThree = await folderClient.New(TestData.ProjectId, "folderThree", TestData.CollectionId);
            request.Folder = folderOne.Name;
            var dataObjectOne = await client.New(request);
            request.Folder = folderTwo.Name;
            var dataObjectTwo = await client.New(request);
            request.Folder = folderThree.Name;
            var dataObjectThree = await client.New(request);

            var folders = new List<string> { folderOne.Name, folderTwo.Name };
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.Folders = folders;
            deleteRequest.Folder = folderThree.Name;

            //when
            var result = await client.Delete(deleteRequest);

            //then
            try
            {
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: dataObjectOne.Id);
                throw new Exception("GetOne should throw an exception");
            }
            catch (Exception e)
            {
                e.ShouldBeType<SyncanoException>();
            }

            try
            {
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: dataObjectTwo.Id);
                throw new Exception("GetOne should throw an exception");
            }
            catch (Exception e)
            {
                e.ShouldBeType<SyncanoException>();
            }

            try
            {
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: dataObjectThree.Id);
                throw new Exception("GetOne should throw an exception");
            }
            catch (Exception e)
            {
                e.ShouldBeType<SyncanoException>();
            }

            result.ShouldBeTrue();

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