public async Task CreateAndDeleteAssetWorkAsExpectedAsync() { // Arrange var externalIdString = Guid.NewGuid().ToString(); var newAsset = new AssetCreate { ExternalId = externalIdString, Name = "Create Assets c# sdk test", Description = "Just a test" }; var deletes = new AssetDelete { Items = new List <Identity>() { Identity.Create(externalIdString) } }; // Act var res = await WriteClient.Assets.CreateAsync(new List <AssetCreate>() { newAsset }); await WriteClient.Assets.DeleteAsync(deletes); // Assert var resCount = res.Count(); Assert.True(1 == resCount, $"Expected 1 created asset but got {resCount}"); Assert.True(externalIdString == res.First().ExternalId, "Created externalId doesnt match expected"); }
/// <summary> /// Delete multiple assets in the same project, along with all their descendants in the asset hierarchy if /// recursive is true. /// </summary> /// <param name="query">The query of assets to delete.</param> /// <param name="token">Optional cancellation token.</param> public async Task <EmptyResponse> DeleteAsync(AssetDelete query, CancellationToken token = default) { if (query is null) { throw new ArgumentNullException(nameof(query)); } var req = Assets.delete <EmptyResponse>(query); return(await RunAsync(req, token).ConfigureAwait(false)); }
/// <summary> /// Delete multiple assets in the same project by external ids. /// </summary> /// <param name="externalIds">The list of assets ids to delete.</param> /// <param name="token">Optional cancellation token.</param> public async Task <EmptyResponse> DeleteAsync(IEnumerable <string> externalIds, CancellationToken token = default) { if (externalIds is null) { throw new ArgumentNullException(nameof(externalIds)); } var query = new AssetDelete() { Items = externalIds.Select(Identity.Create) }; return(await DeleteAsync(query, token).ConfigureAwait(false)); }
/// <summary> /// Delete multiple assets in the same project by identity items. /// </summary> /// <param name="items">The list of assets identities to delete.</param> /// <param name="token">Optional cancellation token.</param> public async Task <EmptyResponse> DeleteAsync(IEnumerable <Identity> items, CancellationToken token = default) { if (items is null) { throw new ArgumentNullException(nameof(items)); } var query = new AssetDelete() { Items = items }; return(await DeleteAsync(query, token).ConfigureAwait(false)); }
public async Task AssetDeleteFailsWhenIdIsInvalidAsync() { // Arrange var id = 0; var caughtException = false; var query = new AssetDelete { Items = new List <Identity> { Identity.Create(id) } }; // Act try { await WriteClient.Assets.DeleteAsync(query); } catch (ResponseException) { caughtException = true; } // Assert Assert.True(caughtException, "Expected request to fail with 'CogniteSdk.ResponseException' but didnt"); }