Updated voice work delete logic + tests.
This commit is contained in:
@@ -23,8 +23,10 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter
|
|||||||
Dictionary<int, DeleteVoiceWorkStatus> results = request.VoiceWorkIds.Select(x => x)
|
Dictionary<int, DeleteVoiceWorkStatus> results = request.VoiceWorkIds.Select(x => x)
|
||||||
.ToDictionary(x => x, x => DeleteVoiceWorkStatus.NotFound);
|
.ToDictionary(x => x, x => DeleteVoiceWorkStatus.NotFound);
|
||||||
|
|
||||||
VoiceWork[] voiceWorks = [.. dbContext.VoiceWorks.Where(voiceWork => request.VoiceWorkIds.Contains(voiceWork.VoiceWorkId))
|
VoiceWork[] voiceWorks = await dbContext.VoiceWorks
|
||||||
.Include(x => x.Circle)];
|
.Where(voiceWork => request.VoiceWorkIds.Contains(voiceWork.VoiceWorkId))
|
||||||
|
.Include(x => x.Circle)
|
||||||
|
.ToArrayAsync(cancellationToken);
|
||||||
|
|
||||||
List<VoiceWork> voiceWorksToDelete = [];
|
List<VoiceWork> voiceWorksToDelete = [];
|
||||||
|
|
||||||
|
|||||||
@@ -49,4 +49,25 @@ public class Delete_Voice_Work_Tests(MariaDbContainerFixture container) : VoiceW
|
|||||||
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
|
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
|
||||||
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
|
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Try_Delete_Missing_Voice_Work()
|
||||||
|
{
|
||||||
|
await using AppDbContext dbContext = await GetAppDbContextAsync();
|
||||||
|
VoiceWorkWriter writer = new(dbContext);
|
||||||
|
|
||||||
|
int voiceWorkId = 999;
|
||||||
|
DeleteVoiceWorkRequest request = new([voiceWorkId]);
|
||||||
|
|
||||||
|
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
|
||||||
|
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
|
||||||
|
|
||||||
|
DeleteVoiceWorkResponse response = await writer.DeleteAsync(request, TestContext.Current.CancellationToken);
|
||||||
|
response.Results.Count.ShouldBe(1);
|
||||||
|
response.Results.ShouldContainKey(voiceWorkId);
|
||||||
|
response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.NotFound);
|
||||||
|
|
||||||
|
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
|
||||||
|
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user