Beispiel #1
0
        public async Task AddParent_WithNullCollectionIdAndCollectionKey_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);

            try
            {
                //when
                await
                client.AddParent(TestData.ProjectId, childObject.Id, parentObject.Id);

                throw new Exception("AddChild 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 Delete_FilterByImageContent(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);

            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId       = dataObject.Id;
            deleteRequest.Filter       = DataObjectContentFilter.Image;

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

            //then
            try
            {
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId : dataObject.Id);

                throw new Exception("GetOne should throw an exception");
            }
            catch (Exception e)
            {
                e.ShouldBeType <SyncanoException>();
            }

            result.ShouldBeTrue();
        }
        public async Task New_ByCollectionId_WithFolder_CreatesNewDataObject(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 folder = await folderClient.New(TestData.ProjectId, "testFolder", TestData.CollectionId);

            request.Folder = folder.Name;

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

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.Folder.ShouldEqual(folder.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, folder.Name, TestData.CollectionId);
        }
        public async Task New_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 request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Additional   = additionals;

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

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            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 New_ByCollectionId_WithTooBigImageForTcp_ThrowsException()
        {
            //given
            var syncServer = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey);
            await syncServer.Start();

            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;

            var imageBase64 = TestData.ImageToBase64("sampleImage.jpg");

            request.ImageBase64 = imageBase64;

            try
            {
                //when
                await syncServer.DataObjects.New(request);

                throw new Exception("New should throw an exception.");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType <SyncanoException>();
            }
        }
        public async Task New_ByCollectionId_WithDataOneTwoThree_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.DataOne      = -1;
            request.DataTwo      = 1;
            request.DataThree    = 100000;

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

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(request.Folder);
            result.DataOne.ShouldEqual(request.DataOne);
            result.DataTwo.ShouldEqual(request.DataTwo);
            result.DataThree.ShouldEqual(request.DataThree);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();

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

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            var dataObjectOne = await client.New(request);

            var dataObjectTwo = await client.New(request);

            request.State = DataObjectState.Moderated;
            request.State = DataObjectState.Rejected;
            var dataObjectThree = await client.New(request);

            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.State        = DataObjectState.All;

            //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();
        }
        public async Task Delete_FilterByStatePending(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.State        = DataObjectState.Pending;
            var dataObject = await client.New(request);

            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId       = dataObject.Id;
            deleteRequest.State        = DataObjectState.Pending;

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

            //then
            try
            {
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId : dataObject.Id);

                throw new Exception("GetOne should throw an exception");
            }
            catch (Exception e)
            {
                e.ShouldBeType <SyncanoException>();
            }

            result.ShouldBeTrue();
        }
Beispiel #9
0
        public async Task Count_WithSingleFolderName_GetsCountOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();

            dataRequest.ProjectId    = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.Folder       = TestData.FolderName;
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Folder       = TestData.FolderName;

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

            //then
            result.ShouldEqual(1);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.Delete(deleteRequest);
        }
        private DataObjectDefinitionRequest CreateDataDefinitaionRequest(string title, string text, string link,
                                                                         string imagePath, ObservableCollection <AdditionalItem> additionalItems)
        {
            var request = new DataObjectDefinitionRequest();

            request.Title = title;
            request.Text  = text;
            request.Link  = link;

            if (imagePath != "")
            {
                using (var f = new FileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (var ms = new MemoryStream())
                    {
                        f.CopyTo(ms);
                        byte[] imageBytes = ms.ToArray();

                        // Convert byte[] to Base64 String
                        string base64String = Convert.ToBase64String(imageBytes);
                        request.ImageBase64 = base64String;
                    }
                }
            }

            request.Additional = new Dictionary <string, string>();
            foreach (var item in additionalItems)
            {
                request.Additional.Add(item.Key, item.Value);
            }
            return(request);
        }
Beispiel #11
0
        public async Task Get_WithTextContentFilter_GetsListOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();

            dataRequest.ProjectId    = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.Text         = "sample text content";
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Filter       = DataObjectContentFilter.Text;

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

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

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.Delete(deleteRequest);
        }
Beispiel #12
0
        public async Task Get_WithPendingState_GetsListOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();

            dataRequest.ProjectId    = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.State        = DataObjectState.Pending;
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.State        = DataObjectState.Pending;

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

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

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.Delete(deleteRequest);
        }
