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

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.
public Merge ( DataObjectDefinitionRequest request, string dataId = null ) : Task
request Syncano.Net.DataRequests.DataObjectDefinitionRequest Request for defining new data object properties.
dataId string 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.
Результат Task
        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_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 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 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 Merge_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.Merge(request);
                throw new Exception("Merge should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task Merge_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.Merge(request);
                throw new Exception("Merge should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task Merge_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.Merge(request);
                throw new Exception("Merge should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentException>();
            }
        }
        public async Task Merge_WithNullCollectionIdAndKey_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var request = new DataObjectDefinitionRequest();
            request.ProjectId = TestData.ProjectId;

            try
            {
                //when
                await client.Merge(request, "dataId");
                throw new Exception("Merge should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<ArgumentNullException>();
            }
        }
        public async Task Merge_ByCollectionId_WithFolderName_CreatesNewDataObject(DataObjectSyncanoClient client)
        {
            //given
            var link = "custom link";
            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;
            request.Link = link;
            var dataObject = await client.New(request);

            request.Folder = newFolder.Name;
            request.Link = null;

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

            //then
            result.ShouldNotBeNull();
            result.Folder.ShouldEqual(newFolder.Name);
            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);
            await folderClient.Delete(TestData.ProjectId, newFolder.Name, TestData.CollectionId);
        }