public AddParent ( string projectId, string dataId, string parentId, string collectionId = null, string collectionKey = null, bool removeOther = false ) : Task |
||
projectId | string | Project id. |
dataId | string | Data Object id. |
parentId | string | Parent id to add. |
collectionId | string | Collection id defining collection containing data. |
collectionKey | string | Collection key defining collection containing data. |
removeOther | bool | If true, will remove all other parents. Default value: False. |
Résultat | Task |
public async Task AddParent_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.AddParent(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.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 AddParent_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; await client.New(newChildRequest); try { //when await client.AddParent(TestData.ProjectId, "abc", parentObject.Id, TestData.CollectionId); throw new Exception("AddChild 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); }