From 45a8c8be5a1809a93301d440b3c04858e65da47d Mon Sep 17 00:00:00 2001 From: Brian Bicknell Date: Tue, 31 Mar 2026 00:43:02 -0400 Subject: [PATCH] Added voice work repository tests. --- .../VoiceWorks/VoiceWorkWriter.cs | 1 - .../VoiceWorks/Set_Is_Favorite_Tests.cs | 45 +++++++++++++++++++ .../VoiceWorks/VoiceWorkRepositorySeedData.cs | 31 +++++++++++++ .../VoiceWorks/VoiceWorkRepositoryTests.cs | 15 +++++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 JSMR.Tests/Data/Repositories/VoiceWorks/Set_Is_Favorite_Tests.cs create mode 100644 JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositorySeedData.cs create mode 100644 JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositoryTests.cs diff --git a/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs b/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs index a6c2de7..db80b04 100644 --- a/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs +++ b/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs @@ -1,7 +1,6 @@ using JSMR.Application.VoiceWorks.Commands.SetFavorite; using JSMR.Application.VoiceWorks.Ports; using JSMR.Domain.Entities; -using JSMR.Infrastructure.Common.Time; using Microsoft.EntityFrameworkCore; namespace JSMR.Infrastructure.Data.Repositories.VoiceWorks; diff --git a/JSMR.Tests/Data/Repositories/VoiceWorks/Set_Is_Favorite_Tests.cs b/JSMR.Tests/Data/Repositories/VoiceWorks/Set_Is_Favorite_Tests.cs new file mode 100644 index 0000000..f0bf0ce --- /dev/null +++ b/JSMR.Tests/Data/Repositories/VoiceWorks/Set_Is_Favorite_Tests.cs @@ -0,0 +1,45 @@ +using JSMR.Application.VoiceWorks.Commands.SetFavorite; +using JSMR.Domain.Entities; +using JSMR.Infrastructure.Data; +using JSMR.Infrastructure.Data.Repositories.VoiceWorks; +using JSMR.Tests.Fixtures; +using Microsoft.EntityFrameworkCore; +using Shouldly; + +namespace JSMR.Tests.Data.Repositories.VoiceWorks; + +public class Set_Is_Favorite_Tests(MariaDbContainerFixture container) : VoiceWorkRepositoryTests(container) +{ + [Fact] + public async Task Set_Is_Favorite() + { + await using AppDbContext dbContext = await GetAppDbContextAsync(); + VoiceWorkWriter writer = new(dbContext); + + await SetFavoriteAndVerifyAsync(dbContext, writer, 1, true); + await SetFavoriteAndVerifyAsync(dbContext, writer, 1, true); + await SetFavoriteAndVerifyAsync(dbContext, writer, 1, false); + await SetFavoriteAndVerifyAsync(dbContext, writer, 1, false); + await SetFavoriteAndVerifyAsync(dbContext, writer, 1, true); + await SetFavoriteAndVerifyAsync(dbContext, writer, 1, false); + } + + private static async Task SetFavoriteAndVerifyAsync(AppDbContext dbContext, VoiceWorkWriter writer, int voiceWorkId, bool isFavorite) + { + SetVoiceWorkFavoriteRequest request = new( + VoiceWorkId: voiceWorkId, + IsFavorite: isFavorite + ); + + SetVoiceWorkFavoriteResponse response = await writer.SetFavoriteAsync(request, TestContext.Current.CancellationToken); + + response.VoiceWorkId.ShouldBe(voiceWorkId); + response.IsFavorite.ShouldBe(isFavorite); + + VoiceWork? voiceWork = await dbContext.VoiceWorks + .SingleAsync(v => v.VoiceWorkId == voiceWorkId, TestContext.Current.CancellationToken); + + voiceWork.ShouldNotBeNull(); + voiceWork.Favorite.ShouldBe(isFavorite); + } +} \ No newline at end of file diff --git a/JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositorySeedData.cs b/JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositorySeedData.cs new file mode 100644 index 0000000..ab89cc5 --- /dev/null +++ b/JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositorySeedData.cs @@ -0,0 +1,31 @@ +using JSMR.Domain.Enums; +using JSMR.Infrastructure.Data; +using Microsoft.EntityFrameworkCore; + +namespace JSMR.Tests.Data.Repositories.VoiceWorks; + +public static class VoiceWorkRepositorySeedData +{ + public static async Task SeedAsync(AppDbContext context) + { + if (await context.VoiceWorks.AnyAsync()) + return; + + context.Circles.AddRange( + new() { CircleId = 1, Name = "Good Dreams", MakerId = "RG00001" }, + new() { CircleId = 2, Name = "Sweet Dreams", Favorite = true, MakerId = "RG00002" }, + new() { CircleId = 3, Name = "Nightmare Fuel", Blacklisted = true, MakerId = "RG00003" }, + new() { CircleId = 4, Name = "Never Again", Spam = true, MakerId = "RG00004" } + ); + + context.VoiceWorks.AddRange( + new() { VoiceWorkId = 1, CircleId = 1, ProductId = "RJ0000001", ProductName = "Today Sounds", Description = "An average product.", Status = (byte)VoiceWorkStatus.Available, SalesDate = new(2025, 1, 1), Downloads = 500, WishlistCount = 750, StarRating = 35 }, + new() { VoiceWorkId = 2, CircleId = 2, ProductId = "RJ0000002", ProductName = "Super Comfy ASMR", Description = "An amazing product!", Status = (byte)VoiceWorkStatus.NewRelease, SalesDate = new(2025, 1, 3), Downloads = 5000, WishlistCount = 12000, StarRating = 50, Favorite = true }, + new() { VoiceWorkId = 3, CircleId = 3, ProductId = "RJ0000003", ProductName = "Low Effort", Description = "A bad product.", Status = (byte)VoiceWorkStatus.Available, SalesDate = new(2025, 1, 2), Downloads = 50, WishlistCount = 100, StarRating = 20 }, + new() { VoiceWorkId = 4, CircleId = 1, ProductId = "RJ0000004", ProductName = "Tomorrow Sounds", Description = "A average upcoming product.", Status = (byte)VoiceWorkStatus.Upcoming, ExpectedDate = new(2025, 1, 1), WishlistCount = 300 }, + new() { VoiceWorkId = 5, CircleId = 2, ProductId = "RJ0000005", ProductName = "Super Comfy ASMR+", Description = "All your favorite sounds, plus more!", Status = (byte)VoiceWorkStatus.NewAndUpcoming, ExpectedDate = new(2025, 1, 11), WishlistCount = 10000 } + ); + + await context.SaveChangesAsync(); + } +} \ No newline at end of file diff --git a/JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositoryTests.cs b/JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositoryTests.cs new file mode 100644 index 0000000..ffed7ac --- /dev/null +++ b/JSMR.Tests/Data/Repositories/VoiceWorks/VoiceWorkRepositoryTests.cs @@ -0,0 +1,15 @@ +using JSMR.Infrastructure.Data; +using JSMR.Tests.Fixtures; + +namespace JSMR.Tests.Data.Repositories.VoiceWorks; + +public abstract class VoiceWorkRepositoryTests(MariaDbContainerFixture container) +{ + protected async Task GetAppDbContextAsync() + { + return await MariaDbClone.CloneFromTemplateAsync( + container.RootConnectionString, + container.TemplateDbName, + seed: VoiceWorkRepositorySeedData.SeedAsync); + } +} \ No newline at end of file