From 1e16fedbeea119265169a794abdcde370f514233 Mon Sep 17 00:00:00 2001 From: medevod Date: Mon, 20 Nov 2023 17:25:20 +0100 Subject: [PATCH] PR EntityTAble Client Fixes/entitytable client delete one (#64) * Update AzureNativeTableClient.cs * Update EntityTableClientWritingTests.cs --- .../Implementations/AzureNativeTableClient.cs | 8 +++-- .../Table/EntityTableClientWritingTests.cs | 31 ++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Azure.EntityServices.Tables/Core/Implementations/AzureNativeTableClient.cs b/src/Azure.EntityServices.Tables/Core/Implementations/AzureNativeTableClient.cs index d299a6e..f30ef51 100644 --- a/src/Azure.EntityServices.Tables/Core/Implementations/AzureNativeTableClient.cs +++ b/src/Azure.EntityServices.Tables/Core/Implementations/AzureNativeTableClient.cs @@ -1,4 +1,4 @@ -using Azure.Data.Tables; +using Azure.Data.Tables; using Azure.EntityServices.Queries; using Azure.EntityServices.Tables.Core.Abstractions; using Azure.EntityServices.Tables.Extensions; @@ -126,6 +126,10 @@ public Task SubmitOneOperation(EntityOperation entityOperation, CancellationToke await _tableClient.UpsertEntityAsync(nativeEntity, mode: TableUpdateMode.Merge, cancellationToken: cancellationToken); break; + case EntityOperationType.Delete: + await _tableClient.DeleteAsync(); + break; + default: throw new NotSupportedException(nameof(entityOperation.EntityOperationType)); } }); @@ -146,4 +150,4 @@ public Task SubmitTransaction(IEnumerable entityOperations, Can ), cancellationToken)); } } -} \ No newline at end of file +} diff --git a/tests/Azure.EntityServices.Tests/Table/EntityTableClientWritingTests.cs b/tests/Azure.EntityServices.Tests/Table/EntityTableClientWritingTests.cs index 1c8d543..a10451a 100644 --- a/tests/Azure.EntityServices.Tests/Table/EntityTableClientWritingTests.cs +++ b/tests/Azure.EntityServices.Tests/Table/EntityTableClientWritingTests.cs @@ -1,4 +1,4 @@ -using Azure.Data.Tables; +using Azure.Data.Tables; using Azure.EntityServices.Queries; using Azure.EntityServices.Tables; using Azure.EntityServices.Tables.Extensions; @@ -504,7 +504,6 @@ await tableEntity.UpdateManyAsync(person => result.Should().HaveCount(130 + 1000); result.All(person => person.LastName.EndsWith("_updated")).Should().BeTrue(); - } [TestMethod] @@ -533,7 +532,6 @@ public async Task Should_Update_Many_Indexed_Entities_With_No_Existing_Entities( updated.Should().Be(0); } - [TestMethod] public async Task Should_Store_Default_DateTime_Values() { @@ -790,13 +788,36 @@ public async Task Should_Delete_Entity() var persons = Fakers.CreateFakePerson().Generate(1); var person = persons.First(); + var entityTable = EntityTableClient.Create(TestEnvironment.ConnectionString) + .Configure(options => _defaultOptions(options), c => + { + c. + SetPartitionKey(p => p.TenantId) + .SetRowKeyProp(p => p.PersonId); + }); + await entityTable.AddAsync(person); + + var isDeleted = await entityTable.DeleteAsync(person); + + var deleted = await entityTable.GetByIdAsync(person.TenantId, person.PersonId); + + isDeleted.Should().BeTrue(); + deleted.Should().BeNull(); + } + + [TestMethod] + public async Task Should_Delete_Entity_WithTags() + { + var persons = Fakers.CreateFakePerson().Generate(1); + var person = persons.First(); + var entityTable = EntityTableClient.Create(TestEnvironment.ConnectionString) .Configure(options => _defaultOptions(options), c => { c. SetPartitionKey(p => p.TenantId) .SetRowKeyProp(p => p.PersonId) - .AddTag(p => p.LastName) + .AddTag(p => p.LastName) .AddTag(p => p.Created); }); await entityTable.AddAsync(person); @@ -935,4 +956,4 @@ public void Should_Throw_Exception_When_Adding_Invalid_Keys() .WithMessage("Given primaryKey is null"); } } -} \ No newline at end of file +}