diff --git a/src/CrowdParlay.Social.Infrastructure.Persistence/Services/DiscussionsRepository.cs b/src/CrowdParlay.Social.Infrastructure.Persistence/Services/DiscussionsRepository.cs index ad29021..abbe333 100644 --- a/src/CrowdParlay.Social.Infrastructure.Persistence/Services/DiscussionsRepository.cs +++ b/src/CrowdParlay.Social.Infrastructure.Persistence/Services/DiscussionsRepository.cs @@ -59,8 +59,8 @@ public async Task> GetAllAsync() } """); - var record = await data.SingleAsync(); - return record[0].Adapt>(); + var records = await data.ToListAsync(); + return records.Select(x => x[0]).Adapt>(); }); } @@ -85,8 +85,8 @@ public async Task> GetByAuthorAsync(Guid authorId) } """, new { authorId = authorId.ToString() }); - var record = await data.SingleAsync(); - return record[0].Adapt>(); + var records = await data.ToListAsync(); + return records.Select(x => x[0]).Adapt>(); }); } diff --git a/tests/CrowdParlay.Social.IntegrationTests/Tests/DiscussionsRepositoryTests.cs b/tests/CrowdParlay.Social.IntegrationTests/Tests/DiscussionsRepositoryTests.cs new file mode 100644 index 0000000..08e83cc --- /dev/null +++ b/tests/CrowdParlay.Social.IntegrationTests/Tests/DiscussionsRepositoryTests.cs @@ -0,0 +1,54 @@ +namespace CrowdParlay.Social.IntegrationTests.Tests; + +public class DiscussionsRepositoryTests(WebApplicationContext context) : IClassFixture +{ + private readonly IServiceProvider _services = context.Services; + + [Fact(DisplayName = "Get discussions by author")] + public async Task GetDiscussionsByAuthor() + { + // Arrange + await using var scope = _services.CreateAsyncScope(); + var authors = scope.ServiceProvider.GetRequiredService(); + var discussions = scope.ServiceProvider.GetRequiredService(); + + var author = await authors.CreateAsync( + id: Guid.NewGuid(), + username: "compartmental", + displayName: "Степной ишак", + avatarUrl: null); + + DiscussionDto[] expected = + [ + await discussions.CreateAsync(author.Id, "Discussion 1", "bla bla bla"), + await discussions.CreateAsync(author.Id, "Discussion 2", "numa numa e") + ]; + + // Act + var response = await discussions.GetByAuthorAsync(author.Id); + + // Assert + response.Should().BeEquivalentTo(expected); + } + + [Fact(DisplayName = "Get discussions by author of no discussions")] + public async Task GetNoDiscussionsByAuthor() + { + // Arrange + await using var scope = _services.CreateAsyncScope(); + var authors = scope.ServiceProvider.GetRequiredService(); + var discussions = scope.ServiceProvider.GetRequiredService(); + + var author = await authors.CreateAsync( + id: Guid.NewGuid(), + username: "compartmental", + displayName: "Степной ишак", + avatarUrl: null); + + // Act + var response = await discussions.GetByAuthorAsync(author.Id); + + // Assert + response.Should().BeEmpty(); + } +} \ No newline at end of file