From 2aa181525054d6d220c3c31cd4289e944005f1f5 Mon Sep 17 00:00:00 2001 From: forsthug <85173816+forsthug@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:21:41 +0200 Subject: [PATCH] fix np --- .../AzureTableStorageQueueItemRepository.cs | 7 ++++++- .../AbstractQueueItemRepositoryTests.cs | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/queue/src/fiskaltrust.Middleware.Storage.AzureTableStorage/Repositories/AzureTableStorageQueueItemRepository.cs b/queue/src/fiskaltrust.Middleware.Storage.AzureTableStorage/Repositories/AzureTableStorageQueueItemRepository.cs index db260e282..5e475286a 100644 --- a/queue/src/fiskaltrust.Middleware.Storage.AzureTableStorage/Repositories/AzureTableStorageQueueItemRepository.cs +++ b/queue/src/fiskaltrust.Middleware.Storage.AzureTableStorage/Repositories/AzureTableStorageQueueItemRepository.cs @@ -210,7 +210,12 @@ public async Task CountAsync() public async Task GetLastQueueItemAsync() { var result = _tableClient.QueryAsync(select: new string[] { "PartitionKey", "RowKey" }); - var lastEntity = await result.FirstAsync(); + var lastEntity = await result.FirstOrDefaultAsync(); + + if (lastEntity == null) + { + return null; + } return MapToStorageEntity(await _tableClient.GetEntityAsync(lastEntity.PartitionKey, lastEntity.RowKey)); } diff --git a/queue/test/fiskaltrust.Middleware.Storage.AcceptanceTest/AbstractQueueItemRepositoryTests.cs b/queue/test/fiskaltrust.Middleware.Storage.AcceptanceTest/AbstractQueueItemRepositoryTests.cs index 617dbb703..c99440152 100644 --- a/queue/test/fiskaltrust.Middleware.Storage.AcceptanceTest/AbstractQueueItemRepositoryTests.cs +++ b/queue/test/fiskaltrust.Middleware.Storage.AcceptanceTest/AbstractQueueItemRepositoryTests.cs @@ -49,6 +49,16 @@ public async Task GetLastQueueItem_ShouldReturnLastQueueItem() last.ftQueueItemId.Should().Be(entries.Last().ftQueueItemId); } + [Fact] + public async Task GetLastQueueItem_NoEntries_ShouldNull() + { + var entries = new List(); + var sut = await CreateRepository(entries); + + var last = await sut.GetLastQueueItemAsync(); + last.Should().BeNull(); + } + [Fact] public async Task GetAsync_ShouldReturnAllEntriesThatExistInRepository() {