Beispiel #13
0
        public async Task Count_WithImageContentFilter_GetsCountOfUsers(UserSyncanoClient client)
        {
            //given
            var dataRequest = new DataObjectDefinitionRequest();

            dataRequest.ProjectId    = TestData.ProjectId;
            dataRequest.CollectionId = TestData.CollectionId;
            dataRequest.ImageBase64  = TestData.ImageToBase64("smallSampleImage.png");
            await _dataClient.New(dataRequest);

            var request = new UserQueryRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.Filter       = DataObjectContentFilter.Image;

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

            //then
            result.ShouldEqual(1);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;

            await _dataClient.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 New_ByCollectionId_WithImage_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;

            var imageBase64 = TestData.ImageToBase64("smallSampleImage.png");

            request.ImageBase64 = imageBase64;

            //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 New_ByCollectionId_WithSourceUrl_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.SourceUrl    = "sourceUrl";

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

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

            //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_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.New(request);

                throw new Exception("New should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType <ArgumentException>();
            }
        }
        /// <summary>
        /// Updates an existing Data Object if data with a specified data_id or data_key already exists. Will not delete/empty previously set data but merge it instead with new data.
        /// </summary>
        /// <param name="request">Request for defining new data object properties.</param>
        /// <param name="dataId">Data id. If both id and key are specified, will use id for getting object while data_key will be updated with provided new value. data_key has to be unique within collection.</param>
        /// <returns>Updated DataObject object.</returns>
        public Task <DataObject> Merge(DataObjectDefinitionRequest request, string dataId = null)
        {
            if (request.ProjectId == null)
            {
                throw new ArgumentNullException();
            }

            if (request.CollectionId == null && request.CollectionKey == null)
            {
                throw new ArgumentNullException();
            }

            if (request.Text != null && request.Text.Length > MaxTextLenght)
            {
                throw new ArgumentException();
            }

            if (request.Title != null && request.Title.Length > MaxTitleLenght)
            {
                throw new ArgumentException();
            }

            AssertAditionals(request.Additional);

            return(_syncanoClient.PostAsync <DataObject>("data.update",
                                                         new
            {
                project_id = request.ProjectId,
                collection_id = request.CollectionId,
                collection_key = request.CollectionKey,
                data_id = dataId,
                data_key = request.DataKey,
                update_method = "merge",
                user_name = request.UserName,
                source_url = request.SourceUrl,
                title = request.Title,
                text = request.Text,
                link = request.Link,
                image = request.ImageBase64,
                image_url = request.ImageUrl,
                data1 = request.DataOne,
                data2 = request.DataTwo,
                data3 = request.DataThree,
                folder = request.Folder,
                state = request.State.ToString(),
                parent_id = request.ParentId,
                additionals = request.Additional
            }, "data"));
        }
Beispiel #19
0
        public async Task RemoveParent_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.RemoveParent(TestData.ProjectId, childObject.Id, parentObject.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);
        }
Beispiel #20
0
        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 New_WithNullCollectionIdAndCollectionKey_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId = TestData.ProjectId;

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

                throw new Exception("New should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType <ArgumentNullException>();
            }
        }
        public async Task New_WithInvalidProjectId_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = "abc";
            request.CollectionId = TestData.CollectionId;

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

                throw new Exception("New should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType <SyncanoException>();
            }
        }
        public async Task Delete_ByCollectionKey(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId     = TestData.ProjectId;
            request.CollectionKey = TestData.CollectionKey;
            var dataObject = await client.New(request);

            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId       = dataObject.Id;

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

            //then
            result.ShouldBeTrue();
        }
Beispiel #24
0
        public async Task RemoveParent_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.RemoveParent(TestData.ProjectId, childObject.Id, parentObject.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);
        }
        public async Task Delete_FilterByUserName(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            request.UserName     = TestData.UserName;
            await client.New(request);

            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.ByUser       = TestData.UserName;

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

            //then
            result.ShouldBeTrue();
        }
        public async Task New_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.New(request);

                throw new Exception("New should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType <ArgumentException>();
            }
        }
        public async Task New_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.New(request);

                throw new Exception("New should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType <ArgumentException>();
            }
        }
Beispiel #28
0
        public async Task RemoveParent_WithInvalidProjectId_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.RemoveParent("abc", childObject.Id, parentObject.Id, TestData.CollectionId);

                throw new Exception("RemoveParent 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 Delete_MultipleDataIds_WithLimit(DataObjectSyncanoClient client)
        {
            //given
            int counter = 0;
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            var dataObjectOne = await client.New(request);

            var dataObjectTwo = await client.New(request);

            var dataObjectThree = await client.New(request);

            var dataIds = new List <string> {
                dataObjectTwo.Id, dataObjectThree.Id
            };
            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId       = dataObjectOne.Id;
            deleteRequest.DataIds      = dataIds;
            deleteRequest.Limit        = 2;

            //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)
            {
                if (!(e is SyncanoException))
                {
                    ++counter;
                }
            }

            try
            {
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId : dataObjectTwo.Id);

                throw new Exception("GetOne should throw an exception");
            }
            catch (Exception e)
            {
                if (!(e is SyncanoException))
                {
                    ++counter;
                }
            }

            try
            {
                await client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId : dataObjectThree.Id);

                throw new Exception("GetOne should throw an exception");
            }
            catch (Exception e)
            {
                if (!(e is SyncanoException))
                {
                    ++counter;
                }
            }

            counter.ShouldEqual(1);
            result.ShouldBeTrue();

            //cleanup
            deleteRequest.Limit = 100;
            await client.Delete(deleteRequest);
        }
        public async Task Delete_MultipleDataIds(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();

            request.ProjectId    = TestData.ProjectId;
            request.CollectionId = TestData.CollectionId;
            var dataObjectOne = await client.New(request);

            var dataObjectTwo = await client.New(request);

            var dataObjectThree = await client.New(request);

            var dataIds = new List <string> {
                dataObjectTwo.Id, dataObjectThree.Id
            };
            var deleteRequest = new DataObjectSimpleQueryRequest();

            deleteRequest.ProjectId    = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            deleteRequest.DataId       = dataObjectOne.Id;
            deleteRequest.DataIds      = dataIds;

            //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();
        }