Class with Folder management api.
 public async Task New_WithNullProjectId_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.New(null, TestData.FolderName, TestData.CollectionId);
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentNullException>();
     }
 }
 public async Task New_WithInvalidIdAndKey_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.New(TestData.ProjectId, TestData.FolderName, "abcde", "abcde");
         throw new Exception("New should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
        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 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 Authorize_WithInvalidIdAndKey_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.Authorize(TestData.UserApiClientId, Permissions.DeleteData, TestData.ProjectId,
                 TestData.FolderName, "abcde", "abcde");
         throw new Exception("Authorize should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
 public async Task Update_WithInvalidFolderName_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.Update(TestData.ProjectId, "abcde", TestData.CollectionId);
         throw new Exception("Update should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
        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_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 GetOne_WithInvalidProjectId_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.GetOne("abcde", TestData.FolderName, TestData.CollectionId);
         throw new Exception("GetOne should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
 public async Task GetOne_WithNullFolderName_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.GetOne(TestData.ProjectId, null, TestData.CollectionId);
         throw new Exception("GetOne should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentNullException>();
     }
 }
        public async Task GetOne_ByCollectionKey(FolderSyncanoClient client)
        {
            //when
            var folder = await client.GetOne(TestData.ProjectId, TestData.FolderName, collectionKey: TestData.CollectionKey);

            //then
            folder.Id.ShouldEqual(TestData.FolderId);
            folder.Name.ShouldEqual(TestData.FolderName);
        }
        public async Task Get_ByCollectionKey(FolderSyncanoClient client)
        {
            //when
            var response = await client.Get(TestData.ProjectId, collectionKey: TestData.CollectionKey);

            //then
            response.ShouldNotBeEmpty();
            response.Any(f => f.Name == TestData.FolderName).ShouldBeTrue();
        }
        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 Deauthorize_WithNullFolderName_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.Deauthorize(TestData.UserApiClientId, Permissions.DeleteData, TestData.ProjectId,
                 null, TestData.CollectionId);
         throw new Exception("Deauthorize should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentNullException>();
     }
 }
        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 Deauthorize_WithInvalidUserApiKey_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.Deauthorize("abcde", Permissions.DeleteData, TestData.ProjectId,
                 TestData.FolderName, TestData.CollectionId);
         throw new Exception("Deauthorize should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<SyncanoException>();
     }
 }
 public async Task Update_WithNullIdAndKey_ThrowsException(FolderSyncanoClient client)
 {
     try
     {
         //when
         await client.Update(TestData.ProjectId, TestData.FolderName);
         throw new Exception("Update should throw an exception");
     }
     catch (Exception e)
     {
         //then
         e.ShouldBeType<ArgumentNullException>();
     }
 }
        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_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);
        }